From 30d0650424e9418da7684d642ebaf6974a08e592 Mon Sep 17 00:00:00 2001 From: Guillermo Paoletti Date: Fri, 11 Nov 2022 17:18:07 +0100 Subject: [PATCH 1/4] feat: amino encoding support for the vesting module (#1070) * feat: amino enconding support for the vesting module * fix: missing enconding added * chore: update changelog * chore: remove temp files (cherry picked from commit c768d166904686c766039e2f0fd9216197ce0c8e) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 5 +++++ x/vesting/module.go | 4 +++- x/vesting/types/codec.go | 34 ++++++++++++++++++++++++++++------ x/vesting/types/msg.go | 4 ++-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad9e337b2..a4141b4e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,8 +39,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +<<<<<<< HEAD +======= +- (ante) [#1054](https://github.com/evmos/evmos/pull/1054) Remove validator commission `AnteHandler` decorator and replace it with the new `MinCommissionRate` staking parameter. +>>>>>>> c768d16 (feat: amino encoding support for the vesting module (#1070)) - (deps) [\#1041](https://github.com/evmos/evmos/pull/1041) Add ics23 dragonberry replace in go.mod as mentioned in the [Cosmos SDK release](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4) - (deps) [\#1037](https://github.com/evmos/evmos/pull/1037) Bump Ethermint version to [`v0.20.0-rc2`](https://github.com/evmos/ethermint/releases/tag/v0.20.0-rc2) +- (feat) [\#1070](https://github.com/evmos/evmos/pull/1070) Add amino support to the vesting module, it enables signing the module messages using EIP-712. ### API Breaking diff --git a/x/vesting/module.go b/x/vesting/module.go index a2c63359a3..bc4c72daef 100644 --- a/x/vesting/module.go +++ b/x/vesting/module.go @@ -39,7 +39,9 @@ func (AppModuleBasic) Name() string { } // RegisterCodec registers the module's types with the given codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // RegisterInterfaces registers the module's interfaces and implementations with // the given interface registry. diff --git a/x/vesting/types/codec.go b/x/vesting/types/codec.go index f776e1029e..eff688b986 100644 --- a/x/vesting/types/codec.go +++ b/x/vesting/types/codec.go @@ -10,12 +10,26 @@ 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()) +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. + ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + // AminoCdc is a amino codec created to support amino JSON compatible msgs. + AminoCdc = codec.NewAminoCodec(amino) +) + +const ( + // Amino names + clawback = "evmos/MsgClawback" + createClawbackVestingAccount = "evmos/MsgCreateClawbackVestingAccount" +) + +// NOTE: This is required for the GetSignBytes function +func init() { + RegisterLegacyAminoCodec(amino) + amino.Seal() +} // RegisterInterface associates protoName with AccountI and VestingAccount // Interfaces and creates a registry of it's concrete implementations @@ -48,3 +62,11 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } + +// RegisterLegacyAminoCodec registers the necessary x/erc20 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(&MsgClawback{}, clawback, nil) + cdc.RegisterConcrete(&MsgCreateClawbackVestingAccount{}, createClawbackVestingAccount, nil) +} diff --git a/x/vesting/types/msg.go b/x/vesting/types/msg.go index b22bf6a70e..e996c23136 100644 --- a/x/vesting/types/msg.go +++ b/x/vesting/types/msg.go @@ -81,7 +81,7 @@ func (msg MsgCreateClawbackVestingAccount) ValidateBasic() error { // GetSignBytes encodes the message for signing func (msg *MsgCreateClawbackVestingAccount) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg)) } // GetSigners defines whose signature is required @@ -131,7 +131,7 @@ func (msg MsgClawback) ValidateBasic() error { // GetSignBytes encodes the message for signing func (msg *MsgClawback) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) + return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg)) } // GetSigners defines whose signature is required From 1b1b7fcab076b4f1e7653e7038f88cdbc3603738 Mon Sep 17 00:00:00 2001 From: hanchon Date: Mon, 14 Nov 2022 16:48:25 +0100 Subject: [PATCH 2/4] fix: conflicts --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4141b4e45..63d68504b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,10 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking -<<<<<<< HEAD -======= - (ante) [#1054](https://github.com/evmos/evmos/pull/1054) Remove validator commission `AnteHandler` decorator and replace it with the new `MinCommissionRate` staking parameter. ->>>>>>> c768d16 (feat: amino encoding support for the vesting module (#1070)) - (deps) [\#1041](https://github.com/evmos/evmos/pull/1041) Add ics23 dragonberry replace in go.mod as mentioned in the [Cosmos SDK release](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4) - (deps) [\#1037](https://github.com/evmos/evmos/pull/1037) Bump Ethermint version to [`v0.20.0-rc2`](https://github.com/evmos/ethermint/releases/tag/v0.20.0-rc2) - (feat) [\#1070](https://github.com/evmos/evmos/pull/1070) Add amino support to the vesting module, it enables signing the module messages using EIP-712. From c7ff9143488ebd34dc0ec1027e98ea76025df1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Mon, 14 Nov 2022 18:36:15 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63d68504b3..0602755914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ - (ante) [#1054](https://github.com/evmos/evmos/pull/1054) Remove validator commission `AnteHandler` decorator and replace it with the new `MinCommissionRate` staking parameter. - (deps) [\#1041](https://github.com/evmos/evmos/pull/1041) Add ics23 dragonberry replace in go.mod as mentioned in the [Cosmos SDK release](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4) - (deps) [\#1037](https://github.com/evmos/evmos/pull/1037) Bump Ethermint version to [`v0.20.0-rc2`](https://github.com/evmos/ethermint/releases/tag/v0.20.0-rc2) -- (feat) [\#1070](https://github.com/evmos/evmos/pull/1070) Add amino support to the vesting module, it enables signing the module messages using EIP-712. +- (vesting) [\#1070](https://github.com/evmos/evmos/pull/1070) Add Amino encoding support to the vesting module for EIP-712 signing. ### API Breaking From 1cb1f39227fd2c6cfd5404a92d1fde30782d12e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Tue, 15 Nov 2022 13:14:59 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com> --- x/vesting/types/codec.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/vesting/types/codec.go b/x/vesting/types/codec.go index eff688b986..289da2e247 100644 --- a/x/vesting/types/codec.go +++ b/x/vesting/types/codec.go @@ -12,7 +12,7 @@ import ( var ( amino = codec.NewLegacyAmino() - // ModuleCdc references the global vesting module codec. Note, the codec should + // ModuleCdc references the global vesting module codec. Note, the codec should // ONLY be used in certain instances of tests and for JSON encoding. ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) // AminoCdc is a amino codec created to support amino JSON compatible msgs. @@ -63,7 +63,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -// RegisterLegacyAminoCodec registers the necessary x/erc20 interfaces and +// 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) {