fix: aggregator contract

This commit is contained in:
bahadylbekov 2020-11-15 13:16:38 +03:00
parent b04ba982a9
commit 78e4ec34a6
5 changed files with 24 additions and 22 deletions

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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)")));
}

View File

@ -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;

View File

@ -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
}