-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmt.go
executable file
·45 lines (36 loc) · 1.17 KB
/
cmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package testutil
import (
cmtcrypto "github.com/cometbft/cometbft/crypto"
cmttypes "github.com/cometbft/cometbft/types"
"cosmossdk.io/math"
"github.com/axiome-pro/axm-node/x/staking/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
)
// GetCmtConsPubKey gets the validator's public key as a cmtcrypto.PubKey.
func GetCmtConsPubKey(v types.Validator) (cmtcrypto.PubKey, error) {
pk, err := v.ConsPubKey()
if err != nil {
return nil, err
}
return cryptocodec.ToCmtPubKeyInterface(pk)
}
// ToCmtValidator casts an SDK validator to a CometBFT type Validator.
func ToCmtValidator(v types.Validator, r math.Int) (*cmttypes.Validator, error) {
tmPk, err := GetCmtConsPubKey(v)
if err != nil {
return nil, err
}
return cmttypes.NewValidator(tmPk, v.ConsensusPower(r)), nil
}
// ToCmtValidators casts all validators to the corresponding CometBFT type.
func ToCmtValidators(v types.Validators, r math.Int) ([]*cmttypes.Validator, error) {
validators := make([]*cmttypes.Validator, len(v.Validators))
var err error
for i, val := range v.Validators {
validators[i], err = ToCmtValidator(val, r)
if err != nil {
return nil, err
}
}
return validators, nil
}