From cc034cc884c1b6c7a1dbdecfb20de9862c6b8187 Mon Sep 17 00:00:00 2001 From: bahadylbekov <33404905+bahadylbekov@users.noreply.github.com> Date: Wed, 25 Nov 2020 21:54:59 +0300 Subject: [PATCH] fix: Proof-of-Stake mining reward on sending data to Aggregator contract --- contracts/aggregator/Aggregator.go | 23 +------- contracts/dioneStaking/DioneStaking.go | 70 ++++++++++++++++-------- eth-contracts/contracts/Aggregator.sol | 15 ++--- eth-contracts/contracts/DioneStaking.sol | 21 +++---- node/ethereum.go | 5 +- types/task.go | 2 + 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/contracts/aggregator/Aggregator.go b/contracts/aggregator/Aggregator.go index 7156d31..028cdd6 100644 --- a/contracts/aggregator/Aggregator.go +++ b/contracts/aggregator/Aggregator.go @@ -27,7 +27,7 @@ var ( ) // AggregatorABI is the input ABI used to generate the binding from. -const AggregatorABI = "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"name\":\"setDioneStaking\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"contractIMediator\",\"name\":\"callbackAddress\",\"type\":\"address\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" +const AggregatorABI = "[{\"inputs\":[{\"internalType\":\"contractDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"data\",\"type\":\"string\"},{\"internalType\":\"contractIMediator\",\"name\":\"callbackAddress\",\"type\":\"address\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" // Aggregator is an auto generated Go binding around an Ethereum contract. type Aggregator struct { @@ -265,27 +265,6 @@ func (_Aggregator *AggregatorTransactorSession) RenounceOwnership() (*types.Tran return _Aggregator.Contract.RenounceOwnership(&_Aggregator.TransactOpts) } -// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4. -// -// Solidity: function setDioneStaking(address _dioneStaking) returns() -func (_Aggregator *AggregatorTransactor) SetDioneStaking(opts *bind.TransactOpts, _dioneStaking common.Address) (*types.Transaction, error) { - return _Aggregator.contract.Transact(opts, "setDioneStaking", _dioneStaking) -} - -// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4. -// -// Solidity: function setDioneStaking(address _dioneStaking) returns() -func (_Aggregator *AggregatorSession) SetDioneStaking(_dioneStaking common.Address) (*types.Transaction, error) { - return _Aggregator.Contract.SetDioneStaking(&_Aggregator.TransactOpts, _dioneStaking) -} - -// SetDioneStaking is a paid mutator transaction binding the contract method 0xc2cf98a4. -// -// Solidity: function setDioneStaking(address _dioneStaking) returns() -func (_Aggregator *AggregatorTransactorSession) SetDioneStaking(_dioneStaking common.Address) (*types.Transaction, error) { - return _Aggregator.Contract.SetDioneStaking(&_Aggregator.TransactOpts, _dioneStaking) -} - // TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b. // // Solidity: function transferOwnership(address newOwner) returns() diff --git a/contracts/dioneStaking/DioneStaking.go b/contracts/dioneStaking/DioneStaking.go index ffac6a3..32f4627 100644 --- a/contracts/dioneStaking/DioneStaking.go +++ b/contracts/dioneStaking/DioneStaking.go @@ -27,7 +27,7 @@ var ( ) // DioneStakingABI is the input ABI used to generate the binding from. -const DioneStakingABI = "[{\"inputs\":[{\"internalType\":\"contractDioneToken\",\"name\":\"_dione\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_aggregatorAddr\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_minerReward\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_startBlock\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_minimumStake\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"blockNumber\",\"type\":\"uint256\"}],\"name\":\"Mine\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Stake\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"aggregatorAddr\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"dione\",\"outputs\":[{\"internalType\":\"contractDioneToken\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"minerInfo\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"firstStakeBlock\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastRewardBlock\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minerReward\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"mine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"mineAndStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"stake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"minerStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_minerReward\",\"type\":\"uint256\"}],\"name\":\"setMinerReward\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"isLegitMiner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_minimumStake\",\"type\":\"uint256\"}],\"name\":\"setMinimumStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" +const DioneStakingABI = "[{\"inputs\":[{\"internalType\":\"contractDioneToken\",\"name\":\"_dione\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_minerReward\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_startBlock\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_minimumStake\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"blockNumber\",\"type\":\"uint256\"}],\"name\":\"Mine\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Stake\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"miner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"Withdraw\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"aggregatorAddr\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"dione\",\"outputs\":[{\"internalType\":\"contractDioneToken\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"minerInfo\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"firstStakeBlock\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"lastRewardBlock\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minerReward\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"startBlock\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"mine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"mineAndStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"stake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_amount\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"minerStake\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_minerReward\",\"type\":\"uint256\"}],\"name\":\"setMinerReward\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_minerAddr\",\"type\":\"address\"}],\"name\":\"isMiner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_minimumStake\",\"type\":\"uint256\"}],\"name\":\"setMinimumStake\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_aggregatorAddr\",\"type\":\"address\"}],\"name\":\"setAggregator\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" // DioneStaking is an auto generated Go binding around an Ethereum contract. type DioneStaking struct { @@ -223,6 +223,32 @@ func (_DioneStaking *DioneStakingCallerSession) Dione() (common.Address, error) return _DioneStaking.Contract.Dione(&_DioneStaking.CallOpts) } +// IsMiner is a free data retrieval call binding the contract method 0x701b70ac. +// +// Solidity: function isMiner(address _minerAddr) view returns(bool) +func (_DioneStaking *DioneStakingCaller) IsMiner(opts *bind.CallOpts, _minerAddr common.Address) (bool, error) { + var ( + ret0 = new(bool) + ) + out := ret0 + err := _DioneStaking.contract.Call(opts, out, "isMiner", _minerAddr) + return *ret0, err +} + +// IsMiner is a free data retrieval call binding the contract method 0x701b70ac. +// +// Solidity: function isMiner(address _minerAddr) view returns(bool) +func (_DioneStaking *DioneStakingSession) IsMiner(_minerAddr common.Address) (bool, error) { + return _DioneStaking.Contract.IsMiner(&_DioneStaking.CallOpts, _minerAddr) +} + +// IsMiner is a free data retrieval call binding the contract method 0x701b70ac. +// +// Solidity: function isMiner(address _minerAddr) view returns(bool) +func (_DioneStaking *DioneStakingCallerSession) IsMiner(_minerAddr common.Address) (bool, error) { + return _DioneStaking.Contract.IsMiner(&_DioneStaking.CallOpts, _minerAddr) +} + // MinerInfo is a free data retrieval call binding the contract method 0x03337fd8. // // Solidity: function minerInfo(address ) view returns(uint256 amount, uint256 firstStakeBlock, uint256 lastRewardBlock) @@ -419,27 +445,6 @@ func (_DioneStaking *DioneStakingCallerSession) TotalStake() (*big.Int, error) { return _DioneStaking.Contract.TotalStake(&_DioneStaking.CallOpts) } -// IsLegitMiner is a paid mutator transaction binding the contract method 0x3b1175eb. -// -// Solidity: function isLegitMiner(address _minerAddr) returns(bool) -func (_DioneStaking *DioneStakingTransactor) IsLegitMiner(opts *bind.TransactOpts, _minerAddr common.Address) (*types.Transaction, error) { - return _DioneStaking.contract.Transact(opts, "isLegitMiner", _minerAddr) -} - -// IsLegitMiner is a paid mutator transaction binding the contract method 0x3b1175eb. -// -// Solidity: function isLegitMiner(address _minerAddr) returns(bool) -func (_DioneStaking *DioneStakingSession) IsLegitMiner(_minerAddr common.Address) (*types.Transaction, error) { - return _DioneStaking.Contract.IsLegitMiner(&_DioneStaking.TransactOpts, _minerAddr) -} - -// IsLegitMiner is a paid mutator transaction binding the contract method 0x3b1175eb. -// -// Solidity: function isLegitMiner(address _minerAddr) returns(bool) -func (_DioneStaking *DioneStakingTransactorSession) IsLegitMiner(_minerAddr common.Address) (*types.Transaction, error) { - return _DioneStaking.Contract.IsLegitMiner(&_DioneStaking.TransactOpts, _minerAddr) -} - // Mine is a paid mutator transaction binding the contract method 0x81923240. // // Solidity: function mine(address _minerAddr) returns() @@ -503,6 +508,27 @@ func (_DioneStaking *DioneStakingTransactorSession) RenounceOwnership() (*types. return _DioneStaking.Contract.RenounceOwnership(&_DioneStaking.TransactOpts) } +// SetAggregator is a paid mutator transaction binding the contract method 0xf9120af6. +// +// Solidity: function setAggregator(address _aggregatorAddr) returns() +func (_DioneStaking *DioneStakingTransactor) SetAggregator(opts *bind.TransactOpts, _aggregatorAddr common.Address) (*types.Transaction, error) { + return _DioneStaking.contract.Transact(opts, "setAggregator", _aggregatorAddr) +} + +// SetAggregator is a paid mutator transaction binding the contract method 0xf9120af6. +// +// Solidity: function setAggregator(address _aggregatorAddr) returns() +func (_DioneStaking *DioneStakingSession) SetAggregator(_aggregatorAddr common.Address) (*types.Transaction, error) { + return _DioneStaking.Contract.SetAggregator(&_DioneStaking.TransactOpts, _aggregatorAddr) +} + +// SetAggregator is a paid mutator transaction binding the contract method 0xf9120af6. +// +// Solidity: function setAggregator(address _aggregatorAddr) returns() +func (_DioneStaking *DioneStakingTransactorSession) SetAggregator(_aggregatorAddr common.Address) (*types.Transaction, error) { + return _DioneStaking.Contract.SetAggregator(&_DioneStaking.TransactOpts, _aggregatorAddr) +} + // SetMinerReward is a paid mutator transaction binding the contract method 0x816caed5. // // Solidity: function setMinerReward(uint256 _minerReward) returns() diff --git a/eth-contracts/contracts/Aggregator.sol b/eth-contracts/contracts/Aggregator.sol index f4c1b43..f6fad23 100644 --- a/eth-contracts/contracts/Aggregator.sol +++ b/eth-contracts/contracts/Aggregator.sol @@ -3,26 +3,21 @@ pragma solidity >= 0.5.0 < 0.7.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; - -interface IDioneStaking { - function mine(address _minerAddr) external; - function mineAndStake(address _minerAddr) external; - function isLegitMiner(address _minerAddr) external returns (bool); -} +import "./DioneStaking.sol"; interface IMediator { function _receiveDataCallback(uint256 reqID, string memory data) external; } contract Aggregator is Ownable, ReentrancyGuard { - IDioneStaking public dioneStaking; + DioneStaking public dioneStaking; - // Set DioneStaking contract. Can only be called by the owner. - function setDioneStaking(IDioneStaking _dioneStaking) public onlyOwner { + constructor(DioneStaking _dioneStaking) public { dioneStaking = _dioneStaking; } - function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public nonReentrant { + function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public { + dioneStaking.mine(msg.sender); callbackAddress._receiveDataCallback(reqID, data); } } diff --git a/eth-contracts/contracts/DioneStaking.sol b/eth-contracts/contracts/DioneStaking.sol index 79fb5e5..0d0c751 100644 --- a/eth-contracts/contracts/DioneStaking.sol +++ b/eth-contracts/contracts/DioneStaking.sol @@ -40,15 +40,18 @@ contract DioneStaking is Ownable, ReentrancyGuard { event Withdraw(address indexed miner, uint256 amount); event Mine(address indexed miner, uint256 blockNumber); + modifier onlyMiner(address _minerAddr) { + require(isMiner(_minerAddr), "Exception: caller is not the miner"); + _; + } + constructor( DioneToken _dione, - address _aggregatorAddr, uint256 _minerReward, uint256 _startBlock, uint256 _minimumStake ) public { dione = _dione; - aggregatorAddr = _aggregatorAddr; minerReward = _minerReward; startBlock = _startBlock; minimumStake = _minimumStake; @@ -107,8 +110,7 @@ contract DioneStaking is Ownable, ReentrancyGuard { } function minerStake(address _minerAddr) external view returns (uint256) { - MinerInfo storage miner = minerInfo[_minerAddr]; - return miner.amount; + return minerInfo[_minerAddr].amount; } // Update miner reward in DIONE tokens, only can be executed by owner of the contract @@ -117,12 +119,8 @@ contract DioneStaking is Ownable, ReentrancyGuard { minerReward = _minerReward; } - function isLegitMiner(address _minerAddr) external returns (bool) { - MinerInfo storage miner = minerInfo[_minerAddr]; - if (miner.amount >= minimumStake) { - return true; - } - return false; + function isMiner(address _minerAddr) public view returns (bool) { + return minerInfo[_minerAddr].amount >= minimumStake; } // Update minimum stake in DIONE tokens for miners, only can be executed by owner of the contract @@ -131,4 +129,7 @@ contract DioneStaking is Ownable, ReentrancyGuard { minimumStake = _minimumStake; } + function setAggregator(address _aggregatorAddr) public onlyOwner { + aggregatorAddr = _aggregatorAddr; + } } \ No newline at end of file diff --git a/node/ethereum.go b/node/ethereum.go index ed3e8a8..ae2c387 100644 --- a/node/ethereum.go +++ b/node/ethereum.go @@ -25,10 +25,9 @@ func (n *Node) subscribeOnEthContracts(ctx context.Context) { if task == nil { continue } - logrus.Info("BlockHash for Solana transaction: ", task.BlockHash) - logrus.Info("Started new consensus round with ID: ", task.BlockHash) + logrus.Info("Started new consensus round with ID: ", task.Signature) - err = n.ConsensusManager.Propose(event.RequestID.String(), task.BlockHash, event.RequestID, event.CallbackAddress) + err = n.ConsensusManager.Propose(event.RequestID.String(), string(task.Payload), event.RequestID, event.CallbackAddress) if err != nil { logrus.Errorf("Failed to propose task: %w", err) } diff --git a/types/task.go b/types/task.go index 08027ed..ca48994 100644 --- a/types/task.go +++ b/types/task.go @@ -28,6 +28,7 @@ func (e DrandRound) String() string { // DioneTask represents the values of task computation // Miner is an address of miner node type DioneTask struct { + Miner peer.ID Type TaskType Ticket *Ticket ElectionProof *ElectionProof @@ -49,6 +50,7 @@ func NewDioneTask( ) *DioneTask { return &DioneTask{ Type: t, + Miner: miner, Ticket: ticket, ElectionProof: electionProof, BeaconEntries: beacon,