Skip to content

Commit

Permalink
Use nil instead of protobuf.Empty in genesis BaseAccount (#7463)
Browse files Browse the repository at this point in the history
* Use nil instead of protobuf.Empty in genesis

* Fix tests
  • Loading branch information
amaury1093 authored Oct 6, 2020
1 parent c9cb02e commit 090bae5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
19 changes: 6 additions & 13 deletions x/auth/legacy/v040/migrate.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -13,20 +11,15 @@ 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)
if err != nil {
panic(err)
}
}

return &v040auth.BaseAccount{
Expand Down
5 changes: 1 addition & 4 deletions x/auth/legacy/v040/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 090bae5

Please sign in to comment.