From 629eed9a7c940e62b3ff16bd097a0c176d9ad977 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 26 Sep 2023 14:46:20 +0800 Subject: [PATCH] use cb events --- .../precompile/ica/i_ica_module.abigen.go | 287 +++++++++++++++++- x/cronos/events/bindings/src/ICA.sol | 23 ++ x/cronos/events/events.go | 16 +- 3 files changed, 324 insertions(+), 2 deletions(-) diff --git a/x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go b/x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go index dfc2242bb3..277e2c80fe 100644 --- a/x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go +++ b/x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go @@ -30,7 +30,7 @@ var ( // ICAModuleMetaData contains all meta data concerning the ICAModule contract. var ICAModuleMetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"}],\"name\":\"SubmitMsgsResult\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"packetSenderAddress\",\"type\":\"string\"}],\"name\":\"onAcknowledgementPacketCallback\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"packetSenderAddress\",\"type\":\"string\"}],\"name\":\"onTimeoutPacketCallback\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"addr\",\"type\":\"address\"}],\"name\":\"queryAccount\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"version\",\"type\":\"string\"}],\"name\":\"registerAccount\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"},{\"internalType\":\"uint256\",\"name\":\"timeout\",\"type\":\"uint256\"}],\"name\":\"submitMsgs\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"payable\",\"type\":\"function\"}]", + ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"module\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackAddress\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackResult\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackError\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackExecGasLimit\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackCommitGasLimit\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetDestPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetDestChannel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetSequence\",\"type\":\"string\"}],\"name\":\"DestinationCallback\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"module\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackType\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackAddress\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackResult\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackExecGasLimit\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callbackCommitGasLimit\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetSrcPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetSrcChannel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"packetSequence\",\"type\":\"string\"}],\"name\":\"SourceCallback\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"}],\"name\":\"SubmitMsgsResult\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"packetSenderAddress\",\"type\":\"string\"}],\"name\":\"onAcknowledgementPacketCallback\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"seq\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"packetSenderAddress\",\"type\":\"string\"}],\"name\":\"onTimeoutPacketCallback\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"addr\",\"type\":\"address\"}],\"name\":\"queryAccount\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"version\",\"type\":\"string\"}],\"name\":\"registerAccount\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"connectionID\",\"type\":\"string\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"},{\"internalType\":\"uint256\",\"name\":\"timeout\",\"type\":\"uint256\"}],\"name\":\"submitMsgs\",\"outputs\":[{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"stateMutability\":\"payable\",\"type\":\"function\"}]", } // ICAModuleABI is the input ABI used to generate the binding from. @@ -294,6 +294,291 @@ func (_ICAModule *ICAModuleTransactorSession) SubmitMsgs(connectionID string, da return _ICAModule.Contract.SubmitMsgs(&_ICAModule.TransactOpts, connectionID, data, timeout) } +// ICAModuleDestinationCallbackIterator is returned from FilterDestinationCallback and is used to iterate over the raw logs and unpacked data for DestinationCallback events raised by the ICAModule contract. +type ICAModuleDestinationCallbackIterator struct { + Event *ICAModuleDestinationCallback // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *ICAModuleDestinationCallbackIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(ICAModuleDestinationCallback) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(ICAModuleDestinationCallback) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *ICAModuleDestinationCallbackIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *ICAModuleDestinationCallbackIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// ICAModuleDestinationCallback represents a DestinationCallback event raised by the ICAModule contract. +type ICAModuleDestinationCallback struct { + Module string + CallbackType string + CallbackAddress string + CallbackResult string + CallbackError string + CallbackExecGasLimit string + CallbackCommitGasLimit string + PacketDestPort string + PacketDestChannel string + PacketSequence string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterDestinationCallback is a free log retrieval operation binding the contract event 0x2ae174bea5540138f8433743ac6f4338f304522f95b07f0fbfaeb260143a71ba. +// +// Solidity: event DestinationCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackError, string callbackExecGasLimit, string callbackCommitGasLimit, string packetDestPort, string packetDestChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) FilterDestinationCallback(opts *bind.FilterOpts) (*ICAModuleDestinationCallbackIterator, error) { + + logs, sub, err := _ICAModule.contract.FilterLogs(opts, "DestinationCallback") + if err != nil { + return nil, err + } + return &ICAModuleDestinationCallbackIterator{contract: _ICAModule.contract, event: "DestinationCallback", logs: logs, sub: sub}, nil +} + +// WatchDestinationCallback is a free log subscription operation binding the contract event 0x2ae174bea5540138f8433743ac6f4338f304522f95b07f0fbfaeb260143a71ba. +// +// Solidity: event DestinationCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackError, string callbackExecGasLimit, string callbackCommitGasLimit, string packetDestPort, string packetDestChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) WatchDestinationCallback(opts *bind.WatchOpts, sink chan<- *ICAModuleDestinationCallback) (event.Subscription, error) { + + logs, sub, err := _ICAModule.contract.WatchLogs(opts, "DestinationCallback") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(ICAModuleDestinationCallback) + if err := _ICAModule.contract.UnpackLog(event, "DestinationCallback", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseDestinationCallback is a log parse operation binding the contract event 0x2ae174bea5540138f8433743ac6f4338f304522f95b07f0fbfaeb260143a71ba. +// +// Solidity: event DestinationCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackError, string callbackExecGasLimit, string callbackCommitGasLimit, string packetDestPort, string packetDestChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) ParseDestinationCallback(log types.Log) (*ICAModuleDestinationCallback, error) { + event := new(ICAModuleDestinationCallback) + if err := _ICAModule.contract.UnpackLog(event, "DestinationCallback", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + +// ICAModuleSourceCallbackIterator is returned from FilterSourceCallback and is used to iterate over the raw logs and unpacked data for SourceCallback events raised by the ICAModule contract. +type ICAModuleSourceCallbackIterator struct { + Event *ICAModuleSourceCallback // Event containing the contract specifics and raw log + + contract *bind.BoundContract // Generic contract to use for unpacking event data + event string // Event name to use for unpacking event data + + logs chan types.Log // Log channel receiving the found contract events + sub ethereum.Subscription // Subscription for errors, completion and termination + done bool // Whether the subscription completed delivering logs + fail error // Occurred error to stop iteration +} + +// Next advances the iterator to the subsequent event, returning whether there +// are any more events found. In case of a retrieval or parsing error, false is +// returned and Error() can be queried for the exact failure. +func (it *ICAModuleSourceCallbackIterator) Next() bool { + // If the iterator failed, stop iterating + if it.fail != nil { + return false + } + // If the iterator completed, deliver directly whatever's available + if it.done { + select { + case log := <-it.logs: + it.Event = new(ICAModuleSourceCallback) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + default: + return false + } + } + // Iterator still in progress, wait for either a data or an error event + select { + case log := <-it.logs: + it.Event = new(ICAModuleSourceCallback) + if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { + it.fail = err + return false + } + it.Event.Raw = log + return true + + case err := <-it.sub.Err(): + it.done = true + it.fail = err + return it.Next() + } +} + +// Error returns any retrieval or parsing error occurred during filtering. +func (it *ICAModuleSourceCallbackIterator) Error() error { + return it.fail +} + +// Close terminates the iteration process, releasing any pending underlying +// resources. +func (it *ICAModuleSourceCallbackIterator) Close() error { + it.sub.Unsubscribe() + return nil +} + +// ICAModuleSourceCallback represents a SourceCallback event raised by the ICAModule contract. +type ICAModuleSourceCallback struct { + Module string + CallbackType string + CallbackAddress string + CallbackResult string + CallbackExecGasLimit string + CallbackCommitGasLimit string + PacketSrcPort string + PacketSrcChannel string + PacketSequence string + Raw types.Log // Blockchain specific contextual infos +} + +// FilterSourceCallback is a free log retrieval operation binding the contract event 0xb76e53cebd913fb7a3a645584b8ee6889866564177fc6a11ada9f86b66046ac3. +// +// Solidity: event SourceCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackExecGasLimit, string callbackCommitGasLimit, string packetSrcPort, string packetSrcChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) FilterSourceCallback(opts *bind.FilterOpts) (*ICAModuleSourceCallbackIterator, error) { + + logs, sub, err := _ICAModule.contract.FilterLogs(opts, "SourceCallback") + if err != nil { + return nil, err + } + return &ICAModuleSourceCallbackIterator{contract: _ICAModule.contract, event: "SourceCallback", logs: logs, sub: sub}, nil +} + +// WatchSourceCallback is a free log subscription operation binding the contract event 0xb76e53cebd913fb7a3a645584b8ee6889866564177fc6a11ada9f86b66046ac3. +// +// Solidity: event SourceCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackExecGasLimit, string callbackCommitGasLimit, string packetSrcPort, string packetSrcChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) WatchSourceCallback(opts *bind.WatchOpts, sink chan<- *ICAModuleSourceCallback) (event.Subscription, error) { + + logs, sub, err := _ICAModule.contract.WatchLogs(opts, "SourceCallback") + if err != nil { + return nil, err + } + return event.NewSubscription(func(quit <-chan struct{}) error { + defer sub.Unsubscribe() + for { + select { + case log := <-logs: + // New log arrived, parse the event and forward to the user + event := new(ICAModuleSourceCallback) + if err := _ICAModule.contract.UnpackLog(event, "SourceCallback", log); err != nil { + return err + } + event.Raw = log + + select { + case sink <- event: + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + case err := <-sub.Err(): + return err + case <-quit: + return nil + } + } + }), nil +} + +// ParseSourceCallback is a log parse operation binding the contract event 0xb76e53cebd913fb7a3a645584b8ee6889866564177fc6a11ada9f86b66046ac3. +// +// Solidity: event SourceCallback(string module, string callbackType, string callbackAddress, string callbackResult, string callbackExecGasLimit, string callbackCommitGasLimit, string packetSrcPort, string packetSrcChannel, string packetSequence) +func (_ICAModule *ICAModuleFilterer) ParseSourceCallback(log types.Log) (*ICAModuleSourceCallback, error) { + event := new(ICAModuleSourceCallback) + if err := _ICAModule.contract.UnpackLog(event, "SourceCallback", log); err != nil { + return nil, err + } + event.Raw = log + return event, nil +} + // ICAModuleSubmitMsgsResultIterator is returned from FilterSubmitMsgsResult and is used to iterate over the raw logs and unpacked data for SubmitMsgsResult events raised by the ICAModule contract. type ICAModuleSubmitMsgsResultIterator struct { Event *ICAModuleSubmitMsgsResult // Event containing the contract specifics and raw log diff --git a/x/cronos/events/bindings/src/ICA.sol b/x/cronos/events/bindings/src/ICA.sol index b57bddc503..e98d28a905 100644 --- a/x/cronos/events/bindings/src/ICA.sol +++ b/x/cronos/events/bindings/src/ICA.sol @@ -3,6 +3,29 @@ pragma solidity ^0.8.4; interface IICAModule { event SubmitMsgsResult(uint64 seq); + event DestinationCallback( + string module, + string callbackType, + string callbackAddress, + string callbackResult, + string callbackError, + string callbackExecGasLimit, + string callbackCommitGasLimit, + string packetDestPort, + string packetDestChannel, + string packetSequence + ); + event SourceCallback( + string module, + string callbackType, + string callbackAddress, + string callbackResult, + string callbackExecGasLimit, + string callbackCommitGasLimit, + string packetSrcPort, + string packetSrcChannel, + string packetSequence + ); function registerAccount(string calldata connectionID, string calldata version) external payable returns (bool); function queryAccount(string calldata connectionID, address addr) external view returns (string memory); function submitMsgs(string calldata connectionID, bytes calldata data, uint256 timeout) external payable returns (uint64); diff --git a/x/cronos/events/events.go b/x/cronos/events/events.go index d4b0a98be4..1d65a54a9c 100644 --- a/x/cronos/events/events.go +++ b/x/cronos/events/events.go @@ -3,6 +3,7 @@ package events import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + ibccallbackstypes "github.com/cosmos/ibc-go/modules/apps/callbacks/types" ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -35,7 +36,20 @@ var ( transfertypes.AttributeKeyDenom: ReturnStringAsIs, } IcaValueDecoders = ValueDecoders{ - cronoseventstypes.AttributeKeySeq: ConvertUint64, + cronoseventstypes.AttributeKeySeq: ConvertUint64, + ibccallbackstypes.AttributeKeyCallbackType: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackAddress: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackResult: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackError: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackGasLimit: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackCommitGasLimit: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackSourcePortID: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackSourceChannelID: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackDestPortID: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackDestChannelID: ReturnStringAsIs, + ibccallbackstypes.AttributeKeyCallbackSequence: ReturnStringAsIs, + ibccallbackstypes.AttributeValueCallbackSuccess: ReturnStringAsIs, + ibccallbackstypes.AttributeValueCallbackFailure: ReturnStringAsIs, } )