diff --git a/app/app.go b/app/app.go index 47a6eb8048..4ce672b8e8 100644 --- a/app/app.go +++ b/app/app.go @@ -549,11 +549,7 @@ func New( []vm.PrecompiledContract{ cronosprecompiles.NewBankContract(app.BankKeeper, appCodec), cronosprecompiles.NewRelayerContract(app.IBCKeeper, appCodec), - cronosprecompiles.NewIcaContract( - appCodec, - &app.IBCKeeper.ChannelKeeper, - &app.ICAControllerKeeper, - ), + cronosprecompiles.NewIcaContract(&app.ICAAuthKeeper, appCodec), }, allKeys, ) diff --git a/go.mod b/go.mod index 7a0f68d8bd..48d051684a 100644 --- a/go.mod +++ b/go.mod @@ -231,7 +231,6 @@ replace ( github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.37.2-0.20230905115601-790d57e1748f github.com/cometbft/cometbft-db => github.com/crypto-org-chain/cometbft-db v0.0.0-20230412133340-ac70df4b45f6 github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.46.0-beta2.0.20230905040840-b3af5590283b - github.com/cosmos/ibc-go/v7 => github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623 github.com/crypto-org-chain/cronos/memiavl => ./memiavl github.com/crypto-org-chain/cronos/store => ./store github.com/crypto-org-chain/cronos/versiondb => ./versiondb diff --git a/go.sum b/go.sum index c5876275c6..42e4ce6f0c 100644 --- a/go.sum +++ b/go.sum @@ -467,6 +467,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek= github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583 h1:3Matt7/LjZiZkIBPalYazOZcw2B05Ch14dU5TJyqJEc= github.com/cosmos/iavl v0.21.0-alpha.1.0.20230904092046-df3db2d96583/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A= +github.com/cosmos/ibc-go/v7 v7.2.0 h1:dx0DLUl7rxdyZ8NiT6UsrbzKOJx/w7s+BOaewFRH6cg= +github.com/cosmos/ibc-go/v7 v7.2.0/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= @@ -1192,8 +1194,6 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623 h1:JjCrbTMp2OKUx6AXSNNLgIERDpgfdfbJk1aElv1NtaA= -github.com/mmsqe/ibc-go/v7 v7.0.0-20230912011206-c6947c7bc623/go.mod h1:OOcjKIRku/j1Xs1RgKK0yvKRrJ5iFuZYMetR1n3yMlc= github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU= github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= diff --git a/gomod2nix.toml b/gomod2nix.toml index 35b3f0fdb4..0e1480f7a5 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -160,9 +160,8 @@ schema = 3 version = "v0.21.0-alpha.1.0.20230904092046-df3db2d96583" hash = "sha256-3Va8Ljq63IXty0oHlRpqfsC6WsMut6TWZ2R+/nYtfTU=" [mod."github.com/cosmos/ibc-go/v7"] - version = "v7.0.0-20230912011206-c6947c7bc623" - hash = "sha256-zaoFkKhNBOQmIU8wKMCeq9Y+4GtAMHx8wZ6Q1JFEdkc=" - replaced = "github.com/mmsqe/ibc-go/v7" + version = "v7.2.0" + hash = "sha256-fg+0AykvEMzqRGI5CmqwjQtSIwTyT6RuSDpp12wzReM=" [mod."github.com/cosmos/ics23/go"] version = "v0.10.0" hash = "sha256-KYEv727BO/ht63JO02xiKFGFAddg41Ve9l2vSSZZBq0=" diff --git a/integration_tests/contracts/contracts/TestICA.sol b/integration_tests/contracts/contracts/TestICA.sol index 1fc31cc5d4..c0cc8e492a 100644 --- a/integration_tests/contracts/contracts/TestICA.sol +++ b/integration_tests/contracts/contracts/TestICA.sol @@ -3,6 +3,7 @@ pragma solidity ^0.6.6; contract TestICA { address constant icaContract = 0x0000000000000000000000000000000000000066; + event SubmitMsgsResult(string seq); function nativeRegister(string memory connectionID) public { (bool result,) = icaContract.call(abi.encodeWithSignature( diff --git a/integration_tests/ibc_utils.py b/integration_tests/ibc_utils.py index 83db123f0a..78e203344b 100644 --- a/integration_tests/ibc_utils.py +++ b/integration_tests/ibc_utils.py @@ -600,16 +600,3 @@ def funds_ica(cli, adr): # check if the funds are received in interchain account assert cli.balance(adr, denom="basecro") == 100000000 - - -def generate_ica_packet(cli, ica_address, to): - # generate a transaction to send to host chain - generated_tx_msg = { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": ica_address, - "to_address": to, - "amount": [{"denom": "basecro", "amount": "50000000"}], - } - str = json.dumps(generated_tx_msg) - generated_packet = cli.ica_generate_packet_data(str) - return json.dumps(generated_packet) diff --git a/integration_tests/test_ica_precompile.py b/integration_tests/test_ica_precompile.py index 4c6efe0b1e..8a426c95a2 100644 --- a/integration_tests/test_ica_precompile.py +++ b/integration_tests/test_ica_precompile.py @@ -6,14 +6,12 @@ from .ibc_utils import ( funds_ica, - generate_ica_packet, prepare_network, wait_for_check_channel_ready, wait_for_check_tx, ) from .utils import ( ADDRS, - CONTRACT_ABIS, CONTRACTS, KEYS, deploy_contract, @@ -24,10 +22,6 @@ send_transaction, ) -CONTRACT = "0x0000000000000000000000000000000000000066" -contract_info = json.loads(CONTRACT_ABIS["IICAModule"].read_text()) -method_map = get_method_map(contract_info) - @pytest.fixture(scope="module") def ibc(request, tmp_path_factory): @@ -38,6 +32,19 @@ def ibc(request, tmp_path_factory): yield from network +def generate_ica_packet(cli, ica_address, to): + # generate a transaction to send to host chain + generated_tx_msg = { + "@type": "/cosmos.bank.v1beta1.MsgSend", + "from_address": ica_address, + "to_address": to, + "amount": [{"denom": "basecro", "amount": "50000000"}], + } + str = json.dumps(generated_tx_msg) + generated_packet = cli.ica_generate_packet_data(str) + return json.dumps(generated_packet) + + def test_call(ibc): connid = "connection-0" cli_host = ibc.chainmain.cosmos_cli() @@ -47,23 +54,18 @@ def test_call(ibc): addr = ADDRS["signer2"] keys = KEYS["signer2"] jsonfile = CONTRACTS["TestICA"] + contract_info = json.loads(jsonfile.read_text()) + method_map = get_method_map(contract_info["abi"]) + contract = deploy_contract(w3, jsonfile, (), keys) data = {"from": addr, "gas": 200000} print("register ica account from", contract.address) - start = w3.eth.get_block_number() tx = contract.functions.nativeRegister(connid).build_transaction(data) receipt = send_transaction(w3, tx, keys) assert receipt.status == 1 - logs = get_logs_since(w3, CONTRACT, start) owner = eth_to_bech32(addr) channel_id = "channel-0" - port_id = f"icacontroller-{owner}" - expected = [{"channelId": channel_id, "portId": port_id}] - for i, log in enumerate(logs): - method_name, args = get_topic_data(w3, method_map, contract_info, log) - assert args == AttributeDict(expected[i]), [i, method_name] - wait_for_check_channel_ready(cli_controller, connid, channel_id) res = cli_controller.ica_query_account(connid, owner) ica_address = res["interchain_account_address"] @@ -80,7 +82,9 @@ def test_call(ibc): tx = contract.functions.nativeSubmitMsgs(connid, str).build_transaction(data) receipt = send_transaction(w3, tx, keys) assert receipt.status == 1 - logs = get_logs_since(w3, CONTRACT, start) + + precompile_addr = "0x0000000000000000000000000000000000000066" + logs = get_logs_since(w3, precompile_addr, start) expected = [{"seq": "1"}] for i, log in enumerate(logs): method_name, args = get_topic_data(w3, method_map, contract_info, log) diff --git a/integration_tests/utils.py b/integration_tests/utils.py index 9fd9a481b2..15f7f1b683 100644 --- a/integration_tests/utils.py +++ b/integration_tests/utils.py @@ -84,7 +84,6 @@ def contract_path(name, filename): CONTRACT_ABIS = { "IRelayerModule": Path(__file__).parent.parent / "build/IRelayerModule.abi", - "IICAModule": Path(__file__).parent.parent / "build/IICAModule.abi", } diff --git a/proto/icaauth/v1/tx.proto b/proto/icaauth/v1/tx.proto index 2512714436..ec5e5a6d56 100644 --- a/proto/icaauth/v1/tx.proto +++ b/proto/icaauth/v1/tx.proto @@ -54,4 +54,4 @@ message MsgSubmitTx { } // MsgSubmitTxResponse defines the response message for MsgSubmitTx -message MsgSubmitTxResponse {} \ No newline at end of file +message MsgSubmitTxResponse { uint64 sequence = 1; } \ No newline at end of file diff --git a/scripts/gen-bindings-contracts b/scripts/gen-bindings-contracts index a7b40edab3..13803bbff2 100755 --- a/scripts/gen-bindings-contracts +++ b/scripts/gen-bindings-contracts @@ -2,9 +2,7 @@ solc08 --abi --bin x/cronos/events/bindings/src/CosmosTypes.sol -o build --overwrite solc08 --abi --bin x/cronos/events/bindings/src/Relayer.sol -o build --overwrite -solc06 --abi --bin x/cronos/events/bindings/src/ICA.sol -o build --overwrite abigen --pkg lib --abi build/CosmosTypes.abi --bin build/CosmosTypes.bin --out x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go --type CosmosTypes abigen --pkg relayer --abi build/IRelayerModule.abi --bin build/IRelayerModule.bin --out x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go --type RelayerModule -abigen --pkg ica --abi build/IICAModule.abi --bin build/IICAModule.bin --out x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go --type ICAModule diff --git a/scripts/run-integration-tests b/scripts/run-integration-tests index 34e0b05e1f..1609dd454b 100755 --- a/scripts/run-integration-tests +++ b/scripts/run-integration-tests @@ -10,4 +10,4 @@ cd ../integration_tests/contracts HUSKY_SKIP_INSTALL=1 npm install npm run typechain cd .. -nix-shell --run "pytest -v -s test_ica_precompile.py" +nix-shell --run "pytest -vv -s" diff --git a/x/cronos/events/bindings/src/ICA.sol b/x/cronos/events/bindings/src/ICA.sol deleted file mode 100644 index 9968afd181..0000000000 --- a/x/cronos/events/bindings/src/ICA.sol +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.6.6; - -interface IICAModule { - event RegisterAccountResult(string channelId, string portId); - event SubmitMsgsResult(string seq); -} diff --git a/x/cronos/events/types/types.go b/x/cronos/events/types/types.go index b764b9ec01..66ace42d19 100644 --- a/x/cronos/events/types/types.go +++ b/x/cronos/events/types/types.go @@ -1,7 +1,6 @@ package types const ( - EventTypeRegisterAccountResult = "register_account_result" - EventTypeSubmitMsgsResult = "submit_msgs_result" - AttributeKeySeq = "seq" + EventTypeSubmitMsgsResult = "submit_msgs_result" + AttributeKeySeq = "seq" ) diff --git a/x/cronos/keeper/precompiles/ica.go b/x/cronos/keeper/precompiles/ica.go index 060d13b69e..ccd3dfbb56 100644 --- a/x/cronos/keeper/precompiles/ica.go +++ b/x/cronos/keeper/precompiles/ica.go @@ -5,16 +5,15 @@ import ( "errors" "fmt" "math/big" + "time" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - ibcchannelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" cronosevents "github.com/crypto-org-chain/cronos/v2/x/cronos/events" cronoseventstypes "github.com/crypto-org-chain/cronos/v2/x/cronos/events/types" + icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper" + "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" @@ -86,20 +85,17 @@ func init() { } type IcaContract struct { - cdc codec.Codec - channelKeeper *ibcchannelkeeper.Keeper - icaControllerKeeper *icacontrollerkeeper.Keeper + BaseContract + + cdc codec.Codec + icaauthKeeper *icaauthkeeper.Keeper } -func NewIcaContract( - cdc codec.Codec, - channelKeeper *ibcchannelkeeper.Keeper, - icaControllerKeeper *icacontrollerkeeper.Keeper, -) vm.PrecompiledContract { +func NewIcaContract(icaauthKeeper *icaauthkeeper.Keeper, cdc codec.Codec) vm.PrecompiledContract { return &IcaContract{ - cdc, - channelKeeper, - icaControllerKeeper, + BaseContract: NewBaseContract(IcaContractAddress), + cdc: cdc, + icaauthKeeper: icaauthKeeper, } } @@ -122,7 +118,7 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([ stateDB := evm.StateDB.(ExtStateDB) precompileAddr := ic.Address() converter := cronosevents.IcaConvertEvent - var err error + var execErr error var res codec.ProtoMarshaler switch string(methodID) { case string(RegisterAccountMethod.ID): @@ -141,22 +137,13 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([ return nil, errors.New("unauthorized account registration") } owner := sdk.AccAddress(account.Bytes()).String() - err = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error { - response, err := ic.icaControllerKeeper.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{ + execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error { + response, err := ic.icaauthKeeper.RegisterAccount(ctx, &types.MsgRegisterAccount{ Owner: owner, ConnectionId: connectionID, Version: version, }) res = response - if err == nil && response != nil { - ctx.EventManager().EmitEvents(sdk.Events{ - sdk.NewEvent( - cronoseventstypes.EventTypeRegisterAccountResult, - sdk.NewAttribute(channeltypes.AttributeKeyChannelID, response.ChannelId), - sdk.NewAttribute(channeltypes.AttributeKeyPortID, response.PortId), - ), - }) - } return err }) case string(QueryAccountMethod.ID): @@ -166,11 +153,13 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([ } connectionID := args[0].(string) account := args[1].(common.Address) - err = stateDB.ExecuteNativeAction(precompileAddr, nil, func(ctx sdk.Context) error { - res, err = ic.icaControllerKeeper.InterchainAccount(ctx, &icacontrollertypes.QueryInterchainAccountRequest{ - Owner: sdk.AccAddress(account.Bytes()).String(), + owner := sdk.AccAddress(account.Bytes()).String() + execErr = stateDB.ExecuteNativeAction(precompileAddr, nil, func(ctx sdk.Context) error { + response, err := ic.icaauthKeeper.InterchainAccountAddress(ctx, &types.QueryInterchainAccountAddressRequest{ + Owner: owner, ConnectionId: connectionID, }) + res = response return err }) case string(SubmitMsgsMethod.ID): @@ -192,16 +181,18 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([ var icaMsgData icatypes.InterchainAccountPacketData err = ic.cdc.UnmarshalJSON([]byte(data), &icaMsgData) if err != nil { - panic(err) + return nil, errors.New("fail to unmarshal packet data") } owner := sdk.AccAddress(account.Bytes()).String() - err = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error { - response, err := ic.icaControllerKeeper.SendTx(ctx, &icacontrollertypes.MsgSendTx{ //nolint:staticcheck - Owner: owner, - ConnectionId: connectionID, - PacketData: icaMsgData, - RelativeTimeout: timeout.Uint64(), - }) + timeoutDuration := time.Duration(timeout.Uint64()) + execErr = stateDB.ExecuteNativeAction(precompileAddr, converter, func(ctx sdk.Context) error { + response, err := ic.icaauthKeeper.SubmitTxWithArgs( + ctx, + owner, + connectionID, + timeoutDuration, + icaMsgData, + ) res = response if err == nil && response != nil { ctx.EventManager().EmitEvents(sdk.Events{ @@ -216,8 +207,8 @@ func (ic *IcaContract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) ([ default: return nil, errors.New("unknown method") } - if err != nil { - return nil, err + if execErr != nil { + return nil, execErr } return ic.cdc.Marshal(res) } diff --git a/x/icaauth/keeper/grpc_query_interchain_account_address.go b/x/icaauth/keeper/grpc_query_interchain_account_address.go deleted file mode 100644 index a7e502cccd..0000000000 --- a/x/icaauth/keeper/grpc_query_interchain_account_address.go +++ /dev/null @@ -1,27 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -func (k Keeper) InterchainAccountAddress(goCtx context.Context, req *types.QueryInterchainAccountAddressRequest) (*types.QueryInterchainAccountAddressResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "invalid request") - } - - ctx := sdk.UnwrapSDKContext(goCtx) - - icaAddress, err := k.GetInterchainAccountAddress(ctx, req.ConnectionId, req.Owner) - if err != nil { - return nil, err - } - - return &types.QueryInterchainAccountAddressResponse{ - InterchainAccountAddress: icaAddress, - }, nil -} diff --git a/x/icaauth/keeper/keeper.go b/x/icaauth/keeper/keeper.go index 5054929e63..5137efd79e 100644 --- a/x/icaauth/keeper/keeper.go +++ b/x/icaauth/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "time" @@ -10,9 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cosmos/gogoproto/proto" icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" - icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" "google.golang.org/grpc/codes" @@ -47,57 +46,72 @@ func NewKeeper( } } -// DoSubmitTx submits a transaction to the host chain on behalf of interchain account -func (k *Keeper) DoSubmitTx(ctx sdk.Context, connectionID, owner string, msgs []proto.Message, timeoutDuration time.Duration) error { +// SubmitTx submits a transaction to the host chain on behalf of interchain account +func (k *Keeper) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { + msgs, err := msg.GetMessages() + if err != nil { + return nil, err + } + data, err := icatypes.SerializeCosmosTx(k.cdc, msgs) if err != nil { - return err + return nil, err } packetData := icatypes.InterchainAccountPacketData{ Type: icatypes.EXECUTE_TX, Data: data, } + return k.SubmitTxWithArgs(goCtx, msg.Owner, msg.ConnectionId, *msg.TimeoutDuration, packetData) +} +func (k *Keeper) SubmitTxWithArgs(goCtx context.Context, owner, connectionId string, timeoutDuration time.Duration, packetData icatypes.InterchainAccountPacketData) (*types.MsgSubmitTxResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + portID, err := icatypes.NewControllerPortID(owner) + if err != nil { + return nil, err + } + minTimeoutDuration := k.MinTimeoutDuration(ctx) // timeoutDuration should be constraited by MinTimeoutDuration parameter. - timeoutTimestamp := ctx.BlockTime().Add(timeoutDuration).UnixNano() - _, err = k.icaControllerKeeper.SendTx(ctx, &icacontrollertypes.MsgSendTx{ //nolint:staticcheck - Owner: owner, - ConnectionId: connectionID, - PacketData: packetData, - RelativeTimeout: uint64(timeoutTimestamp), - }) + timeoutTimestamp := ctx.BlockTime().Add( + types.MsgSubmitTx{ + TimeoutDuration: &timeoutDuration, + }.CalculateTimeoutDuration(minTimeoutDuration)).UnixNano() + res, err := k.icaControllerKeeper.SendTx(ctx, nil, connectionId, portID, packetData, uint64(timeoutTimestamp)) //nolint:staticcheck if err != nil { - return err + return nil, err } - - return nil + return &types.MsgSubmitTxResponse{ + Sequence: res, + }, nil } -// RegisterInterchainAccount registers an interchain account with the given `connectionId` and `owner` on the host chain -func (k *Keeper) RegisterInterchainAccount(ctx sdk.Context, connectionID, owner, version string) error { - _, err := k.icaControllerKeeper.RegisterInterchainAccount(ctx, &icacontrollertypes.MsgRegisterInterchainAccount{ - Owner: owner, - ConnectionId: connectionID, - Version: version, - }) - return err +// RegisterAccount registers an interchain account with the given `connectionId` and `owner` on the host chain +func (k *Keeper) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAccount) (*types.MsgRegisterAccountResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.icaControllerKeeper.RegisterInterchainAccount(ctx, msg.ConnectionId, msg.Owner, msg.Version); err != nil { + return nil, err + } + return &types.MsgRegisterAccountResponse{}, nil } -// GetInterchainAccountAddress fetches the interchain account address for given `connectionId` and `owner` -func (k *Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, owner string) (string, error) { - portID, err := icatypes.NewControllerPortID(owner) +// InterchainAccountAddress fetches the interchain account address for given `connectionId` and `owner` +func (k Keeper) InterchainAccountAddress(goCtx context.Context, req *types.QueryInterchainAccountAddressRequest) (*types.QueryInterchainAccountAddressResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + portID, err := icatypes.NewControllerPortID(req.Owner) if err != nil { - return "", status.Errorf(codes.InvalidArgument, "invalid owner address: %s", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid owner address: %s", err) } - icaAddress, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, connectionID, portID) + icaAddress, found := k.icaControllerKeeper.GetInterchainAccountAddress(ctx, req.ConnectionId, portID) if !found { - return "", status.Errorf(codes.NotFound, "could not find account") + return nil, status.Errorf(codes.NotFound, "could not find account") } - return icaAddress, nil + return &types.QueryInterchainAccountAddressResponse{ + InterchainAccountAddress: icaAddress, + }, nil } // ClaimCapability claims the channel capability passed via the OnOpenChanInit callback diff --git a/x/icaauth/keeper/msg_server.go b/x/icaauth/keeper/msg_server.go index d01fce99a6..781d36dc18 100644 --- a/x/icaauth/keeper/msg_server.go +++ b/x/icaauth/keeper/msg_server.go @@ -14,4 +14,4 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { return &msgServer{Keeper: keeper} } -var _ types.MsgServer = msgServer{} +var _ types.MsgServer = new(msgServer) diff --git a/x/icaauth/keeper/msg_server_register_account.go b/x/icaauth/keeper/msg_server_register_account.go deleted file mode 100644 index 45b1939d75..0000000000 --- a/x/icaauth/keeper/msg_server_register_account.go +++ /dev/null @@ -1,18 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" -) - -func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAccount) (*types.MsgRegisterAccountResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - if err := k.RegisterInterchainAccount(ctx, msg.ConnectionId, msg.Owner, msg.Version); err != nil { - return nil, err - } - - return &types.MsgRegisterAccountResponse{}, nil -} diff --git a/x/icaauth/keeper/msg_server_submit_tx.go b/x/icaauth/keeper/msg_server_submit_tx.go deleted file mode 100644 index b0ceba4e6e..0000000000 --- a/x/icaauth/keeper/msg_server_submit_tx.go +++ /dev/null @@ -1,26 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/crypto-org-chain/cronos/v2/x/icaauth/types" -) - -func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - msgs, err := msg.GetMessages() - if err != nil { - return nil, err - } - - minTimeoutDuration := k.MinTimeoutDuration(ctx) - - err = k.DoSubmitTx(ctx, msg.ConnectionId, msg.Owner, msgs, msg.CalculateTimeoutDuration(minTimeoutDuration)) - if err != nil { - return nil, err - } - - return &types.MsgSubmitTxResponse{}, nil -} diff --git a/x/icaauth/types/tx.pb.go b/x/icaauth/types/tx.pb.go index 228e12ffad..24070483b3 100644 --- a/x/icaauth/types/tx.pb.go +++ b/x/icaauth/types/tx.pb.go @@ -212,6 +212,7 @@ func (m *MsgSubmitTx) GetTimeoutDuration() *time.Duration { // MsgSubmitTxResponse defines the response message for MsgSubmitTx type MsgSubmitTxResponse struct { + Sequence uint64 `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"` } func (m *MsgSubmitTxResponse) Reset() { *m = MsgSubmitTxResponse{} } @@ -247,6 +248,13 @@ func (m *MsgSubmitTxResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSubmitTxResponse proto.InternalMessageInfo +func (m *MsgSubmitTxResponse) GetSequence() uint64 { + if m != nil { + return m.Sequence + } + return 0 +} + func init() { proto.RegisterType((*MsgRegisterAccount)(nil), "icaauth.v1.MsgRegisterAccount") proto.RegisterType((*MsgRegisterAccountResponse)(nil), "icaauth.v1.MsgRegisterAccountResponse") @@ -257,36 +265,36 @@ func init() { func init() { proto.RegisterFile("icaauth/v1/tx.proto", fileDescriptor_09bf995a0c8f8b8c) } var fileDescriptor_09bf995a0c8f8b8c = []byte{ - // 449 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x41, 0x8e, 0xd3, 0x30, - 0x14, 0x86, 0x6b, 0x5a, 0x18, 0x70, 0x41, 0x83, 0x32, 0x45, 0xa4, 0x11, 0x4a, 0xab, 0x2c, 0x50, - 0x37, 0xb5, 0x35, 0x45, 0xb3, 0x41, 0x62, 0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0x3a, 0x9f, 0x5b, 0xe8, 0x83, 0x16, 0x7d, 0x36, 0x4b, 0xa4, 0xa2, - 0x4c, 0x83, 0x02, 0x43, 0x17, 0x03, 0xba, 0xa4, 0xee, 0x6a, 0xd8, 0x7c, 0xce, 0xcd, 0xe4, 0x5a, - 0x11, 0xdd, 0x83, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xdd, 0x5f, 0x85, 0x32, 0x03, 0x00, - 0x00, + // 463 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x3f, 0x8e, 0xd3, 0x40, + 0x14, 0xc6, 0x33, 0x24, 0xb0, 0xcb, 0x04, 0xb4, 0xc8, 0x1b, 0x09, 0xc7, 0x42, 0x4e, 0xe4, 0x02, + 0xa5, 0xc9, 0x8c, 0x12, 0xb4, 0x0d, 0x12, 0xc5, 0x46, 0xdb, 0x80, 0x14, 0x21, 0x19, 0x1a, 0x68, + 0x22, 0x67, 0x32, 0x4c, 0x46, 0xac, 0xe7, 0x05, 0xcf, 0x38, 0xc4, 0x35, 0x17, 0xa0, 0xe4, 0x04, + 0x9c, 0x80, 0x43, 0x20, 0xaa, 0x2d, 0xa9, 0x00, 0x25, 0xe2, 0x02, 0x9c, 0x00, 0xf9, 0xcf, 0x64, + 0x21, 0x11, 0x74, 0xdb, 0xf9, 0x7b, 0xbf, 0x37, 0x9f, 0xdf, 0xfb, 0xec, 0xc1, 0xc7, 0x92, 0x45, + 0x51, 0x6a, 0xe6, 0x74, 0x39, 0xa0, 0x66, 0x45, 0x16, 0x09, 0x18, 0x70, 0x70, 0x55, 0x24, 0xcb, + 0x81, 0xd7, 0x66, 0xa0, 0x63, 0xd0, 0x93, 0x82, 0xd0, 0x52, 0x94, 0x6d, 0x5e, 0x4b, 0x80, 0x80, + 0xb2, 0x9e, 0x3f, 0x55, 0x55, 0x5f, 0x00, 0x88, 0x73, 0x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 0x50, 0x78, + 0x54, 0x1d, 0xb4, 0xe5, 0x60, 0x80, 0x8f, 0xff, 0x58, 0xd3, 0xae, 0xef, 0x78, 0xf8, 0x50, 0xf3, + 0x37, 0x29, 0x57, 0x8c, 0x17, 0x1b, 0x37, 0xc2, 0xad, 0x1e, 0x7e, 0x44, 0xb8, 0x3e, 0xd6, 0xc2, + 0x79, 0x81, 0x8f, 0x76, 0x3f, 0xa1, 0x4f, 0x2e, 0x7f, 0x29, 0xb2, 0x9f, 0xae, 0x77, 0xff, 0xff, + 0x7c, 0xfb, 0xfa, 0x33, 0x7c, 0xb8, 0x4d, 0xfe, 0xee, 0xce, 0x19, 0x0b, 0xbc, 0xce, 0x3f, 0x80, + 0x75, 0x19, 0x3d, 0xfd, 0xbc, 0xf6, 0xd1, 0xc5, 0xda, 0x47, 0x3f, 0xd6, 0x3e, 0x7a, 0xbf, 0xf1, + 0x6b, 0x17, 0x1b, 0xbf, 0xf6, 0x75, 0xe3, 0xd7, 0x5e, 0x9e, 0x08, 0x69, 0xe6, 0xe9, 0x94, 0x30, + 0x88, 0x29, 0x4b, 0xb2, 0x85, 0x81, 0x3e, 0x24, 0xa2, 0xcf, 0xe6, 0x91, 0x54, 0x94, 0x25, 0xa0, + 0x40, 0xd3, 0xe5, 0x90, 0xae, 0xa8, 0xbd, 0x36, 0x26, 0x5b, 0x70, 0x3d, 0xbd, 0x51, 0xc4, 0xfa, + 0xe0, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf3, 0xfc, 0xdd, 0xdc, 0x4e, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -561,6 +569,11 @@ func (m *MsgSubmitTxResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Sequence != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Sequence)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -638,6 +651,9 @@ func (m *MsgSubmitTxResponse) Size() (n int) { } var l int _ = l + if m.Sequence != 0 { + n += 1 + sovTx(uint64(m.Sequence)) + } return n } @@ -1056,6 +1072,25 @@ func (m *MsgSubmitTxResponse) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: MsgSubmitTxResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) + } + m.Sequence = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Sequence |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:])