From ba8e9268fc5594352379243fbab19609ef69488d Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 11:19:12 -0300 Subject: [PATCH 1/8] readd RegisterAccountTypeCodec --- x/auth/types/codec.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index be7f21b3f1d1..cf9dbd887370 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -26,6 +26,12 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } +// RegisterAccountTypeCodec registers an external account type defined in +// another module for the internal ModuleCdc. +func RegisterAccountTypeCodec(o interface{}, name string) { + ModuleCdc.RegisterConcrete(o, name, nil) +} + var ( amino = codec.New() From fcab2f32a2a1ac493c205b0f44ab3e960872eabb Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 11:54:25 -0300 Subject: [PATCH 2/8] fix --- codec/hybrid_codec.go | 9 +++++++++ x/auth/types/codec.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/codec/hybrid_codec.go b/codec/hybrid_codec.go index c004df1425ce..14597a5641aa 100644 --- a/codec/hybrid_codec.go +++ b/codec/hybrid_codec.go @@ -14,6 +14,15 @@ func NewHybridCodec(amino *Codec) Marshaler { } } +// func (hc HybridCodec) GetAminoCodec() *Codec { +// cdc, ok := hc.amino.(*Codec) +// if !ok { +// return nil +// } + +// return cdc +// } + func (hc *HybridCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) { return hc.proto.MarshalBinaryBare(o) } diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index cf9dbd887370..4c228b98e213 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -29,7 +29,7 @@ func RegisterCodec(cdc *codec.Codec) { // RegisterAccountTypeCodec registers an external account type defined in // another module for the internal ModuleCdc. func RegisterAccountTypeCodec(o interface{}, name string) { - ModuleCdc.RegisterConcrete(o, name, nil) + amino.RegisterConcrete(o, name, nil) } var ( From c2e00ebd34a251bb59b2dee98df60b6aa123b942 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 12:08:32 -0300 Subject: [PATCH 3/8] remove seal --- x/auth/types/codec.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 4c228b98e213..b46a3e067435 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -29,7 +29,7 @@ func RegisterCodec(cdc *codec.Codec) { // RegisterAccountTypeCodec registers an external account type defined in // another module for the internal ModuleCdc. func RegisterAccountTypeCodec(o interface{}, name string) { - amino.RegisterConcrete(o, name, nil) + amino.RegisterConcrete(o, name, nil) } var ( @@ -47,5 +47,4 @@ var ( func init() { RegisterCodec(amino) codec.RegisterCrypto(amino) - amino.Seal() } From 2942e8aea8a989d4aa10cc9abf2e4659b1859c1c Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 12:21:54 -0300 Subject: [PATCH 4/8] update BaseAccount and StdSig to use amino codec --- x/auth/types/account.go | 3 +-- x/auth/types/codec.go | 1 + x/auth/types/stdtx.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/types/account.go b/x/auth/types/account.go index bae7d8f3b4fe..8be072d1d169 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -8,7 +8,6 @@ import ( "github.com/tendermint/tendermint/crypto" yaml "gopkg.in/yaml.v2" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" ) @@ -61,7 +60,7 @@ func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) { return nil } - codec.Cdc.MustUnmarshalBinaryBare(acc.PubKey, &pk) + amino.MustUnmarshalBinaryBare(acc.PubKey, &pk) return pk } diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index b46a3e067435..4d041e1fdf08 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -30,6 +30,7 @@ func RegisterCodec(cdc *codec.Codec) { // another module for the internal ModuleCdc. func RegisterAccountTypeCodec(o interface{}, name string) { amino.RegisterConcrete(o, name, nil) + ModuleCdc = codec.NewHybridCodec(amino) } var ( diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 04e9ec1fdd79..786d8ffde979 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -79,7 +79,7 @@ func (ss StdSignature) GetPubKey() (pk crypto.PubKey) { return nil } - codec.Cdc.MustUnmarshalBinaryBare(ss.PubKey, &pk) + amino.MustUnmarshalBinaryBare(ss.PubKey, &pk) return pk } From ee15eeaae6727e17e26906cbd365c9bbb99f0824 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 12:24:31 -0300 Subject: [PATCH 5/8] remove comments --- codec/hybrid_codec.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/codec/hybrid_codec.go b/codec/hybrid_codec.go index 14597a5641aa..c004df1425ce 100644 --- a/codec/hybrid_codec.go +++ b/codec/hybrid_codec.go @@ -14,15 +14,6 @@ func NewHybridCodec(amino *Codec) Marshaler { } } -// func (hc HybridCodec) GetAminoCodec() *Codec { -// cdc, ok := hc.amino.(*Codec) -// if !ok { -// return nil -// } - -// return cdc -// } - func (hc *HybridCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) { return hc.proto.MarshalBinaryBare(o) } From f5622974a700fd3949007e4185683f2da9c55e5f Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 13:54:21 -0300 Subject: [PATCH 6/8] rename --- x/auth/types/codec.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 4d041e1fdf08..6f50d86c6a93 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -26,9 +26,9 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } -// RegisterAccountTypeCodec registers an external account type defined in +// RegisterConcreteTypeCodec registers an external concrete type defined in // another module for the internal ModuleCdc. -func RegisterAccountTypeCodec(o interface{}, name string) { +func RegisterConcreteTypeCodec(o interface{}, name string) { amino.RegisterConcrete(o, name, nil) ModuleCdc = codec.NewHybridCodec(amino) } From 510bc1f4ea7e29ebcd91c4f61b462e3cbcab8d42 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 13:56:44 -0300 Subject: [PATCH 7/8] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1505a53da4bb..230e17d6988d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,8 @@ to now accept a `codec.JSONMarshaler` for modular serialization of genesis state * (modules) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) `InitGenesis`, for the relevant modules, now ensures module accounts exist. * (crypto/keys) [\#5844](https://github.com/cosmos/cosmos-sdk/pull/5844) Keybase/Keyring `Sign()` methods no longer decode amino signatures when method receivers are offline/multisig keys. +* (x/auth) [\#5892](https://github.com/cosmos/cosmos-sdk/pull/5892) Add `RegisterConcreteTypeCodec` to register new +types (eg. keys) to the `auth` module internal amino codec. ### State Machine Breaking From 28d5aaec5e3eabf30b410c9d852bd91549f2b647 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 30 Mar 2020 13:58:53 -0300 Subject: [PATCH 8/8] rename --- CHANGELOG.md | 2 +- x/auth/types/codec.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d809800718b..3b7ab31b0ea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,7 +88,7 @@ to now accept a `codec.JSONMarshaler` for modular serialization of genesis state * (modules) [\#5569](https://github.com/cosmos/cosmos-sdk/issues/5569) `InitGenesis`, for the relevant modules, now ensures module accounts exist. * (crypto/keyring) [\#5844](https://github.com/cosmos/cosmos-sdk/pull/5844) Keybase/Keyring `Sign()` methods no longer decode amino signatures when method receivers are offline/multisig keys. -* (x/auth) [\#5892](https://github.com/cosmos/cosmos-sdk/pull/5892) Add `RegisterConcreteTypeCodec` to register new +* (x/auth) [\#5892](https://github.com/cosmos/cosmos-sdk/pull/5892) Add `RegisterKeyTypeCodec` to register new types (eg. keys) to the `auth` module internal amino codec. ### State Machine Breaking diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 6f50d86c6a93..53de61568a1a 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -26,9 +26,9 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } -// RegisterConcreteTypeCodec registers an external concrete type defined in +// RegisterKeyTypeCodec registers an external concrete type defined in // another module for the internal ModuleCdc. -func RegisterConcreteTypeCodec(o interface{}, name string) { +func RegisterKeyTypeCodec(o interface{}, name string) { amino.RegisterConcrete(o, name, nil) ModuleCdc = codec.NewHybridCodec(amino) }