Skip to content

Commit 090bae5

Browse files
authored
Use nil instead of protobuf.Empty in genesis BaseAccount (#7463)
* Use nil instead of protobuf.Empty in genesis * Fix tests
1 parent c9cb02e commit 090bae5

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

x/auth/legacy/v040/migrate.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package v040
22

33
import (
4-
pt "github.com/gogo/protobuf/types"
5-
64
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
75
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
86
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
@@ -13,20 +11,15 @@ import (
1311

1412
// convertBaseAccount converts a 0.39 BaseAccount to a 0.40 BaseAccount.
1513
func convertBaseAccount(old *v039auth.BaseAccount) *v040auth.BaseAccount {
16-
// In `x/auth/legacy/v038/migrate.go`, when creating a BaseAccount, we
17-
// explicitly set the PublicKey field to nil. This propagates until 0.40,
18-
// and we don't know the PubKey for those accounts, so we just put an empty
19-
// string inside the Any.
2014
var any *codectypes.Any
21-
var err error
15+
// If the old genesis had a pubkey, we pack it inside an Any. Or else, we
16+
// just leave it nil.
2217
if old.PubKey != nil {
18+
var err error
2319
any, err = tx.PubKeyToAny(old.PubKey)
24-
} else {
25-
s := pt.Empty{}
26-
any, err = codectypes.NewAnyWithValue(&s)
27-
}
28-
if err != nil {
29-
panic(err)
20+
if err != nil {
21+
panic(err)
22+
}
3023
}
3124

3225
return &v040auth.BaseAccount{

x/auth/legacy/v040/migrate_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ func TestMigrate(t *testing.T) {
228228
"@type": "/cosmos.auth.v1beta1.BaseAccount",
229229
"account_number": "1",
230230
"address": "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00",
231-
"pub_key": {
232-
"@type": "/google.protobuf.Empty",
233-
"value": {}
234-
},
231+
"pub_key": null,
235232
"sequence": "0"
236233
}
237234
],

x/auth/types/codec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
1919
legacytx.RegisterLegacyAminoCodec(cdc)
2020
}
2121

22-
// RegisterInterface associates protoName with AccountI interface
22+
// RegisterInterfaces associates protoName with AccountI interface
2323
// and creates a registry of it's concrete implementations
2424
func RegisterInterfaces(registry types.InterfaceRegistry) {
2525
registry.RegisterInterface(

0 commit comments

Comments
 (0)