Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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