Use nil instead of protobuf.Empty in genesis BaseAccount (#7463)

* Use nil instead of protobuf.Empty in genesis

* Fix tests
This commit is contained in:
Amaury Martiny 2020-10-06 18:07:37 +02:00 committed by GitHub
parent c9cb02ea98
commit 090bae567b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 18 deletions

View File

@ -1,8 +1,6 @@
package v040
import (
pt "github.com/gogo/protobuf/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
@ -13,21 +11,16 @@ import (
// convertBaseAccount converts a 0.39 BaseAccount to a 0.40 BaseAccount.
func convertBaseAccount(old *v039auth.BaseAccount) *v040auth.BaseAccount {
// In `x/auth/legacy/v038/migrate.go`, when creating a BaseAccount, we
// explicitly set the PublicKey field to nil. This propagates until 0.40,
// and we don't know the PubKey for those accounts, so we just put an empty
// string inside the Any.
var any *codectypes.Any
var err error
// If the old genesis had a pubkey, we pack it inside an Any. Or else, we
// just leave it nil.
if old.PubKey != nil {
var err error
any, err = tx.PubKeyToAny(old.PubKey)
} else {
s := pt.Empty{}
any, err = codectypes.NewAnyWithValue(&s)
}
if err != nil {
panic(err)
}
}
return &v040auth.BaseAccount{
Address: old.Address.String(),

View File

@ -228,10 +228,7 @@ func TestMigrate(t *testing.T) {
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"account_number": "1",
"address": "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00",
"pub_key": {
"@type": "/google.protobuf.Empty",
"value": {}
},
"pub_key": null,
"sequence": "0"
}
],

View File

@ -19,7 +19,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacytx.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterface associates protoName with AccountI interface
// RegisterInterfaces associates protoName with AccountI interface
// and creates a registry of it's concrete implementations
func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterInterface(