fix: aggregator contract
This commit is contained in:
parent
b04ba982a9
commit
78e4ec34a6
@ -27,7 +27,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// AggregatorABI is the input ABI used to generate the binding from.
|
// 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.
|
// Aggregator is an auto generated Go binding around an Ethereum contract.
|
||||||
type Aggregator struct {
|
type Aggregator struct {
|
||||||
@ -223,25 +223,25 @@ func (_Aggregator *AggregatorCallerSession) Owner() (common.Address, error) {
|
|||||||
return _Aggregator.Contract.Owner(&_Aggregator.CallOpts)
|
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()
|
// 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, callbackMethodID [4]byte) (*types.Transaction, error) {
|
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, callbackMethodID)
|
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()
|
// Solidity: function collectData(uint256 reqID, string data, address callbackAddress) returns()
|
||||||
func (_Aggregator *AggregatorSession) 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) (*types.Transaction, error) {
|
||||||
return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID)
|
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()
|
// Solidity: function collectData(uint256 reqID, string data, address callbackAddress) returns()
|
||||||
func (_Aggregator *AggregatorTransactorSession) 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) (*types.Transaction, error) {
|
||||||
return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress, callbackMethodID)
|
return _Aggregator.Contract.CollectData(&_Aggregator.TransactOpts, reqID, data, callbackAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
|
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
|
||||||
|
@ -10,6 +10,10 @@ interface IDioneStaking {
|
|||||||
function isLegitMiner(address _minerAddr) external returns (bool);
|
function isLegitMiner(address _minerAddr) external returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IMediator {
|
||||||
|
function _receiveDataCallback(uint256 reqID, string memory data) external;
|
||||||
|
}
|
||||||
|
|
||||||
contract Aggregator is Ownable, ReentrancyGuard {
|
contract Aggregator is Ownable, ReentrancyGuard {
|
||||||
IDioneStaking public dioneStaking;
|
IDioneStaking public dioneStaking;
|
||||||
|
|
||||||
@ -18,9 +22,7 @@ contract Aggregator is Ownable, ReentrancyGuard {
|
|||||||
dioneStaking = _dioneStaking;
|
dioneStaking = _dioneStaking;
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectData(uint256 reqID, string memory data, address callbackAddress, bytes4 callbackMethodID) public nonReentrant {
|
function collectData(uint256 reqID, string memory data, IMediator callbackAddress) public nonReentrant {
|
||||||
require(dioneStaking.isLegitMiner(msg.sender));
|
callbackAddress._receiveDataCallback(reqID, data);
|
||||||
(bool success,) = callbackAddress.call(abi.encode(callbackMethodID, reqID, data));
|
|
||||||
require(success);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ contract Mediator is Ownable {
|
|||||||
aggregator = _aggregator;
|
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)")));
|
return oracleEmitter.requestOracles(originChain, requestType, requestParams, address(this), bytes4(keccak256("_receiveDataCallback(uint256, string)")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,15 +5,15 @@ contract OracleEmitter {
|
|||||||
uint256 requestCounter;
|
uint256 requestCounter;
|
||||||
|
|
||||||
event NewOracleRequest(
|
event NewOracleRequest(
|
||||||
uint8 originChain,
|
string originChain,
|
||||||
uint8 requestType,
|
string requestType,
|
||||||
string requestParams,
|
string requestParams,
|
||||||
address callbackAddress,
|
address callbackAddress,
|
||||||
bytes4 callbackMethodID,
|
bytes4 callbackMethodID,
|
||||||
uint256 requestID
|
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++;
|
requestCounter++;
|
||||||
emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter);
|
emit NewOracleRequest(originChain, requestType, requestParams, callbackAddress, callbackMethodID, requestCounter);
|
||||||
return requestCounter;
|
return requestCounter;
|
||||||
|
@ -162,7 +162,7 @@ func (c *EthereumClient) SubmitRequestAnswer(reqID *big.Int, data string, callba
|
|||||||
// c.Logger.Fatal(err)
|
// c.Logger.Fatal(err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
_, err := c.aggregator.CollectData(reqID, data, callbackAddress, callbackMethodID)
|
_, err := c.aggregator.CollectData(reqID, data, callbackAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user