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:
parent
c9cb02ea98
commit
090bae567b
|
@ -1,8 +1,6 @@
|
||||||
package v040
|
package v040
|
||||||
|
|
||||||
import (
|
import (
|
||||||
pt "github.com/gogo/protobuf/types"
|
|
||||||
|
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
|
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.
|
// convertBaseAccount converts a 0.39 BaseAccount to a 0.40 BaseAccount.
|
||||||
func convertBaseAccount(old *v039auth.BaseAccount) *v040auth.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 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 {
|
if old.PubKey != nil {
|
||||||
|
var err error
|
||||||
any, err = tx.PubKeyToAny(old.PubKey)
|
any, err = tx.PubKeyToAny(old.PubKey)
|
||||||
} else {
|
|
||||||
s := pt.Empty{}
|
|
||||||
any, err = codectypes.NewAnyWithValue(&s)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &v040auth.BaseAccount{
|
return &v040auth.BaseAccount{
|
||||||
Address: old.Address.String(),
|
Address: old.Address.String(),
|
||||||
|
|
|
@ -228,10 +228,7 @@ func TestMigrate(t *testing.T) {
|
||||||
"@type": "/cosmos.auth.v1beta1.BaseAccount",
|
"@type": "/cosmos.auth.v1beta1.BaseAccount",
|
||||||
"account_number": "1",
|
"account_number": "1",
|
||||||
"address": "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00",
|
"address": "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00",
|
||||||
"pub_key": {
|
"pub_key": null,
|
||||||
"@type": "/google.protobuf.Empty",
|
|
||||||
"value": {}
|
|
||||||
},
|
|
||||||
"sequence": "0"
|
"sequence": "0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -19,7 +19,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
legacytx.RegisterLegacyAminoCodec(cdc)
|
legacytx.RegisterLegacyAminoCodec(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInterface associates protoName with AccountI interface
|
// RegisterInterfaces associates protoName with AccountI interface
|
||||||
// and creates a registry of it's concrete implementations
|
// and creates a registry of it's concrete implementations
|
||||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||||
registry.RegisterInterface(
|
registry.RegisterInterface(
|
||||||
|
|
Loading…
Reference in New Issue