x/ibc: remove parts of amino (#6819)

* remove amino from channel types

* fix unmarshal error

* fix msgs_test

* update msgs test with underscore json encoding

* remove amino from connections

* purge amino from ibc-transfer

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
colin axnér 2020-08-03 14:08:41 +02:00 committed by GitHub
parent 6f3ca5c140
commit 00961f2082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 98 deletions

View File

@ -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.

View File

@ -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()
}

View File

@ -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

View File

@ -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))
}

View File

@ -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))
}

View File

@ -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()
}

View File

@ -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())

View File

@ -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

View File

@ -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))

View File

@ -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)