-
Notifications
You must be signed in to change notification settings - Fork 29
/
tm.go
44 lines (36 loc) · 1.18 KB
/
tm.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
package teststaking
import (
tmcrypto "github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/iqlusioninc/liquidity-staking-module/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, r sdk.Int) (*tmtypes.Validator, error) {
tmPk, err := GetTmConsPubKey(v)
if err != nil {
return nil, err
}
return tmtypes.NewValidator(tmPk, v.ConsensusPower(r)), nil
}
// ToTmValidators casts all validators to the corresponding tendermint type.
func ToTmValidators(v types.Validators, r sdk.Int) ([]*tmtypes.Validator, error) {
validators := make([]*tmtypes.Validator, len(v))
var err error
for i, val := range v {
validators[i], err = ToTmValidator(val, r)
if err != nil {
return nil, err
}
}
return validators, nil
}