From 78e4ec34a6d537cdd1021c668355855ef836f904 Mon Sep 17 00:00:00 2001 From: bahadylbekov <33404905+bahadylbekov@users.noreply.github.com> Date: Sun, 15 Nov 2020 13:16:38 +0300 Subject: [PATCH] fix: aggregator contract --- contracts/aggregator/Aggregator.go | 26 +++++++++++------------ eth-contracts/contracts/Aggregator.sol | 10 +++++---- eth-contracts/contracts/Mediator.sol | 2 +- eth-contracts/contracts/OracleEmitter.sol | 6 +++--- ethclient/ethereum.go | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/contracts/aggregator/Aggregator.go b/contracts/aggregator/Aggregator.go index eb270e9..7156d31 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\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"}],\"name\":\"collectData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" +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\"}]" // Aggregator is an auto generated Go binding around an Ethereum contract. type Aggregator struct { @@ -223,25 +223,25 @@ func (_Aggregator *AggregatorCallerSession) Owner() (common.Address, error) { return _Aggregator.Contract.Owner(&_Aggregator.CallOpts) } -// CollectData is a paid mutator transaction binding the contract method 0x05187092. +// CollectData is a paid mutator transaction binding the contract method 0xce45d837. // -// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() -func (_Aggregator *AggregatorTransactor) CollectData(opts *bind.TransactOpts, reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { - return _Aggregator.contract.Transact(opts, "collectData", reqID, data, callbackAddress, callbackMethodID) +// Solidity: function collectData(uint256 reqID, string data, address callbackAddress) returns() +func (_Aggregator *AggregatorTransactor) CollectData(opts *bind.TransactOpts, reqID *big.Int, data string, callbackAddress common.Address) (*types.Transaction, error) { + return _Aggregator.contract.Transact(opts, "collectData", reqID, data, callbackAddress) } -// CollectData is a paid mutator transaction binding the contract method 0x05187092. +// CollectData is a paid mutator transaction binding the contract method 0xce45d837. // -// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() -func (_Aggregator *AggregatorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { - return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID) +// Solidity: function collectData(uint256 reqID, string data, address callbackAddress) returns() +func (_Aggregator *AggregatorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address) (*types.Transaction, error) { + return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress) } -// CollectData is a paid mutator transaction binding the contract method 0x05187092. +// CollectData is a paid mutator transaction binding the contract method 0xce45d837. // -// Solidity: function collectData(uint256 reqID, string data, address callbackAddress, bytes4 callbackMethodID) returns() -func (_Aggregator *AggregatorTransactorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address, callbackMethodID [4]byte) (*types.Transaction, error) { - return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID) +// Solidity: function collectData(uint256 reqID, string data, address callbackAddress) returns() +func (_Aggregator *AggregatorTransactorSession) CollectData(reqID *big.Int, data string, callbackAddress common.Address) (*types.Transaction, error) { + return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress) } // RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6. diff --git a/eth-contracts/contracts/Aggregator.sol b/eth-contracts/contracts/Aggregator.sol index 164f2d3..f4c1b43 100644 --- a/eth-contracts/contracts/Aggregator.sol +++ b/eth-contracts/contracts/Aggregator.sol @@ -10,6 +10,10 @@ interface IDioneStaking { function isLegitMiner(address _minerAddr) external returns (bool); } +interface IMediator { + function _receiveDataCallback(uint256 reqID, string memory data) external; +} + contract Aggregator is Ownable, ReentrancyGuard { IDioneStaking public dioneStaking; @@ -18,9 +22,7 @@ contract Aggregator is Ownable, ReentrancyGuard { dioneStaking = _dioneStaking; } - function collectData(uint256 reqID, string memory data, address callbackAddress, bytes4 callbackMethodID) public nonReentrant { - require(dioneStaking.isLegitMiner(msg.sender)); - (bool success,) = callbackAddress.call(abi.encode(callbackMethodID, reqID, data)); - require(success); + function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public nonReentrant { + callbackAddress._receiveDataCallback(reqID, data); } } diff --git a/eth-contracts/contracts/Mediator.sol b/eth-contracts/contracts/Mediator.sol index 2363306..fcbac98 100644 --- a/eth-contracts/contracts/Mediator.sol +++ b/eth-contracts/contracts/Mediator.sol @@ -18,7 +18,7 @@ contract Mediator is Ownable { aggregator = _aggregator; } - function request(uint8 memory originChain, uint8 memory requestType, string memory requestParams) public returns (uint256) { + function request(string memory originChain, string memory requestType, string memory requestParams) public returns (uint256) { return oracleEmitter.requestOracles(originChain, requestType, requestParams, address(this), bytes4(keccak256("_receiveDataCallback(uint256, string)"))); } diff --git a/eth-contracts/contracts/OracleEmitter.sol b/eth-contracts/contracts/OracleEmitter.sol index f0df37a..b0a3b14 100644 --- a/eth-contracts/contracts/OracleEmitter.sol +++ b/eth-contracts/contracts/OracleEmitter.sol @@ -5,15 +5,15 @@ contract OracleEmitter { uint256 requestCounter; event NewOracleRequest( - uint8 originChain, - uint8 requestType, + string originChain, + string requestType, string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 requestID ); - function requestOracles(uint8 memory originChain, uint8 memory requestType, string memory requestParams, address callbackAddress, bytes4 callbackMethodID) public returns (uint256) { + function requestOracles(string memory originChain, string memory requestType, string memory requestParams, address callbackAddress, bytes4 callbackMethodID) public returns (uint256) { requestCounter++; emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter); return requestCounter; diff --git a/ethclient/ethereum.go b/ethclient/ethereum.go index e0c542e..32c4e12 100644 --- a/ethclient/ethereum.go +++ b/ethclient/ethereum.go @@ -162,7 +162,7 @@ func (c *EthereumClient) SubmitRequestAnswer(reqID *big.Int, data string, callba // c.Logger.Fatal(err) // } - _, err := c.aggregator.CollectData(reqID, data, callbackAddress, callbackMethodID) + _, err := c.aggregator.CollectData(reqID, data, callbackAddress) if err != nil { return err }