Skip to content

Commit

Permalink
imp(vesting): add amino vesting (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanguyenkh authored Jul 6, 2022
1 parent aca87d9 commit 9c1d456
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
6 changes: 4 additions & 2 deletions x/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func (AppModuleBasic) Name() string {
return types.ModuleName
}

// RegisterCodec registers the module's types with the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {}
// RegisterLegacyAminoCodec registers the module's types with the given codec.
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterLegacyAminoCodec(cdc)
}

// RegisterInterfaces registers the module's interfaces and implementations with
// the given interface registry.
Expand Down
42 changes: 34 additions & 8 deletions x/vesting/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@ import (
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

// ModuleCdc references the global erc20 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 modules/erc20 and
// defined at the application level.
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())

// RegisterInterface associates protoName with AccountI and VestingAccount
var (
amino = codec.NewLegacyAmino()

// ModuleCdc references the global vesting 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 modules/vesting and
// defined at the application level.
ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())

// AminoCdc is a amino codec created to support amino JSON compatible msgs.
AminoCdc = codec.NewAminoCodec(amino)
)

const (
// Amino names
createClawbackVestingAccount = "astra/MsgCreateClawbackVestingAccount"
clawback = "astra/MsgClawback"
)

func init() {
RegisterLegacyAminoCodec(amino)
amino.Seal()
}

// RegisterInterfaces associates protoName with AccountI and VestingAccount
// Interfaces and creates a registry of it's concrete implementations
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
// NOTE: BaseVestingAccount is still supported to as it's the underlying embedded
Expand Down Expand Up @@ -48,3 +66,11 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

// RegisterLegacyAminoCodec registers the necessary x/vesting interfaces and
// concrete types on the provided LegacyAmino codec. These types are used for
// Amino JSON serialization and EIP-712 compatibility.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgCreateClawbackVestingAccount{}, createClawbackVestingAccount, nil)
cdc.RegisterConcrete(&MsgClawback{}, clawback, nil)
}
8 changes: 4 additions & 4 deletions x/vesting/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func (msg MsgCreateClawbackVestingAccount) ValidateBasic() error {
}

// GetSignBytes encodes the message for signing
func (msg *MsgCreateClawbackVestingAccount) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
func (msg MsgCreateClawbackVestingAccount) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
}

// GetSigners defines whose signature is required
Expand Down Expand Up @@ -129,8 +129,8 @@ func (msg MsgClawback) ValidateBasic() error {
}

// GetSignBytes encodes the message for signing
func (msg *MsgClawback) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
func (msg MsgClawback) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
}

// GetSigners defines whose signature is required
Expand Down

0 comments on commit 9c1d456

Please sign in to comment.