-
Notifications
You must be signed in to change notification settings - Fork 340
/
sequencer.go
45 lines (39 loc) · 1.39 KB
/
sequencer.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 types
import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
tmtypes "github.com/tendermint/tendermint/types"
)
func (seq Sequencer) IsBonded() bool {
return seq.Status == Bonded
}
// is proposer
func (seq Sequencer) IsProposer() bool {
return seq.Proposer
}
// GetDymintPubKeyHash returns the hash of the sequencer
// as expected to be written on the rollapp ibc client headers
func (seq Sequencer) GetDymintPubKeyHash() ([]byte, error) {
// load the dymint pubkey into a cryptotypes.PubKey
interfaceRegistry := cdctypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(interfaceRegistry)
protoCodec := codec.NewProtoCodec(interfaceRegistry)
var pubKey cryptotypes.PubKey
err := protoCodec.UnpackAny(seq.DymintPubKey, &pubKey)
if err != nil {
return nil, err
}
// convert the pubkey to tmPubKey
tmPubKey, err := cryptocodec.ToTmPubKeyInterface(pubKey)
if err != nil {
return nil, err
}
// Create a new tmValidator with fixed voting power of 1
// TODO: Make sure the voting power is a param coming from hub and
// not being set independently in dymint and hub
tmValidator := tmtypes.NewValidator(tmPubKey, 1)
tmValidatorSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{tmValidator})
return tmValidatorSet.Hash(), nil
}