* WIP on removing tm pub/privkey * Fix part of crypto tests * Add PrivKeyLedgerSecp256K1 proto type * Use BasePrivKey for ledger priv key type * Refacto continued * First round * x/staking * Continue porting * x/* done * Make build pass * More conversion * Remove IntoTmPubKey * Fix test * Remove crypto.PubKey in some other places * Revert ledger changes * Fix comment * Remove useless function * Add To/FromTmPublicKey * Add migrate tests * Fix test * Fix another test * Rename tm conversion functions * Less code * Rename BasePrivKey to LedgerPrivKey * Add changelog * Rename functions Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package teststaking
|
|
|
|
import (
|
|
tmcrypto "github.com/tendermint/tendermint/crypto"
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
)
|
|
|
|
// GetTmConsPubKey gets the validator's public key as a tmcrypto.PubKey.
|
|
func GetTmConsPubKey(v types.Validator) (tmcrypto.PubKey, error) {
|
|
pk, err := v.ConsPubKey()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cryptocodec.ToTmPubKeyInterface(pk)
|
|
}
|
|
|
|
// ToTmValidator casts an SDK validator to a tendermint type Validator.
|
|
func ToTmValidator(v types.Validator) (*tmtypes.Validator, error) {
|
|
tmPk, err := GetTmConsPubKey(v)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return tmtypes.NewValidator(tmPk, v.ConsensusPower()), nil
|
|
}
|
|
|
|
// ToTmValidators casts all validators to the corresponding tendermint type.
|
|
func ToTmValidators(v types.Validators) ([]*tmtypes.Validator, error) {
|
|
validators := make([]*tmtypes.Validator, len(v))
|
|
var err error
|
|
for i, val := range v {
|
|
validators[i], err = ToTmValidator(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return validators, nil
|
|
}
|