Reduce params count for submission in DioneOracle contract, fix small stupid bugs in dione

This commit is contained in:
ChronosX88 2021-04-19 22:46:17 +03:00
parent acf6a5cdcb
commit f0ecad1cbf
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
7 changed files with 72 additions and 79 deletions

View File

@ -27,8 +27,8 @@ type EthereumConfig struct {
PrivateKey string `mapstructure:"private_key"`
MnemonicPhrase string `mapstructure:"mnemonic_phrase"`
HDDerivationPath string `mapstructure:"hd_derivation_path"`
DioneOracleContractAddress string `mapstructure:"dione_oracle_contract_address"`
DioneStakingContractAddress string `mapstructure:"dione_staking_address"`
DioneOracleContractAddress string `mapstructure:"oracle_contract_address"`
DioneStakingContractAddress string `mapstructure:"staking_contract_address"`
DisputeContractAddress string `mapstructure:"dispute_contract_address"`
}

View File

@ -10,8 +10,6 @@ import (
"github.com/Secured-Finance/dione/consensus/types"
"github.com/ethereum/go-ethereum/common"
"github.com/Secured-Finance/dione/ethclient"
"github.com/sirupsen/logrus"
@ -161,15 +159,8 @@ func (pcm *PBFTConsensusManager) handleCommit(message *types.Message) {
if !ok {
logrus.Errorf("Failed to parse request ID: %v", consensusMsg.Task.RequestID)
}
callbackAddress := common.BytesToAddress(consensusMsg.Task.CallbackAddress)
request, err := pcm.eventCache.GetOracleRequestEvent("request_" + consensusMsg.Task.RequestID)
if err != nil {
logrus.Errorf("Failed to get request from cache: %v", err.Error())
return
}
err = pcm.ethereumClient.SubmitRequestAnswer(reqID, callbackAddress, request.CallbackMethodID, request.RequestParams, request.Deadline, consensusMsg.Task.Payload)
err = pcm.ethereumClient.SubmitRequestAnswer(reqID, consensusMsg.Task.Payload)
if err != nil {
logrus.Errorf("Failed to submit on-chain result: %v", err)
}

View File

@ -19,7 +19,7 @@ type DisputeManager struct {
ctx context.Context
ethClient *ethclient.EthereumClient
pcm *PBFTConsensusManager
submittionMap map[string]*dioneOracle.DioneOracleSubmittedOracleRequest
submissionMap map[string]*dioneOracle.DioneOracleSubmittedOracleRequest
disputeMap map[string]*dioneDispute.DioneDisputeNewDispute
}
@ -38,7 +38,8 @@ func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient,
ethClient: ethClient,
pcm: pcm,
ctx: ctx,
submittionMap: map[string]*dioneOracle.DioneOracleSubmittedOracleRequest{},
submissionMap: map[string]*dioneOracle.DioneOracleSubmittedOracleRequest{},
disputeMap: map[string]*dioneDispute.DioneDisputeNewDispute{},
}
go func() {
@ -52,7 +53,7 @@ func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient,
}
case s := <-newSubmittionsChan:
{
dm.onNewSubmittion(s)
dm.onNewSubmission(s)
}
case d := <-newDisputesChan:
{
@ -65,20 +66,21 @@ func NewDisputeManager(ctx context.Context, ethClient *ethclient.EthereumClient,
return dm, nil
}
func (dm *DisputeManager) onNewSubmittion(submittion *dioneOracle.DioneOracleSubmittedOracleRequest) {
func (dm *DisputeManager) onNewSubmission(submittion *dioneOracle.DioneOracleSubmittedOracleRequest) {
c := dm.pcm.GetConsensusInfo(submittion.ReqID.String())
if c == nil {
// todo: warn
return
}
dm.submittionMap[submittion.ReqID.String()] = submittion
dm.submissionMap[submittion.ReqID.String()] = submittion
submHashBytes := sha3.Sum256(submittion.Data)
localHashBytes := sha3.Sum256(c.Task.Payload)
submHash := hex.EncodeToString(submHashBytes[:])
localHash := hex.EncodeToString(localHashBytes[:])
if submHash != localHash {
logrus.Debugf("submission of request id %s isn't valid - beginning dispute", c.Task.RequestID)
addr := common.HexToAddress(c.Task.MinerEth)
reqID, ok := big.NewInt(0).SetString(c.Task.RequestID, 10)
if !ok {
@ -122,7 +124,7 @@ func (dm *DisputeManager) onNewDispute(dispute *dioneDispute.DioneDisputeNewDisp
return
}
subm, ok := dm.submittionMap[dispute.RequestID.String()]
subm, ok := dm.submissionMap[dispute.RequestID.String()]
if !ok {
// todo: warn
return

View File

@ -174,7 +174,7 @@ func (ppp *PrePreparePool) IsValidPrePrepare(prePrepare *types2.Message) bool {
logrus.Errorf("payload validation has failed: %v", err)
}
} else {
logrus.Warnf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType)
logrus.Debugf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", consensusMsg.Task.OriginChain, consensusMsg.Task.RequestType)
}
/////////////////////////////////

View File

@ -27,7 +27,7 @@ var (
)
// DioneOracleABI is the input ABI used to generate the binding from.
const DioneOracleABI = "[{\"inputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"}],\"name\":\"CancelOracleRequest\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"originChain\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"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\":false,\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"SubmittedOracleRequest\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"MAXIMUM_DELAY\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumDisputeFee\",\"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\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"_originChain\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"_requestType\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_requestParams\",\"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\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_requestParams\",\"type\":\"string\"},{\"internalType\":\"bytes4\",\"name\":\"_callbackMethodID\",\"type\":\"bytes4\"},{\"internalType\":\"uint256\",\"name\":\"_reqID\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_requestDeadline\",\"type\":\"uint256\"}],\"name\":\"cancelOracleRequest\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_requestParams\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"_callbackAddress\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"_callbackMethodID\",\"type\":\"bytes4\"},{\"internalType\":\"uint256\",\"name\":\"_reqID\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_requestDeadline\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"submitOracleRequest\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
const DioneOracleABI = "[{\"inputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"_dioneStaking\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"}],\"name\":\"CancelOracleRequest\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint8\",\"name\":\"originChain\",\"type\":\"uint8\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"requestParams\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"callbackAddress\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"bytes4\",\"name\":\"callbackMethodID\",\"type\":\"bytes4\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"deadline\",\"type\":\"uint256\"}],\"name\":\"NewOracleRequest\",\"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\":false,\"internalType\":\"uint256\",\"name\":\"reqID\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"name\":\"SubmittedOracleRequest\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"MAXIMUM_DELAY\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_reqID\",\"type\":\"uint256\"}],\"name\":\"cancelOracleRequest\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"dioneStaking\",\"outputs\":[{\"internalType\":\"contractIDioneStaking\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"minimumDisputeFee\",\"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\":[{\"internalType\":\"uint8\",\"name\":\"_originChain\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"_requestType\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_requestParams\",\"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\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_reqID\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"submitOracleRequest\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
// DioneOracle is an auto generated Go binding around an Ethereum contract.
type DioneOracle struct {
@ -295,25 +295,25 @@ func (_DioneOracle *DioneOracleCallerSession) Owner() (common.Address, error) {
return _DioneOracle.Contract.Owner(&_DioneOracle.CallOpts)
}
// CancelOracleRequest is a paid mutator transaction binding the contract method 0xb509ff78.
// CancelOracleRequest is a paid mutator transaction binding the contract method 0x1d2a198a.
//
// Solidity: function cancelOracleRequest(string _requestParams, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline) returns()
func (_DioneOracle *DioneOracleTransactor) CancelOracleRequest(opts *bind.TransactOpts, _requestParams string, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int) (*types.Transaction, error) {
return _DioneOracle.contract.Transact(opts, "cancelOracleRequest", _requestParams, _callbackMethodID, _reqID, _requestDeadline)
// Solidity: function cancelOracleRequest(uint256 _reqID) returns()
func (_DioneOracle *DioneOracleTransactor) CancelOracleRequest(opts *bind.TransactOpts, _reqID *big.Int) (*types.Transaction, error) {
return _DioneOracle.contract.Transact(opts, "cancelOracleRequest", _reqID)
}
// CancelOracleRequest is a paid mutator transaction binding the contract method 0xb509ff78.
// CancelOracleRequest is a paid mutator transaction binding the contract method 0x1d2a198a.
//
// Solidity: function cancelOracleRequest(string _requestParams, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline) returns()
func (_DioneOracle *DioneOracleSession) CancelOracleRequest(_requestParams string, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int) (*types.Transaction, error) {
return _DioneOracle.Contract.CancelOracleRequest(&_DioneOracle.TransactOpts, _requestParams, _callbackMethodID, _reqID, _requestDeadline)
// Solidity: function cancelOracleRequest(uint256 _reqID) returns()
func (_DioneOracle *DioneOracleSession) CancelOracleRequest(_reqID *big.Int) (*types.Transaction, error) {
return _DioneOracle.Contract.CancelOracleRequest(&_DioneOracle.TransactOpts, _reqID)
}
// CancelOracleRequest is a paid mutator transaction binding the contract method 0xb509ff78.
// CancelOracleRequest is a paid mutator transaction binding the contract method 0x1d2a198a.
//
// Solidity: function cancelOracleRequest(string _requestParams, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline) returns()
func (_DioneOracle *DioneOracleTransactorSession) CancelOracleRequest(_requestParams string, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int) (*types.Transaction, error) {
return _DioneOracle.Contract.CancelOracleRequest(&_DioneOracle.TransactOpts, _requestParams, _callbackMethodID, _reqID, _requestDeadline)
// Solidity: function cancelOracleRequest(uint256 _reqID) returns()
func (_DioneOracle *DioneOracleTransactorSession) CancelOracleRequest(_reqID *big.Int) (*types.Transaction, error) {
return _DioneOracle.Contract.CancelOracleRequest(&_DioneOracle.TransactOpts, _reqID)
}
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
@ -358,25 +358,25 @@ func (_DioneOracle *DioneOracleTransactorSession) RequestOracles(_originChain ui
return _DioneOracle.Contract.RequestOracles(&_DioneOracle.TransactOpts, _originChain, _requestType, _requestParams, _callbackAddress, _callbackMethodID)
}
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xabb0e32a.
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xcbed450e.
//
// Solidity: function submitOracleRequest(string _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleTransactor) SubmitOracleRequest(opts *bind.TransactOpts, _requestParams string, _callbackAddress common.Address, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.contract.Transact(opts, "submitOracleRequest", _requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline, _data)
// Solidity: function submitOracleRequest(uint256 _reqID, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleTransactor) SubmitOracleRequest(opts *bind.TransactOpts, _reqID *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.contract.Transact(opts, "submitOracleRequest", _reqID, _data)
}
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xabb0e32a.
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xcbed450e.
//
// Solidity: function submitOracleRequest(string _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleSession) SubmitOracleRequest(_requestParams string, _callbackAddress common.Address, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.Contract.SubmitOracleRequest(&_DioneOracle.TransactOpts, _requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline, _data)
// Solidity: function submitOracleRequest(uint256 _reqID, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleSession) SubmitOracleRequest(_reqID *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.Contract.SubmitOracleRequest(&_DioneOracle.TransactOpts, _reqID, _data)
}
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xabb0e32a.
// SubmitOracleRequest is a paid mutator transaction binding the contract method 0xcbed450e.
//
// Solidity: function submitOracleRequest(string _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleTransactorSession) SubmitOracleRequest(_requestParams string, _callbackAddress common.Address, _callbackMethodID [4]byte, _reqID *big.Int, _requestDeadline *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.Contract.SubmitOracleRequest(&_DioneOracle.TransactOpts, _requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline, _data)
// Solidity: function submitOracleRequest(uint256 _reqID, bytes _data) returns(bool)
func (_DioneOracle *DioneOracleTransactorSession) SubmitOracleRequest(_reqID *big.Int, _data []byte) (*types.Transaction, error) {
return _DioneOracle.Contract.SubmitOracleRequest(&_DioneOracle.TransactOpts, _reqID, _data)
}
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
@ -896,18 +896,14 @@ func (it *DioneOracleSubmittedOracleRequestIterator) Close() error {
// DioneOracleSubmittedOracleRequest represents a SubmittedOracleRequest event raised by the DioneOracle contract.
type DioneOracleSubmittedOracleRequest struct {
RequestParams string
CallbackAddress common.Address
CallbackMethodID [4]byte
ReqID *big.Int
Deadline *big.Int
Data []byte
Raw types.Log // Blockchain specific contextual infos
ReqID *big.Int
Data []byte
Raw types.Log // Blockchain specific contextual infos
}
// FilterSubmittedOracleRequest is a free log retrieval operation binding the contract event 0x19cfd2527b69fe86ec071989b16b761fdd69e5130930e9edb3247888ebbbb96c.
// FilterSubmittedOracleRequest is a free log retrieval operation binding the contract event 0x30c6663e7dc6e4e92bde7b263ac094ed9141eba4437261c482c14e41d855040f.
//
// Solidity: event SubmittedOracleRequest(string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 reqID, uint256 deadline, bytes data)
// Solidity: event SubmittedOracleRequest(uint256 reqID, bytes data)
func (_DioneOracle *DioneOracleFilterer) FilterSubmittedOracleRequest(opts *bind.FilterOpts) (*DioneOracleSubmittedOracleRequestIterator, error) {
logs, sub, err := _DioneOracle.contract.FilterLogs(opts, "SubmittedOracleRequest")
@ -917,9 +913,9 @@ func (_DioneOracle *DioneOracleFilterer) FilterSubmittedOracleRequest(opts *bind
return &DioneOracleSubmittedOracleRequestIterator{contract: _DioneOracle.contract, event: "SubmittedOracleRequest", logs: logs, sub: sub}, nil
}
// WatchSubmittedOracleRequest is a free log subscription operation binding the contract event 0x19cfd2527b69fe86ec071989b16b761fdd69e5130930e9edb3247888ebbbb96c.
// WatchSubmittedOracleRequest is a free log subscription operation binding the contract event 0x30c6663e7dc6e4e92bde7b263ac094ed9141eba4437261c482c14e41d855040f.
//
// Solidity: event SubmittedOracleRequest(string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 reqID, uint256 deadline, bytes data)
// Solidity: event SubmittedOracleRequest(uint256 reqID, bytes data)
func (_DioneOracle *DioneOracleFilterer) WatchSubmittedOracleRequest(opts *bind.WatchOpts, sink chan<- *DioneOracleSubmittedOracleRequest) (event.Subscription, error) {
logs, sub, err := _DioneOracle.contract.WatchLogs(opts, "SubmittedOracleRequest")
@ -954,9 +950,9 @@ func (_DioneOracle *DioneOracleFilterer) WatchSubmittedOracleRequest(opts *bind.
}), nil
}
// ParseSubmittedOracleRequest is a log parse operation binding the contract event 0x19cfd2527b69fe86ec071989b16b761fdd69e5130930e9edb3247888ebbbb96c.
// ParseSubmittedOracleRequest is a log parse operation binding the contract event 0x30c6663e7dc6e4e92bde7b263ac094ed9141eba4437261c482c14e41d855040f.
//
// Solidity: event SubmittedOracleRequest(string requestParams, address callbackAddress, bytes4 callbackMethodID, uint256 reqID, uint256 deadline, bytes data)
// Solidity: event SubmittedOracleRequest(uint256 reqID, bytes data)
func (_DioneOracle *DioneOracleFilterer) ParseSubmittedOracleRequest(log types.Log) (*DioneOracleSubmittedOracleRequest, error) {
event := new(DioneOracleSubmittedOracleRequest)
if err := _DioneOracle.contract.UnpackLog(event, "SubmittedOracleRequest", log); err != nil {

View File

@ -6,11 +6,11 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IDioneStaking.sol";
contract DioneOracle is Ownable {
contract DioneOracle {
using SafeMath for uint256;
// Global counter of oracle requests, works as an index in mapping structures
uint256 private requestCounter;
uint256 private requestCounter = 0;
// Maximum time for computing oracle request
uint256 constant public MAXIMUM_DELAY = 5 minutes;
// Dione staking contract
@ -19,6 +19,7 @@ contract DioneOracle is Ownable {
uint256 public minimumDisputeFee = 100**18;
struct OracleRequest {
address requestSender;
uint8 originChain; // origin blockchain for request
string requestType; // rpc call type
string requestParams; // rpc call params
@ -29,7 +30,7 @@ contract DioneOracle is Ownable {
bytes data;
}
mapping(uint256 => bytes32) private pendingRequests;
mapping(uint256 => OracleRequest) private pendingRequests;
event NewOracleRequest(
uint8 originChain,
@ -46,16 +47,12 @@ contract DioneOracle is Ownable {
);
event SubmittedOracleRequest(
string requestParams,
address callbackAddress,
bytes4 callbackMethodID,
uint256 reqID,
uint256 deadline,
bytes data
);
modifier onlyPendingRequest(uint256 _reqID) {
require(pendingRequests[_reqID] != 0, "This request is not pending");
require(pendingRequests[_reqID].requestSender != address(0), "This request is not pending");
_;
}
@ -65,30 +62,37 @@ contract DioneOracle is Ownable {
function requestOracles(uint8 _originChain, string memory _requestType, string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID) public returns (uint256) {
requestCounter += 1;
require(pendingRequests[requestCounter] == 0, "This counter is not unique");
require(pendingRequests[requestCounter].reqID == 0, "This counter is not unique");
uint256 requestDeadline = block.timestamp.add(MAXIMUM_DELAY);
pendingRequests[requestCounter] = keccak256(abi.encodePacked(_requestParams, _callbackAddress, _callbackMethodID, requestCounter, requestDeadline));
pendingRequests[requestCounter] = OracleRequest({
requestSender: msg.sender,
originChain: _originChain,
requestType: _requestType,
requestParams: _requestParams,
callbackAddress: _callbackAddress,
callbackMethodID: _callbackMethodID,
reqID: requestCounter,
deadline: requestDeadline,
data: new bytes(0)
});
emit NewOracleRequest(_originChain, _requestType, _requestParams, _callbackAddress, _callbackMethodID, requestCounter, requestDeadline);
return requestCounter;
}
function cancelOracleRequest(string memory _requestParams, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline) public {
bytes32 requestHash = keccak256(abi.encodePacked(_requestParams, msg.sender, _callbackMethodID, _reqID, _requestDeadline));
require(requestHash == pendingRequests[_reqID], "Request hash do not match it's origin");
require(_requestDeadline <= block.timestamp, "Request didn't reached it's deadline");
function cancelOracleRequest(uint256 _reqID) public onlyPendingRequest(_reqID) {
require(msg.sender == pendingRequests[_reqID].requestSender, "you aren't request sender");
delete pendingRequests[_reqID];
emit CancelOracleRequest(_reqID);
}
function submitOracleRequest(string memory _requestParams, address _callbackAddress, bytes4 _callbackMethodID, uint256 _reqID, uint256 _requestDeadline, bytes memory _data) public onlyPendingRequest(_reqID) returns (bool) {
bytes32 requestHash = keccak256(abi.encodePacked(_requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline));
require(pendingRequests[_reqID] == requestHash, "Params do not match request ID");
function submitOracleRequest(uint256 _reqID, bytes memory _data) public onlyPendingRequest(_reqID) returns (bool) {
delete pendingRequests[_reqID];
dioneStaking.mine(msg.sender);
(bool success, ) = _callbackAddress.call(abi.encodeWithSelector(_callbackMethodID, _reqID, _data)); // TODO: check on success call
emit SubmittedOracleRequest(_requestParams, _callbackAddress, _callbackMethodID, _reqID, _requestDeadline, _data);
return success;
(bool success, ) = pendingRequests[_reqID].callbackAddress.call(abi.encodeWithSelector(pendingRequests[_reqID].callbackMethodID, _reqID, _data));
require(success == true, "cannot call callback method");
emit SubmittedOracleRequest(_reqID, _data);
return true;
}
}

View File

@ -184,8 +184,8 @@ func (c *EthereumClient) SubscribeOnOracleEvents(ctx context.Context) (chan *dio
return resChan, subscription, err
}
func (c *EthereumClient) SubmitRequestAnswer(reqID *big.Int, callbackAddress common.Address, callbackMethodID [4]byte, requestParams string, requestDeadline *big.Int, data []byte) error {
_, err := c.dioneOracle.SubmitOracleRequest(requestParams, callbackAddress, callbackMethodID, reqID, requestDeadline, data)
func (c *EthereumClient) SubmitRequestAnswer(reqID *big.Int, data []byte) error {
_, err := c.dioneOracle.SubmitOracleRequest(reqID, data)
if err != nil {
return err
}