Skip to content

Commit

Permalink
chore: remove deprecated amino codec and signbytes method
Browse files Browse the repository at this point in the history
  • Loading branch information
dadamu committed Sep 28, 2023
1 parent 15d5dfe commit 763c8fd
Show file tree
Hide file tree
Showing 35 changed files with 13 additions and 818 deletions.
20 changes: 0 additions & 20 deletions x/posts/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)
Expand Down Expand Up @@ -58,22 +57,3 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
amino = codec.NewLegacyAmino()

// AminoCodec references the global x/posts 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/posts and
// defined at the application level.
AminoCodec = codec.NewAminoCodec(amino)
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)

}
45 changes: 2 additions & 43 deletions x/posts/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ func (msg *MsgCreatePost) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgCreatePost) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgCreatePost) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Author)
Expand Down Expand Up @@ -192,11 +187,6 @@ func (msg *MsgEditPost) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgEditPost) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgEditPost) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Editor)
Expand Down Expand Up @@ -253,11 +243,6 @@ func (msg *MsgAddPostAttachment) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgAddPostAttachment) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgAddPostAttachment) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Editor)
Expand Down Expand Up @@ -310,11 +295,6 @@ func (msg *MsgRemovePostAttachment) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgRemovePostAttachment) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgRemovePostAttachment) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Editor)
Expand Down Expand Up @@ -356,11 +336,6 @@ func (msg *MsgDeletePost) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgDeletePost) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgDeletePost) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Signer)
Expand Down Expand Up @@ -427,11 +402,6 @@ func (msg *MsgAnswerPoll) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgAnswerPoll) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgAnswerPoll) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -441,8 +411,7 @@ func (msg *MsgAnswerPoll) GetSigners() []sdk.AccAddress {
// --------------------------------------------------------------------------------------------------------------------

var (
_ sdk.Msg = &MsgMovePost{}
_ legacytx.LegacyMsg = &MsgMovePost{}
_ sdk.Msg = &MsgMovePost{}
)

// NewMsgMovePost returns a new MsgMovePost instance
Expand Down Expand Up @@ -494,11 +463,6 @@ func (msg *MsgMovePost) ValidateBasic() error {
return nil
}

// GetSignBytes implements sdk.Msg
func (msg *MsgMovePost) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// GetSigners implements sdk.Msg
func (msg *MsgMovePost) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Owner)
Expand All @@ -509,7 +473,7 @@ func (msg *MsgMovePost) GetSigners() []sdk.AccAddress {

var (
_ sdk.Msg = &MsgUpdateParams{}
_ legacytx.LegacyMsg = &MsgUpdateParams{}
_ &MsgUpdateParams{}
)

func NewMsgUpdateParams(params Params, authority string) *MsgUpdateParams {
Expand Down Expand Up @@ -544,8 +508,3 @@ func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
authority := sdk.MustAccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{authority}
}

// GetSigners implements legacytx.LegacyMsg
func (msg *MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}
33 changes: 4 additions & 29 deletions x/posts/types/msgs_owner_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
)

var (
_ sdk.Msg = &MsgRequestPostOwnerTransfer{}
_ legacytx.LegacyMsg = &MsgRequestPostOwnerTransfer{}
_ sdk.Msg = &MsgRequestPostOwnerTransfer{}
)

// MsgRequestPostOwnerTransfer returns a new MsgRequestPostOwnerTransfer instance
Expand Down Expand Up @@ -65,16 +63,10 @@ func (msg *MsgRequestPostOwnerTransfer) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sender}
}

// GetSigners implements legacytx.LegacyMsg
func (msg *MsgRequestPostOwnerTransfer) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// --------------------------------------------------------------------------------------------------------------------

var (
_ sdk.Msg = &MsgCancelPostOwnerTransferRequest{}
_ legacytx.LegacyMsg = &MsgCancelPostOwnerTransferRequest{}
_ sdk.Msg = &MsgCancelPostOwnerTransferRequest{}
)

// MsgCancelPostOwnerTransferRequest returns a new MsgCancelPostOwnerTransferRequest instance
Expand Down Expand Up @@ -120,16 +112,10 @@ func (msg *MsgCancelPostOwnerTransferRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{sender}
}

// GetSigners implements legacytx.LegacyMsg
func (msg *MsgCancelPostOwnerTransferRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// --------------------------------------------------------------------------------------------------------------------

var (
_ sdk.Msg = &MsgAcceptPostOwnerTransferRequest{}
_ legacytx.LegacyMsg = &MsgAcceptPostOwnerTransferRequest{}
_ sdk.Msg = &MsgAcceptPostOwnerTransferRequest{}
)

// MsgAcceptPostOwnerTransferRequest returns a new MsgAcceptPostOwnerTransferRequest instance
Expand Down Expand Up @@ -175,16 +161,10 @@ func (msg *MsgAcceptPostOwnerTransferRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{receiver}
}

// GetSigners implements legacytx.LegacyMsg
func (msg *MsgAcceptPostOwnerTransferRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}

// --------------------------------------------------------------------------------------------------------------------

var (
_ sdk.Msg = &MsgRefusePostOwnerTransferRequest{}
_ legacytx.LegacyMsg = &MsgRefusePostOwnerTransferRequest{}
_ sdk.Msg = &MsgRefusePostOwnerTransferRequest{}
)

// MsgRefusePostOwnerTransferRequest returns a new MsgRefusePostOwnerTransferRequest instance
Expand Down Expand Up @@ -229,8 +209,3 @@ func (msg *MsgRefusePostOwnerTransferRequest) GetSigners() []sdk.AccAddress {
receiver := sdk.MustAccAddressFromBech32(msg.Receiver)
return []sdk.AccAddress{receiver}
}

// GetSigners implements legacytx.LegacyMsg
func (msg *MsgRefusePostOwnerTransferRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCodec.MustMarshalJSON(msg))
}
20 changes: 0 additions & 20 deletions x/posts/types/msgs_owner_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ func TestMsgRequestPostOwnerTransfer_ValidateBasic(t *testing.T) {
}
}

func TestMsgRequestPostOwnerTransfer_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgRequestPostOwnerTransfer","value":{"post_id":"1","receiver":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","sender":"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg","subspace_id":"1"}}`
require.Equal(t, expected, string(msgRequestPostOwnerTransfer.GetSignBytes()))
}

func TestMsgRequestPostOwnerTransfer_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgRequestPostOwnerTransfer.Sender)
require.Equal(t, []sdk.AccAddress{addr}, msgRequestPostOwnerTransfer.GetSigners())
Expand Down Expand Up @@ -177,11 +172,6 @@ func TestMsgCancelPostOwnerTransferRequest_ValidateBasic(t *testing.T) {
}
}

func TestMsgCancelPostOwnerTransferRequest_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgCancelPostOwnerTransfer","value":{"post_id":"1","sender":"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg","subspace_id":"1"}}`
require.Equal(t, expected, string(msgCancelPostOwnerTransferRequest.GetSignBytes()))
}

func TestMsgCancelPostOwnerTransferRequest_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgCancelPostOwnerTransferRequest.Sender)
require.Equal(t, []sdk.AccAddress{addr}, msgCancelPostOwnerTransferRequest.GetSigners())
Expand Down Expand Up @@ -255,11 +245,6 @@ func TestMsgAcceptPostOwnerTransferRequest_ValidateBasic(t *testing.T) {
}
}

func TestMsgAcceptPostOwnerTransferRequest_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgAcceptPostOwnerTransfer","value":{"post_id":"1","receiver":"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg","subspace_id":"1"}}`
require.Equal(t, expected, string(msgAcceptPostOwnerTransferRequest.GetSignBytes()))
}

func TestMsgAcceptPostOwnerTransferRequest_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgAcceptPostOwnerTransferRequest.Receiver)
require.Equal(t, []sdk.AccAddress{addr}, msgAcceptPostOwnerTransferRequest.GetSigners())
Expand Down Expand Up @@ -333,11 +318,6 @@ func TestMsgRefusePostOwnerTransferRequest_ValidateBasic(t *testing.T) {
}
}

func TestMsgRefusePostOwnerTransferRequest_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgRefusePostOwnerTransfer","value":{"post_id":"1","receiver":"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg","subspace_id":"1"}}`
require.Equal(t, expected, string(msgRefusePostOwnerTransferRequest.GetSignBytes()))
}

func TestMsgRefusePostOwnerTransferRequest_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgRefusePostOwnerTransferRequest.Receiver)
require.Equal(t, []sdk.AccAddress{addr}, msgRefusePostOwnerTransferRequest.GetSigners())
Expand Down
40 changes: 0 additions & 40 deletions x/posts/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,6 @@ func TestMsgCreatePost_ValidateBasic(t *testing.T) {
}
}

func TestMsgCreatePost_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgCreatePost","value":{"attachments":[{"type":"desmos/Media","value":{"mime_type":"image/png","uri":"ftp://user:[email protected]/image.png"}},{"type":"desmos/Poll","value":{"end_date":"2020-01-01T12:00:00Z","provided_answers":[{"attachments":[{"type":"desmos/Media","value":{"mime_type":"image/png","uri":"ftp://user:[email protected]/cat.png"}}],"text":"Cat"},{"text":"Dog"}],"question":"What animal is best?"}}],"author":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","conversation_id":"1","entities":{"hashtags":[{"end":"3","start":"1","tag":"tag"}],"mentions":[{"end":"6","start":"4","tag":"tag"}],"urls":[{"display_url":"Display URL","end":"9","start":"7","url":"URL"}]},"external_id":"External ID","referenced_posts":[{"post_id":"1","type":2}],"reply_settings":1,"section_id":1,"subspace_id":"1","tags":["general"],"text":"This is a text"}}`
require.Equal(t, expected, string(msgCreatePost.GetSignBytes()))
}

func TestMsgCreatePost_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgCreatePost.Author)
require.Equal(t, []sdk.AccAddress{addr}, msgCreatePost.GetSigners())
Expand Down Expand Up @@ -345,11 +340,6 @@ func TestMsgEditPost_ValidateBasic(t *testing.T) {
}
}

func TestMsgEditPost_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgEditPost","value":{"editor":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","entities":{"hashtags":[{"end":"3","start":"1","tag":"tag"}],"mentions":[{"end":"6","start":"4","tag":"tag"}],"urls":[{"display_url":"Display URL","end":"9","start":"7","url":"URL"}]},"post_id":"1","subspace_id":"1","tags":["general"],"text":"Edited text"}}`
require.Equal(t, expected, string(msgEditPost.GetSignBytes()))
}

func TestMsgEditPost_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgEditPost.Editor)
require.Equal(t, []sdk.AccAddress{addr}, msgEditPost.GetSigners())
Expand Down Expand Up @@ -442,11 +432,6 @@ func TestMsgAddPostAttachment_ValidateBasic(t *testing.T) {
}
}

func TestMsgAddPostAttachment_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgAddPostAttachment","value":{"content":{"type":"desmos/Media","value":{"mime_type":"image/png","uri":"ftp://user:[email protected]/image.png"}},"editor":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","post_id":"1","subspace_id":"1"}}`
require.Equal(t, expected, string(msgAddPostAttachment.GetSignBytes()))
}

func TestMsgAddPostAttachment_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgAddPostAttachment.Editor)
require.Equal(t, []sdk.AccAddress{addr}, msgAddPostAttachment.GetSigners())
Expand Down Expand Up @@ -534,11 +519,6 @@ func TestMsgRemovePostAttachment_ValidateBasic(t *testing.T) {
}
}

func TestMsgRemovePostAttachment_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgRemovePostAttachment","value":{"attachment_id":1,"editor":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","post_id":"1","subspace_id":"1"}}`
require.Equal(t, expected, string(msgRemovePostAttachment.GetSignBytes()))
}

func TestMsgRemovePostAttachment_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgRemovePostAttachment.Editor)
require.Equal(t, []sdk.AccAddress{addr}, msgRemovePostAttachment.GetSigners())
Expand Down Expand Up @@ -612,11 +592,6 @@ func TestMsgDeletePost_ValidateBasic(t *testing.T) {
}
}

func TestMsgDeletePost_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgDeletePost","value":{"post_id":"1","signer":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","subspace_id":"1"}}`
require.Equal(t, expected, string(msgDeletePost.GetSignBytes()))
}

func TestMsgDeletePost_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgDeletePost.Signer)
require.Equal(t, []sdk.AccAddress{addr}, msgDeletePost.GetSigners())
Expand Down Expand Up @@ -731,11 +706,6 @@ func TestMsgAnswerPoll_ValidateBasic(t *testing.T) {
}
}

func TestMsgAnswerPoll_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgAnswerPoll","value":{"answers_indexes":[1,2,3],"poll_id":1,"post_id":"1","signer":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","subspace_id":"1"}}`
require.Equal(t, expected, string(msgAnswerPoll.GetSignBytes()))
}

func TestMsgAnswerPoll_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgAnswerPoll.Signer)
require.Equal(t, []sdk.AccAddress{addr}, msgAnswerPoll.GetSigners())
Expand Down Expand Up @@ -839,11 +809,6 @@ func TestMsgMovePost_ValidateBasic(t *testing.T) {
}
}

func TestMsgMovePost_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/MsgMovePost","value":{"owner":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","post_id":"1","subspace_id":"1","target_subspace_id":"2"}}`
require.Equal(t, expected, string(msgMovePost.GetSignBytes()))
}

func TestMsgMovePost_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgMovePost.Owner)
require.Equal(t, []sdk.AccAddress{addr}, msgMovePost.GetSigners())
Expand Down Expand Up @@ -897,11 +862,6 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
}
}

func TestMsgUpdateParams_GetSignBytes(t *testing.T) {
expected := `{"type":"desmos/x/posts/MsgUpdateParams","value":{"authority":"cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd","params":{"max_text_length":500}}}`
require.Equal(t, expected, string(msgUpdateParams.GetSignBytes()))
}

func TestMsgUpdateParams_GetSigners(t *testing.T) {
addr, _ := sdk.AccAddressFromBech32(msgUpdateParams.Authority)
require.Equal(t, []sdk.AccAddress{addr}, msgUpdateParams.GetSigners())
Expand Down
21 changes: 1 addition & 20 deletions x/profiles/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -81,22 +80,4 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

var (
amino = codec.NewLegacyAmino()

// AminoCdc references the global x/relationships 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/relationships and
// defined at the application level.
AminoCdc = codec.NewAminoCodec(amino)

ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
)

func init() {
RegisterLegacyAminoCodec(amino)
cryptocodec.RegisterCrypto(amino)
sdk.RegisterLegacyAminoCodec(amino)
}
var ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
Loading

0 comments on commit 763c8fd

Please sign in to comment.