From 00b456e051e69aa9632c95d95067e7bd7478ce78 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:59:52 +0800 Subject: [PATCH] feat: add ibc call evm (#241) Co-authored-by: nulnut <151493716+nulnut@users.noreply.github.com> Co-authored-by: fx0x55 <80245546+fx0x55@users.noreply.github.com> --- app/encoding_test.go | 6 +- app/keepers/keepers.go | 1 + .../applications/transfer/v1/transfer.proto | 19 + .../applications/transfer/keeper/ibc_call.go | 43 ++ x/ibc/applications/transfer/keeper/keeper.go | 10 +- x/ibc/applications/transfer/keeper/relay.go | 8 + .../transfer/keeper/relay_test.go | 43 ++ x/ibc/applications/transfer/types/codec.go | 9 + x/ibc/applications/transfer/types/errors.go | 2 + x/ibc/applications/transfer/types/events.go | 3 + .../transfer/types/expected_keepers.go | 7 + x/ibc/applications/transfer/types/keys.go | 13 + x/ibc/applications/transfer/types/packet.go | 54 ++- .../transfer/types/transfer.pb.go | 379 +++++++++++++++++- 14 files changed, 572 insertions(+), 25 deletions(-) create mode 100644 x/ibc/applications/transfer/keeper/ibc_call.go diff --git a/app/encoding_test.go b/app/encoding_test.go index 29fce4dfd..129bd4859 100644 --- a/app/encoding_test.go +++ b/app/encoding_test.go @@ -20,21 +20,21 @@ func TestMakeEncodingConfig_RegisterInterfaces(t *testing.T) { for interfaceNames.Next() { count1++ } - assert.Equal(t, 32, count1) + assert.Equal(t, 33, count1) interfaceImpls := interfaceRegistry.Field(1).MapRange() var count2 int for interfaceImpls.Next() { count2++ } - assert.Equal(t, 32, count2) + assert.Equal(t, 33, count2) typeURLMap := interfaceRegistry.Field(2).MapRange() var count3 int for typeURLMap.Next() { count3++ } - assert.Equal(t, 264, count3) + assert.Equal(t, 265, count3) govContent := encodingConfig.InterfaceRegistry.ListImplementations("cosmos.gov.v1beta1.Content") assert.Equal(t, 14, len(govContent)) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 0cef85736..7e1bc1cbf 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -514,6 +514,7 @@ func NewAppKeeper( appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetRouter(*ibcTransferRouter) appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetRefundHook(appKeepers.Erc20Keeper) appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetErc20Keeper(appKeepers.Erc20Keeper) + appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetEvmKeeper(appKeepers.EvmKeeper) ibcTransferModule := ibctransfer.NewIBCModule(appKeepers.IBCTransferKeeper) transferIBCModule := fxtransfer.NewIBCMiddleware(appKeepers.FxTransferKeeper, ibcTransferModule) diff --git a/proto/fx/ibc/applications/transfer/v1/transfer.proto b/proto/fx/ibc/applications/transfer/v1/transfer.proto index 6a1bc7343..a269717c4 100644 --- a/proto/fx/ibc/applications/transfer/v1/transfer.proto +++ b/proto/fx/ibc/applications/transfer/v1/transfer.proto @@ -1,6 +1,8 @@ syntax = "proto3"; package fx.ibc.applications.transfer.v1; +import "gogoproto/gogo.proto"; + option go_package = "github.com/functionx/fx-core/x/ibc/applications/transfer/types"; // FungibleTokenPacketData defines a struct for the packet payload @@ -22,3 +24,20 @@ message FungibleTokenPacketData { // optional memo string memo = 7; } + +enum IbcCallType { + option (gogoproto.goproto_enum_prefix) = false; + + IBC_CALL_TYPE_UNSPECIFIED = 0; + IBC_CALL_TYPE_EVM = 1; +} + +message IbcCallEvmPacket { + string to = 1; + string value = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + uint64 gas_limit = 3; + string message = 4; +} diff --git a/x/ibc/applications/transfer/keeper/ibc_call.go b/x/ibc/applications/transfer/keeper/ibc_call.go new file mode 100644 index 000000000..8453d79cb --- /dev/null +++ b/x/ibc/applications/transfer/keeper/ibc_call.go @@ -0,0 +1,43 @@ +package keeper + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + evmtypes "github.com/evmos/ethermint/x/evm/types" + + "github.com/functionx/fx-core/v7/x/ibc/applications/transfer/types" +) + +func (k Keeper) HandlerIbcCall(ctx sdk.Context, sourcePort, sourceChannel string, data types.FungibleTokenPacketData) error { + var mp types.MemoPacket + if err := k.cdc.UnmarshalInterfaceJSON([]byte(data.Memo), &mp); err != nil { + return nil + } + + if err := mp.ValidateBasic(); err != nil { + return err + } + + attr := sdk.NewAttribute(types.AttributeKeyIBCCallType, types.IbcCallType_name[int32(mp.GetType())]) + ctx.EventManager().EmitEvents(sdk.Events{sdk.NewEvent(types.EventTypeIBCCall, attr)}) + switch packet := mp.(type) { + case *types.IbcCallEvmPacket: + hexSender := types.IntermediateSender(sourcePort, sourceChannel, data.Sender) + return k.HandlerIbcCallEvm(ctx, hexSender, packet) + default: + return types.ErrMemoNotSupport.Wrapf("invalid call type %s", mp.GetType()) + } +} + +func (k Keeper) HandlerIbcCallEvm(ctx sdk.Context, sender common.Address, evmData *types.IbcCallEvmPacket) error { + txResp, err := k.evmKeeper.CallEVM(ctx, sender, + evmData.MustGetToAddr(), evmData.Value.BigInt(), evmData.GasLimit, evmData.MustGetMessage(), true) + if err != nil { + return err + } + if txResp.Failed() { + return errorsmod.Wrap(evmtypes.ErrVMExecution, txResp.VmError) + } + return nil +} diff --git a/x/ibc/applications/transfer/keeper/keeper.go b/x/ibc/applications/transfer/keeper/keeper.go index 7a31eaae7..4b9bf2d4e 100644 --- a/x/ibc/applications/transfer/keeper/keeper.go +++ b/x/ibc/applications/transfer/keeper/keeper.go @@ -20,7 +20,7 @@ import ( type Keeper struct { ibctransferkeeper.Keeper storeKey storetypes.StoreKey - cdc codec.BinaryCodec + cdc codec.Codec paramSpace paramtypes.Subspace ics4Wrapper porttypes.ICS4Wrapper @@ -30,13 +30,14 @@ type Keeper struct { bankKeeper transfertypes.BankKeeper scopedKeeper capabilitykeeper.ScopedKeeper erc20Keeper types.Erc20Keeper + evmKeeper types.EvmKeeper router *fxtypes.Router refundHook types.RefundHook } // NewKeeper creates a new IBC transfer Keeper instance func NewKeeper(keeper ibctransferkeeper.Keeper, - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper transfertypes.ChannelKeeper, portKeeper transfertypes.PortKeeper, authKeeper transfertypes.AccountKeeper, bankKeeper transfertypes.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper, ) Keeper { @@ -80,6 +81,11 @@ func (k Keeper) SetErc20Keeper(erc20Keeper types.Erc20Keeper) Keeper { return k } +func (k Keeper) SetEvmKeeper(evmKeeper types.EvmKeeper) Keeper { + k.evmKeeper = evmKeeper + return k +} + // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.CompatibleModuleName) diff --git a/x/ibc/applications/transfer/keeper/relay.go b/x/ibc/applications/transfer/keeper/relay.go index 550f0281e..26ea08f62 100644 --- a/x/ibc/applications/transfer/keeper/relay.go +++ b/x/ibc/applications/transfer/keeper/relay.go @@ -174,8 +174,16 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t return err } } + // NOTE: if not router, emit onRecvPacketCtx event, only error is nil emit ctx.EventManager().EmitEvents(onRecvPacketCtxWithNewEvent.EventManager().Events()) + + // ibc call + if len(data.Memo) > 0 { + if err = k.HandlerIbcCall(ctx, packet.SourcePort, packet.SourceChannel, data); err != nil { + return err + } + } return nil } route, exists := k.router.GetRoute(data.Router) diff --git a/x/ibc/applications/transfer/keeper/relay_test.go b/x/ibc/applications/transfer/keeper/relay_test.go index f5c691f4d..fd333c43d 100644 --- a/x/ibc/applications/transfer/keeper/relay_test.go +++ b/x/ibc/applications/transfer/keeper/relay_test.go @@ -8,6 +8,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/ibc-go/v6/modules/apps/transfer" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" @@ -392,6 +393,48 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { checkCoinAddr: senderAddr, expCoins: sdk.NewCoins(sdk.NewCoin(ibcDenomTrace.IBCDenom(), sdkmath.ZeroInt())), }, + { + name: "pass - any memo", + malleate: func(packet *channeltypes.Packet) { + packetData := transfertypes.FungibleTokenPacketData{} + transfertypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &packetData) + packetData.Memo = "0000" + packet.Data = packetData.GetBytes() + }, + expPass: true, + errorStr: "", + checkBalance: true, + checkCoinAddr: senderAddr, + expCoins: sdk.NewCoins(sdk.NewCoin(ibcDenomTrace.IBCDenom(), sdkmath.ZeroInt())), + }, + { + name: "pass - ibc call evm", + malleate: func(packet *channeltypes.Packet) { + packetData := transfertypes.FungibleTokenPacketData{} + transfertypes.ModuleCdc.MustUnmarshalJSON(packet.GetData(), &packetData) + + hexIbcSender := fxtransfertypes.IntermediateSender(ibctesting.TransferPort, "channel-0", senderAddr.String()) + ibcCallBaseAcc := authtypes.NewBaseAccountWithAddress(hexIbcSender.Bytes()) + suite.NoError(ibcCallBaseAcc.SetSequence(0)) + suite.GetApp(suite.chainA.App).AccountKeeper.SetAccount(suite.chainA.GetContext(), ibcCallBaseAcc) + evmPacket := fxtransfertypes.IbcCallEvmPacket{ + To: common.BigToAddress(big.NewInt(0)).String(), + Value: sdkmath.ZeroInt(), + GasLimit: 300000, + Message: "", + } + cdc := suite.GetApp(suite.chainA.App).AppCodec() + bz, err := cdc.MarshalInterfaceJSON(&evmPacket) + suite.Require().NoError(err) + packetData.Memo = string(bz) + packet.Data = packetData.GetBytes() + }, + expPass: true, + errorStr: "", + checkBalance: true, + checkCoinAddr: senderAddr, + expCoins: sdk.NewCoins(sdk.NewCoin(ibcDenomTrace.IBCDenom(), sdkmath.ZeroInt())), + }, } for _, tc := range testCases { diff --git a/x/ibc/applications/transfer/types/codec.go b/x/ibc/applications/transfer/types/codec.go index 58b98f2e0..ef8c39c38 100644 --- a/x/ibc/applications/transfer/types/codec.go +++ b/x/ibc/applications/transfer/types/codec.go @@ -15,7 +15,10 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterInterface((*MemoPacket)(nil), nil) + cdc.RegisterConcrete(&MsgTransfer{}, fmt.Sprintf("%s/%s", CompatibleModuleName, "MsgTransfer"), nil) + cdc.RegisterConcrete(&IbcCallEvmPacket{}, fmt.Sprintf("%s/%s", CompatibleModuleName, "IbcCallEvmPacket"), nil) } // RegisterInterfaces register the ibc transfer module interfaces to protobuf @@ -23,6 +26,12 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgTransfer{}) + registry.RegisterInterface( + "fx.ibc.applications.transfer.v1.MemoPacket", + (*MemoPacket)(nil), + &IbcCallEvmPacket{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/ibc/applications/transfer/types/errors.go b/x/ibc/applications/transfer/types/errors.go index de179df5b..98fc6e475 100644 --- a/x/ibc/applications/transfer/types/errors.go +++ b/x/ibc/applications/transfer/types/errors.go @@ -7,4 +7,6 @@ import ( var ( ErrFeeDenomNotMatchTokenDenom = errorsmod.Register(ModuleName, 100, "invalid fee denom, must match token denom") ErrRouterNotFound = errorsmod.Register(ModuleName, 103, "router not found") + ErrMemoNotSupport = errorsmod.Register(ModuleName, 104, "memo not support") + ErrInvalidEvmData = errorsmod.Register(ModuleName, 105, "invalid evm data") ) diff --git a/x/ibc/applications/transfer/types/events.go b/x/ibc/applications/transfer/types/events.go index a869162db..21a3bc828 100644 --- a/x/ibc/applications/transfer/types/events.go +++ b/x/ibc/applications/transfer/types/events.go @@ -9,4 +9,7 @@ const ( AttributeKeyRouteSuccess = "success" AttributeKeyRoute = "route" AttributeKeyRouteError = "error" + + EventTypeIBCCall = "ibc_call" + AttributeKeyIBCCallType = "ibc_call_type" ) diff --git a/x/ibc/applications/transfer/types/expected_keepers.go b/x/ibc/applications/transfer/types/expected_keepers.go index 47644ecdd..9cfa5f32a 100644 --- a/x/ibc/applications/transfer/types/expected_keepers.go +++ b/x/ibc/applications/transfer/types/expected_keepers.go @@ -2,8 +2,11 @@ package types import ( "context" + "math/big" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + evmtypes "github.com/evmos/ethermint/x/evm/types" fxtypes "github.com/functionx/fx-core/v7/types" erc20types "github.com/functionx/fx-core/v7/x/erc20/types" @@ -18,3 +21,7 @@ type Erc20Keeper interface { ConvertDenomToTarget(ctx sdk.Context, from sdk.AccAddress, coin sdk.Coin, fxTarget fxtypes.FxTarget) (sdk.Coin, error) ConvertCoin(goCtx context.Context, msg *erc20types.MsgConvertCoin) (*erc20types.MsgConvertCoinResponse, error) } + +type EvmKeeper interface { + CallEVM(ctx sdk.Context, from common.Address, contract *common.Address, value *big.Int, gasLimit uint64, data []byte, commit bool) (*evmtypes.MsgEthereumTxResponse, error) +} diff --git a/x/ibc/applications/transfer/types/keys.go b/x/ibc/applications/transfer/types/keys.go index ac27cf3c7..d0346d2bc 100644 --- a/x/ibc/applications/transfer/types/keys.go +++ b/x/ibc/applications/transfer/types/keys.go @@ -1,5 +1,12 @@ package types +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/types/address" + "github.com/ethereum/go-ethereum/common" +) + const ( // ModuleName defines the IBC transfer name ModuleName = "transfer" @@ -10,3 +17,9 @@ const ( // RouterKey is the message route for IBC transfer RouterKey = CompatibleModuleName ) + +func IntermediateSender(sourcePort, sourceChannel, sender string) common.Address { + prefix := fmt.Sprintf("%s/%s", sourcePort, sourceChannel) + senderHash32 := address.Hash(prefix, []byte(sender)) + return common.BytesToAddress(senderHash32) +} diff --git a/x/ibc/applications/transfer/types/packet.go b/x/ibc/applications/transfer/types/packet.go index 58304a008..54b35c5d3 100644 --- a/x/ibc/applications/transfer/types/packet.go +++ b/x/ibc/applications/transfer/types/packet.go @@ -1,6 +1,7 @@ package types import ( + "encoding/hex" "strings" "time" @@ -9,8 +10,20 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + "github.com/ethereum/go-ethereum/common" + "github.com/gogo/protobuf/proto" + + fxtypes "github.com/functionx/fx-core/v7/types" ) +type MemoPacket interface { + proto.Message + GetType() IbcCallType + ValidateBasic() error +} + +var _ MemoPacket = &IbcCallEvmPacket{} + // DefaultRelativePacketTimeoutTimestamp is the default packet timeout timestamp (in nanoseconds) // relative to the current block timestamp of the counterparty chain provided by the client // state. The timeout is disabled when set to 0. The default is currently set to a 12-hour @@ -54,7 +67,10 @@ func (ftpd FungibleTokenPacketData) ValidateBasic() error { if fee.IsNegative() { return errorsmod.Wrapf(transfertypes.ErrInvalidAmount, "fee must be strictly not negative: got %d", fee) } - return transfertypes.ValidatePrefixedDenom(ftpd.Denom) + if err := transfertypes.ValidatePrefixedDenom(ftpd.Denom); err != nil { + return err + } + return nil } // GetBytes is a helper for serialising @@ -71,3 +87,39 @@ func (ftpd FungibleTokenPacketData) ToIBCPacketData() transfertypes.FungibleToke result.Memo = ftpd.Memo return result } + +func (icep IbcCallEvmPacket) GetType() IbcCallType { + return IBC_CALL_TYPE_EVM +} + +func (icep IbcCallEvmPacket) ValidateBasic() error { + if err := fxtypes.ValidateEthereumAddress(icep.To); err != nil { + return ErrInvalidEvmData.Wrap("to") + } + if icep.Value.IsNegative() { + return ErrInvalidEvmData.Wrap("value") + } + + // gas limit + + if _, err := hex.DecodeString(icep.Message); err != nil { + return ErrInvalidEvmData.Wrap("message") + } + return nil +} + +func (icep IbcCallEvmPacket) MustGetToAddr() *common.Address { + if err := fxtypes.ValidateEthereumAddress(icep.To); err != nil { + panic(err) + } + to := common.HexToAddress(icep.To) + return &to +} + +func (icep IbcCallEvmPacket) MustGetMessage() []byte { + bz, err := hex.DecodeString(icep.Message) + if err != nil { + panic(err) + } + return bz +} diff --git a/x/ibc/applications/transfer/types/transfer.pb.go b/x/ibc/applications/transfer/types/transfer.pb.go index e556a3e10..df8228f96 100644 --- a/x/ibc/applications/transfer/types/transfer.pb.go +++ b/x/ibc/applications/transfer/types/transfer.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -22,6 +24,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +type IbcCallType int32 + +const ( + IBC_CALL_TYPE_UNSPECIFIED IbcCallType = 0 + IBC_CALL_TYPE_EVM IbcCallType = 1 +) + +var IbcCallType_name = map[int32]string{ + 0: "IBC_CALL_TYPE_UNSPECIFIED", + 1: "IBC_CALL_TYPE_EVM", +} + +var IbcCallType_value = map[string]int32{ + "IBC_CALL_TYPE_UNSPECIFIED": 0, + "IBC_CALL_TYPE_EVM": 1, +} + +func (x IbcCallType) String() string { + return proto.EnumName(IbcCallType_name, int32(x)) +} + +func (IbcCallType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_60fb0411450507d8, []int{0} +} + // FungibleTokenPacketData defines a struct for the packet payload // See FungibleTokenPacketData spec: // https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#data-structures @@ -124,8 +151,71 @@ func (m *FungibleTokenPacketData) GetMemo() string { return "" } +type IbcCallEvmPacket struct { + To string `protobuf:"bytes,1,opt,name=to,proto3" json:"to,omitempty"` + Value github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=value,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"value"` + GasLimit uint64 `protobuf:"varint,3,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"` + Message string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"` +} + +func (m *IbcCallEvmPacket) Reset() { *m = IbcCallEvmPacket{} } +func (m *IbcCallEvmPacket) String() string { return proto.CompactTextString(m) } +func (*IbcCallEvmPacket) ProtoMessage() {} +func (*IbcCallEvmPacket) Descriptor() ([]byte, []int) { + return fileDescriptor_60fb0411450507d8, []int{1} +} +func (m *IbcCallEvmPacket) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IbcCallEvmPacket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IbcCallEvmPacket.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IbcCallEvmPacket) XXX_Merge(src proto.Message) { + xxx_messageInfo_IbcCallEvmPacket.Merge(m, src) +} +func (m *IbcCallEvmPacket) XXX_Size() int { + return m.Size() +} +func (m *IbcCallEvmPacket) XXX_DiscardUnknown() { + xxx_messageInfo_IbcCallEvmPacket.DiscardUnknown(m) +} + +var xxx_messageInfo_IbcCallEvmPacket proto.InternalMessageInfo + +func (m *IbcCallEvmPacket) GetTo() string { + if m != nil { + return m.To + } + return "" +} + +func (m *IbcCallEvmPacket) GetGasLimit() uint64 { + if m != nil { + return m.GasLimit + } + return 0 +} + +func (m *IbcCallEvmPacket) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + func init() { + proto.RegisterEnum("fx.ibc.applications.transfer.v1.IbcCallType", IbcCallType_name, IbcCallType_value) proto.RegisterType((*FungibleTokenPacketData)(nil), "fx.ibc.applications.transfer.v1.FungibleTokenPacketData") + proto.RegisterType((*IbcCallEvmPacket)(nil), "fx.ibc.applications.transfer.v1.IbcCallEvmPacket") } func init() { @@ -133,25 +223,35 @@ func init() { } var fileDescriptor_60fb0411450507d8 = []byte{ - // 273 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x90, 0xb1, 0x4e, 0xeb, 0x30, - 0x18, 0x85, 0xe3, 0xdb, 0x36, 0x17, 0x3c, 0x21, 0x0b, 0x81, 0xc5, 0x60, 0x10, 0x13, 0x0b, 0xb6, - 0x2a, 0x76, 0x06, 0x84, 0x98, 0x11, 0x62, 0x40, 0x6c, 0x8e, 0xfb, 0xbb, 0x58, 0x6d, 0xec, 0xc8, - 0x71, 0xa2, 0xf0, 0x16, 0xbc, 0x0e, 0x6f, 0xc0, 0xd8, 0x91, 0x11, 0x25, 0x2f, 0x82, 0x62, 0xa3, - 0x88, 0x89, 0xed, 0x7c, 0x9f, 0xff, 0x33, 0xf8, 0x60, 0xae, 0x3b, 0x61, 0x0a, 0x25, 0x64, 0x55, - 0x6d, 0x8d, 0x92, 0xc1, 0x38, 0x5b, 0x8b, 0xe0, 0xa5, 0xad, 0x35, 0x78, 0xd1, 0x2e, 0xa7, 0xcc, - 0x2b, 0xef, 0x82, 0x23, 0xa7, 0xba, 0xe3, 0xa6, 0x50, 0xfc, 0xf7, 0x3d, 0x9f, 0x6e, 0xda, 0xe5, - 0xf9, 0x3b, 0xc2, 0xc7, 0x77, 0x8d, 0x5d, 0x9b, 0x62, 0x0b, 0x8f, 0x6e, 0x03, 0xf6, 0x5e, 0xaa, - 0x0d, 0x84, 0x5b, 0x19, 0x24, 0x39, 0xc4, 0x8b, 0x15, 0x58, 0x57, 0x52, 0x74, 0x86, 0x2e, 0xf6, - 0x1f, 0x12, 0x90, 0x23, 0x9c, 0xcb, 0xd2, 0x35, 0x36, 0xd0, 0x7f, 0x51, 0xff, 0xd0, 0xe8, 0x6b, - 0xb0, 0x2b, 0xf0, 0x74, 0x96, 0x7c, 0x22, 0x72, 0x82, 0xf7, 0x3c, 0x28, 0x30, 0x2d, 0x78, 0x3a, - 0x8f, 0x2f, 0x13, 0x8f, 0x1d, 0xef, 0x9a, 0x00, 0x9e, 0x2e, 0x52, 0x27, 0x11, 0x39, 0xc0, 0x33, - 0x0d, 0x40, 0xf3, 0x28, 0xc7, 0x48, 0x08, 0x9e, 0x97, 0x50, 0x3a, 0xfa, 0x3f, 0xaa, 0x98, 0x6f, - 0x9e, 0x3e, 0x7a, 0x86, 0x76, 0x3d, 0x43, 0x5f, 0x3d, 0x43, 0x6f, 0x03, 0xcb, 0x76, 0x03, 0xcb, - 0x3e, 0x07, 0x96, 0x3d, 0x5f, 0xaf, 0x4d, 0x78, 0x69, 0x0a, 0xae, 0x5c, 0x29, 0x74, 0x63, 0xd5, - 0xf8, 0xef, 0x4e, 0xe8, 0xee, 0x52, 0x39, 0x0f, 0xe2, 0xaf, 0x09, 0xc3, 0x6b, 0x05, 0x75, 0x91, - 0xc7, 0xf5, 0xae, 0xbe, 0x03, 0x00, 0x00, 0xff, 0xff, 0x05, 0x60, 0x94, 0xc7, 0x6f, 0x01, 0x00, - 0x00, + // 446 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0x41, 0x8b, 0xd3, 0x40, + 0x18, 0x4d, 0xba, 0x6d, 0x77, 0x77, 0x04, 0xa9, 0xc3, 0xaa, 0xb1, 0x62, 0x2a, 0x7b, 0x10, 0x11, + 0x36, 0x61, 0xf1, 0x2e, 0xd8, 0x36, 0x0b, 0x81, 0x2a, 0xa5, 0x56, 0x51, 0x2f, 0x65, 0x32, 0xfd, + 0x12, 0x43, 0x93, 0x99, 0x30, 0x33, 0x09, 0xdd, 0x7f, 0xe0, 0xd1, 0x7f, 0xe0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0, 0x6f, 0xbb, 0x22, 0x5d, 0x33, 0xea, 0xea, 0x4b, 0x78, + 0xf9, 0x37, 0x00, 0x00, 0xff, 0xff, 0x25, 0x1e, 0xa7, 0x8d, 0x72, 0x02, 0x00, 0x00, } func (m *FungibleTokenPacketData) Marshal() (dAtA []byte, err error) { @@ -226,6 +326,58 @@ func (m *FungibleTokenPacketData) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *IbcCallEvmPacket) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IbcCallEvmPacket) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IbcCallEvmPacket) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Message) > 0 { + i -= len(m.Message) + copy(dAtA[i:], m.Message) + i = encodeVarintTransfer(dAtA, i, uint64(len(m.Message))) + i-- + dAtA[i] = 0x22 + } + if m.GasLimit != 0 { + i = encodeVarintTransfer(dAtA, i, uint64(m.GasLimit)) + i-- + dAtA[i] = 0x18 + } + { + size := m.Value.Size() + i -= size + if _, err := m.Value.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTransfer(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.To) > 0 { + i -= len(m.To) + copy(dAtA[i:], m.To) + i = encodeVarintTransfer(dAtA, i, uint64(len(m.To))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintTransfer(dAtA []byte, offset int, v uint64) int { offset -= sovTransfer(v) base := offset @@ -274,6 +426,28 @@ func (m *FungibleTokenPacketData) Size() (n int) { return n } +func (m *IbcCallEvmPacket) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.To) + if l > 0 { + n += 1 + l + sovTransfer(uint64(l)) + } + l = m.Value.Size() + n += 1 + l + sovTransfer(uint64(l)) + if m.GasLimit != 0 { + n += 1 + sovTransfer(uint64(m.GasLimit)) + } + l = len(m.Message) + if l > 0 { + n += 1 + l + sovTransfer(uint64(l)) + } + return n +} + func sovTransfer(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -554,6 +728,173 @@ func (m *FungibleTokenPacketData) Unmarshal(dAtA []byte) error { } return nil } +func (m *IbcCallEvmPacket) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: IbcCallEvmPacket: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IbcCallEvmPacket: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field To", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTransfer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTransfer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.To = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTransfer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTransfer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Value.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasLimit", wireType) + } + m.GasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTransfer + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTransfer + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTransfer + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTransfer(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTransfer + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTransfer(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0