From 0fc8f7149e64dcb5c9706bc68b5cf9ea0a04d1a7 Mon Sep 17 00:00:00 2001 From: vuong177 Date: Wed, 21 Jun 2023 05:11:28 +0700 Subject: [PATCH] amino codec for msg push wasm --- modules/light-clients/08-wasm/module.go | 4 ++- modules/light-clients/08-wasm/types/codec.go | 32 +++++++++++++++++++- modules/light-clients/08-wasm/types/msgs.go | 8 +++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/modules/light-clients/08-wasm/module.go b/modules/light-clients/08-wasm/module.go index 56b56b2d719..5f8c9745060 100644 --- a/modules/light-clients/08-wasm/module.go +++ b/modules/light-clients/08-wasm/module.go @@ -35,7 +35,9 @@ func (AppModuleBasic) Name() string { } // RegisterLegacyAminoCodec performs a no-op. The Wasm client does not support amino. -func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers module concrete types into protobuf Any. This allows core IBC // to unmarshal Wasm light client types. diff --git a/modules/light-clients/08-wasm/types/codec.go b/modules/light-clients/08-wasm/types/codec.go index 2e6deddc8e8..a95b38763f3 100644 --- a/modules/light-clients/08-wasm/types/codec.go +++ b/modules/light-clients/08-wasm/types/codec.go @@ -1,12 +1,25 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" "github.com/cosmos/ibc-go/v7/modules/core/exported" + + sdk "github.com/cosmos/cosmos-sdk/types" ) +// RegisterLegacyAminoCodec registers the account interfaces and concrete types on the +// provided LegacyAmino codec. These types are used for Amino JSON serialization +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgPushNewWasmCode{}, "ibc/MsgPushNewWasmCode") +} + // RegisterInterfaces registers the tendermint concrete client-related // implementations and interfaces. func RegisterInterfaces(registry codectypes.InterfaceRegistry) { @@ -33,3 +46,20 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances + RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) +} diff --git a/modules/light-clients/08-wasm/types/msgs.go b/modules/light-clients/08-wasm/types/msgs.go index cd9fd59a2f2..ff0b7a4e200 100644 --- a/modules/light-clients/08-wasm/types/msgs.go +++ b/modules/light-clients/08-wasm/types/msgs.go @@ -5,11 +5,19 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +var TypeMsgPushNewWasmCode = "push_wasm_code" var _ sdk.Msg = &MsgPushNewWasmCode{} // NewMsgPushNewWasmCode creates a new MsgPushNewWasmCode instance // //nolint:interfacer + +// Route Implements Msg. +func (msg MsgPushNewWasmCode) Route() string { return ModuleName } + +// Type Implements Msg. +func (msg MsgPushNewWasmCode) Type() string { return TypeMsgPushNewWasmCode } + func NewMsgPushNewWasmCode(signer string, code []byte) *MsgPushNewWasmCode { return &MsgPushNewWasmCode{ Signer: signer,