diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index 632783c9e..ddeee27c5 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -45,9 +45,7 @@ func (AppModuleBasic) Name() string { } // RegisterCodec implements AppModuleBasic interface -func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { - types.RegisterCodec(cdc) -} +func (AppModuleBasic) RegisterCodec(*codec.Codec) {} // DefaultGenesis returns default genesis state as raw bytes for the ibc // transfer module. diff --git a/x/ibc-transfer/types/codec.go b/x/ibc-transfer/types/codec.go index 66db072e6..84f3664de 100644 --- a/x/ibc-transfer/types/codec.go +++ b/x/ibc-transfer/types/codec.go @@ -4,16 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types" - commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types" ) -// RegisterCodec registers the IBC transfer types -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterConcrete(&MsgTransfer{}, "cosmos-sdk/MsgTransfer", nil) - cdc.RegisterConcrete(FungibleTokenPacketData{}, "cosmos-sdk/PacketDataTransfer", nil) -} - // RegisterInterfaces register the ibc transfer module interfaces to protobuf // Any. func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -21,20 +13,10 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - amino = codec.New() - // ModuleCdc references the global x/ibc-transfer module codec. Note, the codec - // should ONLY be used in certain instances of tests and for JSON encoding as Amino - // is still used for that purpose. + // should ONLY be used in certain instances of tests and for JSON encoding. // // The actual codec used for serialization should be provided to x/ibc-transfer and // defined at the application level. - ModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry()) + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) ) - -func init() { - RegisterCodec(amino) - channeltypes.RegisterCodec(amino) - commitmenttypes.RegisterCodec(amino) - amino.Seal() -} diff --git a/x/ibc-transfer/types/msgs.go b/x/ibc-transfer/types/msgs.go index dc6473d86..d12714c6d 100644 --- a/x/ibc-transfer/types/msgs.go +++ b/x/ibc-transfer/types/msgs.go @@ -69,7 +69,7 @@ func (msg MsgTransfer) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgTransfer) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg diff --git a/x/ibc-transfer/types/msgs_test.go b/x/ibc-transfer/types/msgs_test.go index 954c3f6ef..8a089b830 100644 --- a/x/ibc-transfer/types/msgs_test.go +++ b/x/ibc-transfer/types/msgs_test.go @@ -82,7 +82,7 @@ func TestMsgTransferGetSignBytes(t *testing.T) { msg := NewMsgTransfer(validPort, validChannel, coin, addr1, addr2, 110, 10) res := msg.GetSignBytes() - expected := `{"type":"cosmos-sdk/MsgTransfer","value":{"receiver":"cosmos1w3jhxarpv3j8yvs7f9y7g","sender":"cosmos1w3jhxarpv3j8yvg4ufs4x","source_channel":"testchannel","source_port":"testportid","timeout_height":"110","timeout_timestamp":"10","token":{"amount":"100","denom":"atom"}}}` + expected := `{"receiver":"cosmos1w3jhxarpv3j8yvs7f9y7g","sender":"cosmos1w3jhxarpv3j8yvg4ufs4x","source_channel":"testchannel","source_port":"testportid","timeout_height":"110","timeout_timestamp":"10","token":{"amount":"100","denom":"atom"}}` require.Equal(t, expected, string(res)) } diff --git a/x/ibc-transfer/types/packet.go b/x/ibc-transfer/types/packet.go index da40286e9..4f5bd8ff7 100644 --- a/x/ibc-transfer/types/packet.go +++ b/x/ibc-transfer/types/packet.go @@ -53,10 +53,10 @@ func (ftpd FungibleTokenPacketData) ValidateBasic() error { // GetBytes is a helper for serialising func (ftpd FungibleTokenPacketData) GetBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(ftpd)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&ftpd)) } // GetBytes is a helper for serialising func (ack FungibleTokenPacketAcknowledgement) GetBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(ack)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&ack)) } diff --git a/x/ibc/03-connection/types/codec.go b/x/ibc/03-connection/types/codec.go index f5ebbbe6b..466235fb1 100644 --- a/x/ibc/03-connection/types/codec.go +++ b/x/ibc/03-connection/types/codec.go @@ -4,22 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/exported" ) -// RegisterCodec registers the necessary x/ibc/03-connection interfaces and concrete types -// on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.ConnectionI)(nil), nil) - cdc.RegisterInterface((*exported.CounterpartyI)(nil), nil) - - cdc.RegisterConcrete(ConnectionEnd{}, "ibc/connection/ConnectionEnd", nil) - cdc.RegisterConcrete(&MsgConnectionOpenInit{}, "ibc/connection/MsgConnectionOpenInit", nil) - cdc.RegisterConcrete(&MsgConnectionOpenTry{}, "ibc/connection/MsgConnectionOpenTry", nil) - cdc.RegisterConcrete(&MsgConnectionOpenAck{}, "ibc/connection/MsgConnectionOpenAck", nil) - cdc.RegisterConcrete(&MsgConnectionOpenConfirm{}, "ibc/connection/MsgConnectionOpenConfirm", nil) -} - // RegisterInterfaces register the ibc interfaces submodule implementations to protobuf // Any. func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -33,18 +19,10 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { } var ( - amino = codec.New() - // SubModuleCdc references the global x/ibc/03-connectionl module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. + // ONLY be used in certain instances of tests and for JSON encoding. // // The actual codec used for serialization should be provided to x/ibc/03-connectionl and // defined at the application level. - SubModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry()) + SubModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) ) - -func init() { - RegisterCodec(amino) - amino.Seal() -} diff --git a/x/ibc/04-channel/types/codec.go b/x/ibc/04-channel/types/codec.go index be751513d..6ff4c4812 100644 --- a/x/ibc/04-channel/types/codec.go +++ b/x/ibc/04-channel/types/codec.go @@ -4,27 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported" ) -// RegisterCodec registers the necessary x/ibc/04-channel interfaces and concrete types -// on the provided Amino codec. These types are used for Amino JSON serialization. -func RegisterCodec(cdc *codec.Codec) { - cdc.RegisterInterface((*exported.PacketI)(nil), nil) - cdc.RegisterConcrete(Channel{}, "ibc/channel/Channel", nil) - cdc.RegisterConcrete(Packet{}, "ibc/channel/Packet", nil) - - cdc.RegisterConcrete(&MsgChannelOpenInit{}, "ibc/channel/MsgChannelOpenInit", nil) - cdc.RegisterConcrete(&MsgChannelOpenTry{}, "ibc/channel/MsgChannelOpenTry", nil) - cdc.RegisterConcrete(&MsgChannelOpenAck{}, "ibc/channel/MsgChannelOpenAck", nil) - cdc.RegisterConcrete(&MsgChannelOpenConfirm{}, "ibc/channel/MsgChannelOpenConfirm", nil) - cdc.RegisterConcrete(&MsgChannelCloseInit{}, "ibc/channel/MsgChannelCloseInit", nil) - cdc.RegisterConcrete(&MsgChannelCloseConfirm{}, "ibc/channel/MsgChannelCloseConfirm", nil) - cdc.RegisterConcrete(&MsgRecvPacket{}, "ibc/channel/MsgRecvPacket", nil) - cdc.RegisterConcrete(&MsgAcknowledgement{}, "ibc/channel/MsgAcknowledgement", nil) - cdc.RegisterConcrete(&MsgTimeout{}, "ibc/channel/MsgTimeout", nil) -} - // RegisterInterfaces register the ibc channel submodule interfaces to protobuf // Any. func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -42,19 +23,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { ) } -var ( - amino = codec.New() - - // SubModuleCdc references the global x/ibc/04-channel module codec. Note, the codec should - // ONLY be used in certain instances of tests and for JSON encoding as Amino is - // still used for that purpose. - // - // The actual codec used for serialization should be provided to x/ibc/04-channel and - // defined at the application level. - SubModuleCdc = codec.NewHybridCodec(amino, cdctypes.NewInterfaceRegistry()) -) - -func init() { - RegisterCodec(amino) - amino.Seal() -} +// SubModuleCdc references the global x/ibc/04-channel module codec. Note, the codec should +// ONLY be used in certain instances of tests and for JSON encoding. +// +// The actual codec used for serialization should be provided to x/ibc/04-channel and +// defined at the application level. +var SubModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) diff --git a/x/ibc/04-channel/types/msgs.go b/x/ibc/04-channel/types/msgs.go index 8ef0be7ac..cf4356fd1 100644 --- a/x/ibc/04-channel/types/msgs.go +++ b/x/ibc/04-channel/types/msgs.go @@ -50,7 +50,7 @@ func (msg MsgChannelOpenInit) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelOpenInit) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -109,7 +109,7 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelOpenTry) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -164,7 +164,7 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelOpenAck) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -218,7 +218,7 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelOpenConfirm) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -263,7 +263,7 @@ func (msg MsgChannelCloseInit) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelCloseInit) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -317,7 +317,7 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgChannelCloseConfirm) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -362,7 +362,7 @@ func (msg MsgRecvPacket) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgRecvPacket) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetDataSignBytes returns the base64-encoded bytes used for the @@ -420,7 +420,7 @@ func (msg MsgTimeout) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgTimeout) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg @@ -469,7 +469,7 @@ func (msg MsgAcknowledgement) ValidateBasic() error { // GetSignBytes implements sdk.Msg func (msg MsgAcknowledgement) GetSignBytes() []byte { - return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg)) } // GetSigners implements sdk.Msg diff --git a/x/ibc/04-channel/types/msgs_test.go b/x/ibc/04-channel/types/msgs_test.go index a99c2ed26..bcd0aba61 100644 --- a/x/ibc/04-channel/types/msgs_test.go +++ b/x/ibc/04-channel/types/msgs_test.go @@ -414,7 +414,7 @@ func (suite *MsgTestSuite) TestMsgRecvPacketGetSignBytes() { res := msg.GetSignBytes() expected := fmt.Sprintf( - `{"type":"ibc/channel/MsgRecvPacket","value":{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100","timeout_timestamp":"100"},"proof":"Co0BCi4KCmljczIzOmlhdmwSA0tFWRobChkKA0tFWRIFVkFMVUUaCwgBGAEgASoDAAICClsKDGljczIzOnNpbXBsZRIMaWF2bFN0b3JlS2V5Gj0KOwoMaWF2bFN0b3JlS2V5EiAcIiDXSHQRSvh/Wa07MYpTK0B4XtbaXtzxBED76xk0WhoJCAEYASABKgEA","proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}}`, + `{"packet":{"data":%s,"destination_channel":"testcpchannel","destination_port":"testcpport","sequence":"1","source_channel":"testchannel","source_port":"testportid","timeout_height":"100","timeout_timestamp":"100"},"proof":"Co0BCi4KCmljczIzOmlhdmwSA0tFWRobChkKA0tFWRIFVkFMVUUaCwgBGAEgASoDAAICClsKDGljczIzOnNpbXBsZRIMaWF2bFN0b3JlS2V5Gj0KOwoMaWF2bFN0b3JlS2V5EiAcIiDXSHQRSvh/Wa07MYpTK0B4XtbaXtzxBED76xk0WhoJCAEYASABKgEA","proof_height":"1","signer":"cosmos1w3jhxarpv3j8yvg4ufs4x"}`, string(msg.GetDataSignBytes()), ) suite.Equal(expected, string(res)) diff --git a/x/ibc/types/codec.go b/x/ibc/types/codec.go index 82719b60f..b6537fa8d 100644 --- a/x/ibc/types/codec.go +++ b/x/ibc/types/codec.go @@ -15,8 +15,6 @@ import ( // on the provided Amino codec. These types are used for Amino JSON serialization. func RegisterCodec(cdc *codec.Codec) { clienttypes.RegisterCodec(cdc) - connectiontypes.RegisterCodec(cdc) - channeltypes.RegisterCodec(cdc) ibctmtypes.RegisterCodec(cdc) localhosttypes.RegisterCodec(cdc) commitmenttypes.RegisterCodec(cdc)