Skip to content

Commit

Permalink
chore: fix codec-related parts
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed May 3, 2024
1 parent 70f9499 commit ebefc77
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
18 changes: 18 additions & 0 deletions x/fswap/codec/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package codec

import (
"github.com/Finschia/finschia-sdk/codec"
cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec"
sdk "github.com/Finschia/finschia-sdk/types"
)

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
cryptocodec.RegisterCrypto(Amino)
codec.RegisterEvidences(Amino)
sdk.RegisterLegacyAminoCodec(Amino)
}
8 changes: 1 addition & 7 deletions x/fswap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ func (AppModuleBasic) Name() string {
return types.ModuleName
}

func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}
func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {}

// RegisterInterfaces registers the module's interface types
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
Expand Down
36 changes: 13 additions & 23 deletions x/fswap/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,38 @@ package types

import (
"github.com/Finschia/finschia-sdk/codec"
"github.com/Finschia/finschia-sdk/codec/legacy"
"github.com/Finschia/finschia-sdk/codec/types"
cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec"
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/types/msgservice"
authzcodec "github.com/Finschia/finschia-sdk/x/authz/codec"
fdncodec "github.com/Finschia/finschia-sdk/x/foundation/codec"
fscodec "github.com/Finschia/finschia-sdk/x/fswap/codec"
govcodec "github.com/Finschia/finschia-sdk/x/gov/codec"
govtypes "github.com/Finschia/finschia-sdk/x/gov/types"
)

func RegisterCodec(cdc *codec.LegacyAmino) {
// this line is used by starport scaffolding # 2
}

// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MakeSwapProposal{}, "finschia-sdk/MakeSwapProposal", nil)
legacy.RegisterAminoMsg(cdc, &MsgSwap{}, "lbm-sdk/MsgSwap")
legacy.RegisterAminoMsg(cdc, &MsgSwapAll{}, "lbm-sdk/MsgSwapAll")

cdc.RegisterConcrete(&MakeSwapProposal{}, "lbm-sdk/MakeSwapProposal", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
// this line is used by starport scaffolding # 3
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSwap{},
&MsgSwapAll{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)

registry.RegisterImplementations(
(*govtypes.Content)(nil),
&MakeSwapProposal{},
)
}

var (
amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
)

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 and MsgExec
// instances.
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(fdncodec.Amino)
RegisterLegacyAminoCodec(fscodec.Amino)
}
11 changes: 11 additions & 0 deletions x/fswap/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
"github.com/Finschia/finschia-sdk/x/fswap/codec"
)

var _ sdk.Msg = &MsgSwap{}
Expand Down Expand Up @@ -38,6 +39,11 @@ func (m *MsgSwap) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{from}
}

// GetSignBytes implements the LegacyMsg.GetSignBytes method.
func (m *MsgSwap) GetSignBytes() []byte {
return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m))
}

var _ sdk.Msg = &MsgSwapAll{}

// ValidateBasic Implements Msg.
Expand Down Expand Up @@ -66,3 +72,8 @@ func (m *MsgSwapAll) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{from}
}

// GetSignBytes implements the LegacyMsg.GetSignBytes method.
func (m *MsgSwapAll) GetSignBytes() []byte {
return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(m))
}

0 comments on commit ebefc77

Please sign in to comment.