-
Notifications
You must be signed in to change notification settings - Fork 111
/
validator.go
38 lines (30 loc) · 1.05 KB
/
validator.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
package types
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
func NewCCValidator(address []byte, power int64, pubKey cryptotypes.PubKey) (CrossChainValidator, error) {
pkAny, err := codectypes.NewAnyWithValue(pubKey)
if err != nil {
return CrossChainValidator{}, err
}
return CrossChainValidator{
Address: address,
Power: power,
Pubkey: pkAny,
}, nil
}
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (ccv CrossChainValidator) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var pk cryptotypes.PubKey
return unpacker.UnpackAny(ccv.Pubkey, &pk)
}
// ConsPubKey returns the validator PubKey as a cryptotypes.PubKey.
func (ccv CrossChainValidator) ConsPubKey() (cryptotypes.PubKey, error) {
pk, ok := ccv.Pubkey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "expecting cryptotypes.PubKey, got %T", pk)
}
return pk, nil
}