add: integrate DioneStaking contract into ethereum client and node store

This commit is contained in:
bahadylbekov 2020-10-30 08:23:08 +03:00
parent 9b8c4eb012
commit 9219e483a1
9 changed files with 2298 additions and 1061 deletions

View File

@ -26,107 +26,107 @@ var (
_ = event.NewSubscription _ = event.NewSubscription
) )
// SmartcontractsABI is the input ABI used to generate the binding from. // AggregatorABI is the input ABI used to generate the binding from.
const SmartcontractsABI = "[{\"inputs\":[{\"internalType\":\"contractWhitelist\",\"name\":\"_whitelist\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" const AggregatorABI = "[{\"inputs\":[{\"internalType\":\"contractWhitelist\",\"name\":\"_whitelist\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
// Smartcontracts is an auto generated Go binding around an Ethereum contract. // Aggregator is an auto generated Go binding around an Ethereum contract.
type Smartcontracts struct { type Aggregator struct {
SmartcontractsCaller // Read-only binding to the contract AggregatorCaller // Read-only binding to the contract
SmartcontractsTransactor // Write-only binding to the contract AggregatorTransactor // Write-only binding to the contract
SmartcontractsFilterer // Log filterer for contract events AggregatorFilterer // Log filterer for contract events
} }
// SmartcontractsCaller is an auto generated read-only Go binding around an Ethereum contract. // AggregatorCaller is an auto generated read-only Go binding around an Ethereum contract.
type SmartcontractsCaller struct { type AggregatorCaller struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsTransactor is an auto generated write-only Go binding around an Ethereum contract. // AggregatorTransactor is an auto generated write-only Go binding around an Ethereum contract.
type SmartcontractsTransactor struct { type AggregatorTransactor struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsFilterer is an auto generated log filtering Go binding around an Ethereum contract events. // AggregatorFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
type SmartcontractsFilterer struct { type AggregatorFilterer struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsSession is an auto generated Go binding around an Ethereum contract, // AggregatorSession is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options. // with pre-set call and transact options.
type SmartcontractsSession struct { type AggregatorSession struct {
Contract *Smartcontracts // Generic contract binding to set the session for Contract *Aggregator // Generic contract binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session CallOpts bind.CallOpts // Call options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
} }
// SmartcontractsCallerSession is an auto generated read-only Go binding around an Ethereum contract, // AggregatorCallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options. // with pre-set call options.
type SmartcontractsCallerSession struct { type AggregatorCallerSession struct {
Contract *SmartcontractsCaller // Generic contract caller binding to set the session for Contract *AggregatorCaller // Generic contract caller binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session CallOpts bind.CallOpts // Call options to use throughout this session
} }
// SmartcontractsTransactorSession is an auto generated write-only Go binding around an Ethereum contract, // AggregatorTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options. // with pre-set transact options.
type SmartcontractsTransactorSession struct { type AggregatorTransactorSession struct {
Contract *SmartcontractsTransactor // Generic contract transactor binding to set the session for Contract *AggregatorTransactor // Generic contract transactor binding to set the session for
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
} }
// SmartcontractsRaw is an auto generated low-level Go binding around an Ethereum contract. // AggregatorRaw is an auto generated low-level Go binding around an Ethereum contract.
type SmartcontractsRaw struct { type AggregatorRaw struct {
Contract *Smartcontracts // Generic contract binding to access the raw methods on Contract *Aggregator // Generic contract binding to access the raw methods on
} }
// SmartcontractsCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. // AggregatorCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type SmartcontractsCallerRaw struct { type AggregatorCallerRaw struct {
Contract *SmartcontractsCaller // Generic read-only contract binding to access the raw methods on Contract *AggregatorCaller // Generic read-only contract binding to access the raw methods on
} }
// SmartcontractsTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. // AggregatorTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type SmartcontractsTransactorRaw struct { type AggregatorTransactorRaw struct {
Contract *SmartcontractsTransactor // Generic write-only contract binding to access the raw methods on Contract *AggregatorTransactor // Generic write-only contract binding to access the raw methods on
} }
// NewSmartcontracts creates a new instance of Smartcontracts, bound to a specific deployed contract. // NewAggregator creates a new instance of Aggregator, bound to a specific deployed contract.
func NewSmartcontracts(address common.Address, backend bind.ContractBackend) (*Smartcontracts, error) { func NewAggregator(address common.Address, backend bind.ContractBackend) (*Aggregator, error) {
contract, err := bindSmartcontracts(address, backend, backend, backend) contract, err := bindAggregator(address, backend, backend, backend)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Smartcontracts{SmartcontractsCaller: SmartcontractsCaller{contract: contract}, SmartcontractsTransactor: SmartcontractsTransactor{contract: contract}, SmartcontractsFilterer: SmartcontractsFilterer{contract: contract}}, nil return &Aggregator{AggregatorCaller: AggregatorCaller{contract: contract}, AggregatorTransactor: AggregatorTransactor{contract: contract}, AggregatorFilterer: AggregatorFilterer{contract: contract}}, nil
} }
// NewSmartcontractsCaller creates a new read-only instance of Smartcontracts, bound to a specific deployed contract. // NewAggregatorCaller creates a new read-only instance of Aggregator, bound to a specific deployed contract.
func NewSmartcontractsCaller(address common.Address, caller bind.ContractCaller) (*SmartcontractsCaller, error) { func NewAggregatorCaller(address common.Address, caller bind.ContractCaller) (*AggregatorCaller, error) {
contract, err := bindSmartcontracts(address, caller, nil, nil) contract, err := bindAggregator(address, caller, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsCaller{contract: contract}, nil return &AggregatorCaller{contract: contract}, nil
} }
// NewSmartcontractsTransactor creates a new write-only instance of Smartcontracts, bound to a specific deployed contract. // NewAggregatorTransactor creates a new write-only instance of Aggregator, bound to a specific deployed contract.
func NewSmartcontractsTransactor(address common.Address, transactor bind.ContractTransactor) (*SmartcontractsTransactor, error) { func NewAggregatorTransactor(address common.Address, transactor bind.ContractTransactor) (*AggregatorTransactor, error) {
contract, err := bindSmartcontracts(address, nil, transactor, nil) contract, err := bindAggregator(address, nil, transactor, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsTransactor{contract: contract}, nil return &AggregatorTransactor{contract: contract}, nil
} }
// NewSmartcontractsFilterer creates a new log filterer instance of Smartcontracts, bound to a specific deployed contract. // NewAggregatorFilterer creates a new log filterer instance of Aggregator, bound to a specific deployed contract.
func NewSmartcontractsFilterer(address common.Address, filterer bind.ContractFilterer) (*SmartcontractsFilterer, error) { func NewAggregatorFilterer(address common.Address, filterer bind.ContractFilterer) (*AggregatorFilterer, error) {
contract, err := bindSmartcontracts(address, nil, nil, filterer) contract, err := bindAggregator(address, nil, nil, filterer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsFilterer{contract: contract}, nil return &AggregatorFilterer{contract: contract}, nil
} }
// bindSmartcontracts binds a generic wrapper to an already deployed contract. // bindAggregator binds a generic wrapper to an already deployed contract.
func bindSmartcontracts(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { func bindAggregator(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
parsed, err := abi.JSON(strings.NewReader(SmartcontractsABI)) parsed, err := abi.JSON(strings.NewReader(AggregatorABI))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -137,57 +137,57 @@ func bindSmartcontracts(address common.Address, caller bind.ContractCaller, tran
// sets the output to result. The result type might be a single field for simple // sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named // returns, a slice of interfaces for anonymous returns and a struct for named
// returns. // returns.
func (_Smartcontracts *SmartcontractsRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { func (_Aggregator *AggregatorRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _Smartcontracts.Contract.SmartcontractsCaller.contract.Call(opts, result, method, params...) return _Aggregator.Contract.AggregatorCaller.contract.Call(opts, result, method, params...)
} }
// Transfer initiates a plain transaction to move funds to the contract, calling // Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available. // its default method if one is available.
func (_Smartcontracts *SmartcontractsRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { func (_Aggregator *AggregatorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Smartcontracts.Contract.SmartcontractsTransactor.contract.Transfer(opts) return _Aggregator.Contract.AggregatorTransactor.contract.Transfer(opts)
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (_Smartcontracts *SmartcontractsRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { func (_Aggregator *AggregatorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Smartcontracts.Contract.SmartcontractsTransactor.contract.Transact(opts, method, params...) return _Aggregator.Contract.AggregatorTransactor.contract.Transact(opts, method, params...)
} }
// Call invokes the (constant) contract method with params as input values and // Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple // sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named // returns, a slice of interfaces for anonymous returns and a struct for named
// returns. // returns.
func (_Smartcontracts *SmartcontractsCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { func (_Aggregator *AggregatorCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _Smartcontracts.Contract.contract.Call(opts, result, method, params...) return _Aggregator.Contract.contract.Call(opts, result, method, params...)
} }
// Transfer initiates a plain transaction to move funds to the contract, calling // Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available. // its default method if one is available.
func (_Smartcontracts *SmartcontractsTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { func (_Aggregator *AggregatorTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Smartcontracts.Contract.contract.Transfer(opts) return _Aggregator.Contract.contract.Transfer(opts)
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (_Smartcontracts *SmartcontractsTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { func (_Aggregator *AggregatorTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Smartcontracts.Contract.contract.Transact(opts, method, params...) return _Aggregator.Contract.contract.Transact(opts, method, params...)
} }
// CollectData is a paid mutator transaction binding the contract method 0x05187092. // CollectData is a paid mutator transaction binding the contract method 0x05187092.
// //
// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() // Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns()
func (_Smartcontracts *SmartcontractsTransactor) CollectData(opts *bind.TransactOpts, reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_Aggregator *AggregatorTransactor) CollectData(opts *bind.TransactOpts, reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.contract.Transact(opts, "collectData", reqID, data, callbackAddress, callbackMethodID) return _Aggregator.contract.Transact(opts, "collectData", reqID, data, callbackAddress, callbackMethodID)
} }
// CollectData is a paid mutator transaction binding the contract method 0x05187092. // CollectData is a paid mutator transaction binding the contract method 0x05187092.
// //
// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() // Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns()
func (_Smartcontracts *SmartcontractsSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_Aggregator *AggregatorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.Contract.CollectData(&_Smartcontracts.TransactOpts, reqID, data, callbackAddress, callbackMethodID) return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID)
} }
// CollectData is a paid mutator transaction binding the contract method 0x05187092. // CollectData is a paid mutator transaction binding the contract method 0x05187092.
// //
// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() // Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns()
func (_Smartcontracts *SmartcontractsTransactorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_Aggregator *AggregatorTransactorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.Contract.CollectData(&_Smartcontracts.TransactOpts, reqID, data, callbackAddress, callbackMethodID) return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID)
} }

File diff suppressed because it is too large Load Diff

View File

@ -26,107 +26,107 @@ var (
_ = event.NewSubscription _ = event.NewSubscription
) )
// SmartcontractsABI is the input ABI used to generate the binding from. // OracleEmitterABI is the input ABI used to generate the binding from.
const SmartcontractsABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"requestID\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"requestOracles\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" const OracleEmitterABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"requestID\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"requestOracles\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
// Smartcontracts is an auto generated Go binding around an Ethereum contract. // OracleEmitter is an auto generated Go binding around an Ethereum contract.
type Smartcontracts struct { type OracleEmitter struct {
SmartcontractsCaller // Read-only binding to the contract OracleEmitterCaller // Read-only binding to the contract
SmartcontractsTransactor // Write-only binding to the contract OracleEmitterTransactor // Write-only binding to the contract
SmartcontractsFilterer // Log filterer for contract events OracleEmitterFilterer // Log filterer for contract events
} }
// SmartcontractsCaller is an auto generated read-only Go binding around an Ethereum contract. // OracleEmitterCaller is an auto generated read-only Go binding around an Ethereum contract.
type SmartcontractsCaller struct { type OracleEmitterCaller struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsTransactor is an auto generated write-only Go binding around an Ethereum contract. // OracleEmitterTransactor is an auto generated write-only Go binding around an Ethereum contract.
type SmartcontractsTransactor struct { type OracleEmitterTransactor struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsFilterer is an auto generated log filtering Go binding around an Ethereum contract events. // OracleEmitterFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
type SmartcontractsFilterer struct { type OracleEmitterFilterer struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls contract *bind.BoundContract // Generic contract wrapper for the low level calls
} }
// SmartcontractsSession is an auto generated Go binding around an Ethereum contract, // OracleEmitterSession is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options. // with pre-set call and transact options.
type SmartcontractsSession struct { type OracleEmitterSession struct {
Contract *Smartcontracts // Generic contract binding to set the session for Contract *OracleEmitter // Generic contract binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session CallOpts bind.CallOpts // Call options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
} }
// SmartcontractsCallerSession is an auto generated read-only Go binding around an Ethereum contract, // OracleEmitterCallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options. // with pre-set call options.
type SmartcontractsCallerSession struct { type OracleEmitterCallerSession struct {
Contract *SmartcontractsCaller // Generic contract caller binding to set the session for Contract *OracleEmitterCaller // Generic contract caller binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session CallOpts bind.CallOpts // Call options to use throughout this session
} }
// SmartcontractsTransactorSession is an auto generated write-only Go binding around an Ethereum contract, // OracleEmitterTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options. // with pre-set transact options.
type SmartcontractsTransactorSession struct { type OracleEmitterTransactorSession struct {
Contract *SmartcontractsTransactor // Generic contract transactor binding to set the session for Contract *OracleEmitterTransactor // Generic contract transactor binding to set the session for
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
} }
// SmartcontractsRaw is an auto generated low-level Go binding around an Ethereum contract. // OracleEmitterRaw is an auto generated low-level Go binding around an Ethereum contract.
type SmartcontractsRaw struct { type OracleEmitterRaw struct {
Contract *Smartcontracts // Generic contract binding to access the raw methods on Contract *OracleEmitter // Generic contract binding to access the raw methods on
} }
// SmartcontractsCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. // OracleEmitterCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type SmartcontractsCallerRaw struct { type OracleEmitterCallerRaw struct {
Contract *SmartcontractsCaller // Generic read-only contract binding to access the raw methods on Contract *OracleEmitterCaller // Generic read-only contract binding to access the raw methods on
} }
// SmartcontractsTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. // OracleEmitterTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type SmartcontractsTransactorRaw struct { type OracleEmitterTransactorRaw struct {
Contract *SmartcontractsTransactor // Generic write-only contract binding to access the raw methods on Contract *OracleEmitterTransactor // Generic write-only contract binding to access the raw methods on
} }
// NewSmartcontracts creates a new instance of Smartcontracts, bound to a specific deployed contract. // NewOracleEmitter creates a new instance of OracleEmitter, bound to a specific deployed contract.
func NewSmartcontracts(address common.Address, backend bind.ContractBackend) (*Smartcontracts, error) { func NewOracleEmitter(address common.Address, backend bind.ContractBackend) (*OracleEmitter, error) {
contract, err := bindSmartcontracts(address, backend, backend, backend) contract, err := bindOracleEmitter(address, backend, backend, backend)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Smartcontracts{SmartcontractsCaller: SmartcontractsCaller{contract: contract}, SmartcontractsTransactor: SmartcontractsTransactor{contract: contract}, SmartcontractsFilterer: SmartcontractsFilterer{contract: contract}}, nil return &OracleEmitter{OracleEmitterCaller: OracleEmitterCaller{contract: contract}, OracleEmitterTransactor: OracleEmitterTransactor{contract: contract}, OracleEmitterFilterer: OracleEmitterFilterer{contract: contract}}, nil
} }
// NewSmartcontractsCaller creates a new read-only instance of Smartcontracts, bound to a specific deployed contract. // NewOracleEmitterCaller creates a new read-only instance of OracleEmitter, bound to a specific deployed contract.
func NewSmartcontractsCaller(address common.Address, caller bind.ContractCaller) (*SmartcontractsCaller, error) { func NewOracleEmitterCaller(address common.Address, caller bind.ContractCaller) (*OracleEmitterCaller, error) {
contract, err := bindSmartcontracts(address, caller, nil, nil) contract, err := bindOracleEmitter(address, caller, nil, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsCaller{contract: contract}, nil return &OracleEmitterCaller{contract: contract}, nil
} }
// NewSmartcontractsTransactor creates a new write-only instance of Smartcontracts, bound to a specific deployed contract. // NewOracleEmitterTransactor creates a new write-only instance of OracleEmitter, bound to a specific deployed contract.
func NewSmartcontractsTransactor(address common.Address, transactor bind.ContractTransactor) (*SmartcontractsTransactor, error) { func NewOracleEmitterTransactor(address common.Address, transactor bind.ContractTransactor) (*OracleEmitterTransactor, error) {
contract, err := bindSmartcontracts(address, nil, transactor, nil) contract, err := bindOracleEmitter(address, nil, transactor, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsTransactor{contract: contract}, nil return &OracleEmitterTransactor{contract: contract}, nil
} }
// NewSmartcontractsFilterer creates a new log filterer instance of Smartcontracts, bound to a specific deployed contract. // NewOracleEmitterFilterer creates a new log filterer instance of OracleEmitter, bound to a specific deployed contract.
func NewSmartcontractsFilterer(address common.Address, filterer bind.ContractFilterer) (*SmartcontractsFilterer, error) { func NewOracleEmitterFilterer(address common.Address, filterer bind.ContractFilterer) (*OracleEmitterFilterer, error) {
contract, err := bindSmartcontracts(address, nil, nil, filterer) contract, err := bindOracleEmitter(address, nil, nil, filterer)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsFilterer{contract: contract}, nil return &OracleEmitterFilterer{contract: contract}, nil
} }
// bindSmartcontracts binds a generic wrapper to an already deployed contract. // bindOracleEmitter binds a generic wrapper to an already deployed contract.
func bindSmartcontracts(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { func bindOracleEmitter(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
parsed, err := abi.JSON(strings.NewReader(SmartcontractsABI)) parsed, err := abi.JSON(strings.NewReader(OracleEmitterABI))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -137,64 +137,64 @@ func bindSmartcontracts(address common.Address, caller bind.ContractCaller, tran
// sets the output to result. The result type might be a single field for simple // sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named // returns, a slice of interfaces for anonymous returns and a struct for named
// returns. // returns.
func (_Smartcontracts *SmartcontractsRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { func (_OracleEmitter *OracleEmitterRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _Smartcontracts.Contract.SmartcontractsCaller.contract.Call(opts, result, method, params...) return _OracleEmitter.Contract.OracleEmitterCaller.contract.Call(opts, result, method, params...)
} }
// Transfer initiates a plain transaction to move funds to the contract, calling // Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available. // its default method if one is available.
func (_Smartcontracts *SmartcontractsRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Smartcontracts.Contract.SmartcontractsTransactor.contract.Transfer(opts) return _OracleEmitter.Contract.OracleEmitterTransactor.contract.Transfer(opts)
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (_Smartcontracts *SmartcontractsRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Smartcontracts.Contract.SmartcontractsTransactor.contract.Transact(opts, method, params...) return _OracleEmitter.Contract.OracleEmitterTransactor.contract.Transact(opts, method, params...)
} }
// Call invokes the (constant) contract method with params as input values and // Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple // sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named // returns, a slice of interfaces for anonymous returns and a struct for named
// returns. // returns.
func (_Smartcontracts *SmartcontractsCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { func (_OracleEmitter *OracleEmitterCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error {
return _Smartcontracts.Contract.contract.Call(opts, result, method, params...) return _OracleEmitter.Contract.contract.Call(opts, result, method, params...)
} }
// Transfer initiates a plain transaction to move funds to the contract, calling // Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available. // its default method if one is available.
func (_Smartcontracts *SmartcontractsTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Smartcontracts.Contract.contract.Transfer(opts) return _OracleEmitter.Contract.contract.Transfer(opts)
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (_Smartcontracts *SmartcontractsTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Smartcontracts.Contract.contract.Transact(opts, method, params...) return _OracleEmitter.Contract.contract.Transact(opts, method, params...)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480. // RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480.
// //
// Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_Smartcontracts *SmartcontractsTransactor) RequestOracles(opts *bind.TransactOpts, requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactor) RequestOracles(opts *bind.TransactOpts, requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.contract.Transact(opts, "requestOracles", requestType, callbackAddress, callbackMethodID) return _OracleEmitter.contract.Transact(opts, "requestOracles", requestType, callbackAddress, callbackMethodID)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480. // RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480.
// //
// Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_Smartcontracts *SmartcontractsSession) RequestOracles(requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterSession) RequestOracles(requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.Contract.RequestOracles(&_Smartcontracts.TransactOpts, requestType, callbackAddress, callbackMethodID) return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, requestType, callbackAddress, callbackMethodID)
} }
// RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480. // RequestOracles is a paid mutator transaction binding the contract method 0xcae2f480.
// //
// Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256) // Solidity: function requestOracles(string requestType, address callbackAddress, bytes4 callbackMethodID) returns(uint256)
func (_Smartcontracts *SmartcontractsTransactorSession) RequestOracles(requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { func (_OracleEmitter *OracleEmitterTransactorSession) RequestOracles(requestType string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) {
return _Smartcontracts.Contract.RequestOracles(&_Smartcontracts.TransactOpts, requestType, callbackAddress, callbackMethodID) return _OracleEmitter.Contract.RequestOracles(&_OracleEmitter.TransactOpts, requestType, callbackAddress, callbackMethodID)
} }
// SmartcontractsNewOracleRequestIterator is returned from FilterNewOracleRequest and is used to iterate over the raw logs and unpacked data for NewOracleRequest events raised by the Smartcontracts contract. // OracleEmitterNewOracleRequestIterator is returned from FilterNewOracleRequest and is used to iterate over the raw logs and unpacked data for NewOracleRequest events raised by the OracleEmitter contract.
type SmartcontractsNewOracleRequestIterator struct { type OracleEmitterNewOracleRequestIterator struct {
Event *SmartcontractsNewOracleRequest // Event containing the contract specifics and raw log Event *OracleEmitterNewOracleRequest // Event containing the contract specifics and raw log
contract *bind.BoundContract // Generic contract to use for unpacking event data contract *bind.BoundContract // Generic contract to use for unpacking event data
event string // Event name to use for unpacking event data event string // Event name to use for unpacking event data
@ -208,7 +208,7 @@ type SmartcontractsNewOracleRequestIterator struct {
// Next advances the iterator to the subsequent event, returning whether there // Next advances the iterator to the subsequent event, returning whether there
// are any more events found. In case of a retrieval or parsing error, false is // are any more events found. In case of a retrieval or parsing error, false is
// returned and Error() can be queried for the exact failure. // returned and Error() can be queried for the exact failure.
func (it *SmartcontractsNewOracleRequestIterator) Next() bool { func (it *OracleEmitterNewOracleRequestIterator) Next() bool {
// If the iterator failed, stop iterating // If the iterator failed, stop iterating
if it.fail != nil { if it.fail != nil {
return false return false
@ -217,7 +217,7 @@ func (it *SmartcontractsNewOracleRequestIterator) Next() bool {
if it.done { if it.done {
select { select {
case log := <-it.logs: case log := <-it.logs:
it.Event = new(SmartcontractsNewOracleRequest) it.Event = new(OracleEmitterNewOracleRequest)
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
it.fail = err it.fail = err
return false return false
@ -232,7 +232,7 @@ func (it *SmartcontractsNewOracleRequestIterator) Next() bool {
// Iterator still in progress, wait for either a data or an error event // Iterator still in progress, wait for either a data or an error event
select { select {
case log := <-it.logs: case log := <-it.logs:
it.Event = new(SmartcontractsNewOracleRequest) it.Event = new(OracleEmitterNewOracleRequest)
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
it.fail = err it.fail = err
return false return false
@ -248,19 +248,19 @@ func (it *SmartcontractsNewOracleRequestIterator) Next() bool {
} }
// Error returns any retrieval or parsing error occurred during filtering. // Error returns any retrieval or parsing error occurred during filtering.
func (it *SmartcontractsNewOracleRequestIterator) Error() error { func (it *OracleEmitterNewOracleRequestIterator) Error() error {
return it.fail return it.fail
} }
// Close terminates the iteration process, releasing any pending underlying // Close terminates the iteration process, releasing any pending underlying
// resources. // resources.
func (it *SmartcontractsNewOracleRequestIterator) Close() error { func (it *OracleEmitterNewOracleRequestIterator) Close() error {
it.sub.Unsubscribe() it.sub.Unsubscribe()
return nil return nil
} }
// SmartcontractsNewOracleRequest represents a NewOracleRequest event raised by the Smartcontracts contract. // OracleEmitterNewOracleRequest represents a NewOracleRequest event raised by the OracleEmitter contract.
type SmartcontractsNewOracleRequest struct { type OracleEmitterNewOracleRequest struct {
RequestType string RequestType string
CallbackAddress common.Address CallbackAddress common.Address
CallbackMethodID [4]byte CallbackMethodID [4]byte
@ -271,21 +271,21 @@ type SmartcontractsNewOracleRequest struct {
// FilterNewOracleRequest is a free log retrieval operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a. // FilterNewOracleRequest is a free log retrieval operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a.
// //
// Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_Smartcontracts *SmartcontractsFilterer) FilterNewOracleRequest(opts *bind.FilterOpts) (*SmartcontractsNewOracleRequestIterator, error) { func (_OracleEmitter *OracleEmitterFilterer) FilterNewOracleRequest(opts *bind.FilterOpts) (*OracleEmitterNewOracleRequestIterator, error) {
logs, sub, err := _Smartcontracts.contract.FilterLogs(opts, "NewOracleRequest") logs, sub, err := _OracleEmitter.contract.FilterLogs(opts, "NewOracleRequest")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SmartcontractsNewOracleRequestIterator{contract: _Smartcontracts.contract, event: "NewOracleRequest", logs: logs, sub: sub}, nil return &OracleEmitterNewOracleRequestIterator{contract: _OracleEmitter.contract, event: "NewOracleRequest", logs: logs, sub: sub}, nil
} }
// WatchNewOracleRequest is a free log subscription operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a. // WatchNewOracleRequest is a free log subscription operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a.
// //
// Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_Smartcontracts *SmartcontractsFilterer) WatchNewOracleRequest(opts *bind.WatchOpts, sink chan<- *SmartcontractsNewOracleRequest) (event.Subscription, error) { func (_OracleEmitter *OracleEmitterFilterer) WatchNewOracleRequest(opts *bind.WatchOpts, sink chan<- *OracleEmitterNewOracleRequest) (event.Subscription, error) {
logs, sub, err := _Smartcontracts.contract.WatchLogs(opts, "NewOracleRequest") logs, sub, err := _OracleEmitter.contract.WatchLogs(opts, "NewOracleRequest")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -295,8 +295,8 @@ func (_Smartcontracts *SmartcontractsFilterer) WatchNewOracleRequest(opts *bind.
select { select {
case log := <-logs: case log := <-logs:
// New log arrived, parse the event and forward to the user // New log arrived, parse the event and forward to the user
event := new(SmartcontractsNewOracleRequest) event := new(OracleEmitterNewOracleRequest)
if err := _Smartcontracts.contract.UnpackLog(event, "NewOracleRequest", log); err != nil { if err := _OracleEmitter.contract.UnpackLog(event, "NewOracleRequest", log); err != nil {
return err return err
} }
event.Raw = log event.Raw = log
@ -320,9 +320,9 @@ func (_Smartcontracts *SmartcontractsFilterer) WatchNewOracleRequest(opts *bind.
// ParseNewOracleRequest is a log parse operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a. // ParseNewOracleRequest is a log parse operation binding the contract event 0xc1a7df69ed0404441720a3eb710f322985ecbbe4f31934587bee703efe04427a.
// //
// Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID) // Solidity: event NewOracleRequest(string requestType, address callbackAddress, bytes4 callbackMethodID, uint256 requestID)
func (_Smartcontracts *SmartcontractsFilterer) ParseNewOracleRequest(log types.Log) (*SmartcontractsNewOracleRequest, error) { func (_OracleEmitter *OracleEmitterFilterer) ParseNewOracleRequest(log types.Log) (*OracleEmitterNewOracleRequest, error) {
event := new(SmartcontractsNewOracleRequest) event := new(OracleEmitterNewOracleRequest)
if err := _Smartcontracts.contract.UnpackLog(event, "NewOracleRequest", log); err != nil { if err := _OracleEmitter.contract.UnpackLog(event, "NewOracleRequest", log); err != nil {
return nil, err return nil, err
} }
return event, nil return event, nil

View File

@ -1,7 +1,6 @@
pragma solidity 0.6.12; pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
@ -13,7 +12,6 @@ import "./DioneToken.sol";
// The ownership of the contract would be transfered to 24 hours Timelock // The ownership of the contract would be transfered to 24 hours Timelock
contract DioneStaking is Ownable, ReentrancyGuard { contract DioneStaking is Ownable, ReentrancyGuard {
using SafeMath for uint256; using SafeMath for uint256;
using SafeERC20 for IERC20;
// MinerInfo contains total DIONEs staked by miner, how much tasks been already computed // MinerInfo contains total DIONEs staked by miner, how much tasks been already computed
// and timestamp of first deposit // and timestamp of first deposit
@ -47,7 +45,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
address _aggregatorAddr, address _aggregatorAddr,
uint256 _minerReward, uint256 _minerReward,
uint256 _startBlock, uint256 _startBlock,
uint256 _minimumStake; uint256 _minimumStake
) public { ) public {
dione = _dione; dione = _dione;
aggregatorAddr = _aggregatorAddr; aggregatorAddr = _aggregatorAddr;
@ -60,31 +58,31 @@ contract DioneStaking is Ownable, ReentrancyGuard {
function mine(address _minerAddr) public nonReentrant { function mine(address _minerAddr) public nonReentrant {
require(msg.sender == aggregatorAddr, "not aggregator contract"); require(msg.sender == aggregatorAddr, "not aggregator contract");
MinerInfo storage miner = minerInfo[_minerAddr]; MinerInfo storage miner = minerInfo[_minerAddr];
require(miner.amount >= minimumStake) require(miner.amount >= minimumStake);
dione.mint(_minerAddr, minerReward); dione.mint(_minerAddr, minerReward);
miner.lastRewardBlock = block.number; miner.lastRewardBlock = block.number;
emit Mine(_minerAddr, block.number) emit Mine(_minerAddr, block.number);
} }
// Mine new dione oracle task and stake miner reward, only can be executed by aggregator contract // Mine new dione oracle task and stake miner reward, only can be executed by aggregator contract
function mineAndStake(address _minerAddr) public nonReentrant { function mineAndStake(address _minerAddr) public nonReentrant {
require(msg.sender == aggregatorAddr, "not aggregator contract"); require(msg.sender == aggregatorAddr, "not aggregator contract");
MinerInfo storage miner = minerInfo[_minerAddr]; MinerInfo storage miner = minerInfo[_minerAddr];
require(miner.amount >= minimumStake) require(miner.amount >= minimumStake);
dione.mint(address(this), minerReward); dione.mint(address(this), minerReward);
_totalStake = _totalStake.add(minerReward); _totalStake = _totalStake.add(minerReward);
miner.amount = miner.amount.add(minerReward); miner.amount = miner.amount.add(minerReward);
miner.lastRewardBlock = block.number; miner.lastRewardBlock = block.number;
emit Mine(_minerAddr, block.number) emit Mine(_minerAddr, block.number);
} }
// Deposit DIONE tokens to mine on dione network // Deposit DIONE tokens to mine on dione network
function stake(uint256 _amount) public nonReentrant { function stake(uint256 _amount) public nonReentrant {
require(_amount > 0, "Cannot stake 0"); require(_amount > 0, "Cannot stake 0");
MinerInfo storage miner = minerInfo[msg.sender]; MinerInfo storage miner = minerInfo[msg.sender];
_totalStake = _totalStake.add(amount); _totalStake = _totalStake.add(_amount);
miner.amount = miner.amount.add(_amount); miner.amount = miner.amount.add(_amount);
dione.safeTransferFrom(address(msg.sender), address(this), _amount); dione.transferFrom(address(msg.sender), address(this), _amount);
if (miner.firstStakeBlock == 0 && miner.amount >= minimumStake) { if (miner.firstStakeBlock == 0 && miner.amount >= minimumStake) {
miner.firstStakeBlock = block.number > startBlock ? block.number : startBlock; miner.firstStakeBlock = block.number > startBlock ? block.number : startBlock;
} }
@ -96,9 +94,9 @@ contract DioneStaking is Ownable, ReentrancyGuard {
MinerInfo storage miner = minerInfo[msg.sender]; MinerInfo storage miner = minerInfo[msg.sender];
require(miner.amount >= _amount, "withdraw: not enough tokens"); require(miner.amount >= _amount, "withdraw: not enough tokens");
if(_amount > 0) { if(_amount > 0) {
_totalStake = _totalStake.sub(amount); _totalStake = _totalStake.sub(_amount);
miner.amount = miner.amount.sub(_amount); miner.amount = miner.amount.sub(_amount);
dione.safeTransfer(address(msg.sender), _amount); dione.transfer(address(msg.sender), _amount);
} }
emit Withdraw(msg.sender, _amount); emit Withdraw(msg.sender, _amount);
} }
@ -110,7 +108,7 @@ contract DioneStaking is Ownable, ReentrancyGuard {
function minerStake(address _minerAddr) external view returns (uint256) { function minerStake(address _minerAddr) external view returns (uint256) {
MinerInfo storage miner = minerInfo[_minerAddr]; MinerInfo storage miner = minerInfo[_minerAddr];
return miner.amount return miner.amount;
} }
// Update miner reward in DIONE tokens, only can be executed by owner of the contract // Update miner reward in DIONE tokens, only can be executed by owner of the contract

File diff suppressed because it is too large Load Diff

View File

@ -15,5 +15,8 @@
"@truffle/hdwallet-provider": "^1.0.40", "@truffle/hdwallet-provider": "^1.0.40",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"truffle": "^5.1.37" "truffle": "^5.1.37"
},
"devDependencies": {
"@openzeppelin/contracts": "^3.2.0"
} }
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"math/big" "math/big"
stakingContract "github.com/Secured-Finance/dione/contracts/DioneStaking"
"github.com/Secured-Finance/dione/contracts/aggregator" "github.com/Secured-Finance/dione/contracts/aggregator"
"github.com/Secured-Finance/dione/contracts/oracleemitter" "github.com/Secured-Finance/dione/contracts/oracleemitter"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
@ -13,11 +14,13 @@ import (
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
) )
// TODO: change artifacts for other contracts
type EthereumClient struct { type EthereumClient struct {
client *ethclient.Client client *ethclient.Client
authTransactor *bind.TransactOpts authTransactor *bind.TransactOpts
oracleEmitter *oracleemitter.SmartcontractsSession oracleEmitter *oracleemitter.OracleEmitterSession
aggregator *aggregator.SmartcontractsSession aggregator *aggregator.AggregatorSession
dioneStaking *stakingContract.DioneStakingSession
} }
type OracleEvent struct { type OracleEvent struct {
@ -53,15 +56,15 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
authTransactor := bind.NewKeyedTransactor(ecdsaKey) authTransactor := bind.NewKeyedTransactor(ecdsaKey)
c.authTransactor = authTransactor c.authTransactor = authTransactor
oracleEmitter, err := oracleemitter.NewSmartcontracts(common.HexToAddress(oracleEmitterContractAddress), client) oracleEmitter, err := oracleemitter.NewOracleEmitter(common.HexToAddress(oracleEmitterContractAddress), client)
if err != nil { if err != nil {
return err return err
} }
aggregatorPlainSC, err := aggregator.NewSmartcontracts(common.HexToAddress(aggregatorContractAddress), client) aggregatorPlainSC, err := aggregator.NewAggregator(common.HexToAddress(aggregatorContractAddress), client)
if err != nil { if err != nil {
return err return err
} }
c.oracleEmitter = &oracleemitter.SmartcontractsSession{ c.oracleEmitter = &oracleemitter.OracleEmitterSession{
Contract: oracleEmitter, Contract: oracleEmitter,
CallOpts: bind.CallOpts{ CallOpts: bind.CallOpts{
Pending: true, Pending: true,
@ -76,7 +79,7 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
Context: context.Background(), Context: context.Background(),
}, },
} }
c.aggregator = &aggregator.SmartcontractsSession{ c.aggregator = &aggregator.AggregatorSession{
Contract: aggregatorPlainSC, Contract: aggregatorPlainSC,
CallOpts: bind.CallOpts{ CallOpts: bind.CallOpts{
Pending: true, Pending: true,
@ -175,8 +178,8 @@ func (c *EthereumClient) Initialize(ctx context.Context, url, privateKey, oracle
// return address // return address
// } // }
func (c *EthereumClient) SubscribeOnOracleEvents(incomingEventsChan chan *oracleemitter.SmartcontractsNewOracleRequest) (event.Subscription, error) { func (c *EthereumClient) SubscribeOnOracleEvents(incomingEventsChan chan *oracleemitter.OracleEmitterNewOracleRequest) (event.Subscription, error) {
requestsFilter := c.oracleEmitter.Contract.SmartcontractsFilterer requestsFilter := c.oracleEmitter.Contract.OracleEmitterFilterer
subscription, err := requestsFilter.WatchNewOracleRequest(&bind.WatchOpts{ subscription, err := requestsFilter.WatchNewOracleRequest(&bind.WatchOpts{
Start: nil, //last block Start: nil, //last block
Context: nil, Context: nil,
@ -220,3 +223,19 @@ func (c *EthereumClient) SubmitRequestAnswer(reqID *big.Int, data string, callba
return nil return nil
} }
func (c *EthereumClient) GetTotalStake() (*big.Int, error) {
totalStake, err := c.dioneStaking.TotalStake()
if err != nil {
return nil, err
}
return totalStake, nil
}
func (c *EthereumClient) GetMinerStake(minerAddress common.Address) (*big.Int, error) {
minerStake, err := c.dioneStaking.MinerStake(minerAddress)
if err != nil {
return nil, err
}
return minerStake, nil
}

View File

@ -1,9 +1,45 @@
package store package store
import "math/big" import (
"math/big"
"github.com/Secured-Finance/dione/rpcclient"
"github.com/ethereum/go-ethereum/common"
)
// TODO: specify store for staking mechanism // TODO: specify store for staking mechanism
type StakeTokenInfo struct { type DioneStakeInfo struct {
TotalTokensStaked *big.Int MinerStake *big.Int
NodeTokensStaked *big.Int TotalStake *big.Int
Ethereum *rpcclient.EthereumClient
}
func NewDioneStakeInfo(minerStake, totalStake *big.Int, ethereumClient *rpcclient.EthereumClient) *DioneStakeInfo {
return &DioneStakeInfo{
MinerStake: minerStake,
TotalStake: totalStake,
Ethereum: ethereumClient,
}
}
func (d *DioneStakeInfo) UpdateMinerStake(minerAddress common.Address) error {
minerStake, err := d.Ethereum.GetMinerStake(minerAddress)
if err != nil {
return err
}
d.MinerStake = minerStake
return nil
}
func (d *DioneStakeInfo) UpdateTotalStake(minerAddress common.Address) error {
totalStake, err := d.Ethereum.GetTotalStake()
if err != nil {
return err
}
d.TotalStake = totalStake
return nil
} }

View File

@ -20,3 +20,5 @@ func NewStore(db *sql.DB, node *node.Node, genesisTs uint64) *Store {
genesisTs: genesisTs, genesisTs: genesisTs,
} }
} }
// TODO: connect data base; specify the table for stake storage; queries for stake storage