diff --git a/CHANGELOG.md b/CHANGELOG.md index 14b54ec6d12c..cb6bfb4f6822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,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/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 `RegisterKeyTypeCodec` to register new +types (eg. keys) to the `auth` module internal amino codec. ### State Machine Breaking 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 be7f21b3f1d1..53de61568a1a 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -26,6 +26,13 @@ func RegisterCodec(cdc *codec.Codec) { cdc.RegisterConcrete(StdTx{}, "cosmos-sdk/StdTx", nil) } +// RegisterKeyTypeCodec registers an external concrete type defined in +// another module for the internal ModuleCdc. +func RegisterKeyTypeCodec(o interface{}, name string) { + amino.RegisterConcrete(o, name, nil) + ModuleCdc = codec.NewHybridCodec(amino) +} + var ( amino = codec.New() @@ -41,5 +48,4 @@ var ( func init() { RegisterCodec(amino) codec.RegisterCrypto(amino) - amino.Seal() } 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 }