From 3fe4097b326d42c9a71b5e91af9bce890820e123 Mon Sep 17 00:00:00 2001 From: chixiaoxiao Date: Thu, 14 Mar 2024 15:01:25 +0800 Subject: [PATCH] use validatorUpdates in x/genutil --- x/genutil/genesis.go | 30 ++++++++++++++++++++++++++---- x/genutil/module.go | 26 +------------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/x/genutil/genesis.go b/x/genutil/genesis.go index 64d55293485b7..4e3c56448c50d 100644 --- a/x/genutil/genesis.go +++ b/x/genutil/genesis.go @@ -2,8 +2,8 @@ package genutil import ( "context" - - abci "github.com/cometbft/cometbft/abci/types" + "fmt" + "github.com/cosmos/cosmos-sdk/types/module" "cosmossdk.io/core/genesis" @@ -16,9 +16,31 @@ func InitGenesis( ctx context.Context, stakingKeeper types.StakingKeeper, deliverTx genesis.TxHandler, genesisState types.GenesisState, txEncodingConfig client.TxEncodingConfig, -) (validators []abci.ValidatorUpdate, err error) { +) (validatorUpdates []module.ValidatorUpdate, err error) { if len(genesisState.GenTxs) > 0 { - validators, err = DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig) + cometValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig) + if err != nil { + return nil, err + } + validatorUpdates = make([]module.ValidatorUpdate, len(cometValidatorUpdates)) + for i, v := range cometValidatorUpdates { + if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: ed25519, + PubKeyType: "ed25519", + Power: v.Power, + } + } else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 { + validatorUpdates[i] = module.ValidatorUpdate{ + PubKey: secp256k1, + PubKeyType: "secp256k1", + Power: v.Power, + } + } else { + return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey) + } + } + return validatorUpdates, nil } return } diff --git a/x/genutil/module.go b/x/genutil/module.go index a37b7f021d3e1..cc68668891528 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -78,31 +78,7 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) ([]module.ValidatorUpdate, error) { var genesisState types.GenesisState am.cdc.MustUnmarshalJSON(data, &genesisState) - cometValidatorUpdates, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) - if err != nil { - return nil, err - } - - validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates)) - for i, v := range cometValidatorUpdates { - if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 { - validatorUpdates[i] = module.ValidatorUpdate{ - PubKey: ed25519, - PubKeyType: "ed25519", - Power: v.Power, - } - } else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 { - validatorUpdates[i] = module.ValidatorUpdate{ - PubKey: secp256k1, - PubKeyType: "secp256k1", - Power: v.Power, - } - } else { - return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey) - } - } - - return validatorUpdates, nil + return InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) } // ExportGenesis returns the exported genesis state as raw bytes for the genutil module.