refactor(x/staking,genutil)!: use validatorUpdates (#19754)

Co-authored-by: chixiaoxiao <chixiaoxiao@gmail.com>
This commit is contained in:
Chi Xiao Wen
2024-03-19 19:48:56 +00:00
committed by GitHub
co-authored by chixiaoxiao
parent a1bfe5d285
commit bfa734ce8f
14 changed files with 121 additions and 147 deletions
+1 -25
View File
@@ -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.