-
Notifications
You must be signed in to change notification settings - Fork 1
/
key_valset.go
52 lines (42 loc) · 1.7 KB
/
key_valset.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
46
47
48
49
50
51
52
package types
import (
"encoding/binary"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/router-protocol/sdk-go/routerchain/util"
)
var _ binary.ByteOrder
const (
// ValsetKeyPrefix is the prefix to retrieve all Valset
ValsetKeyPrefix = "Valset/value/"
)
var (
// LatestValsetNonce indexes the latest valset nonce
// [0xba0fa05da166611b656bac7739a6e7d3]
LatestValsetNonce = util.HashString("LatestValsetNonce")
// LastUnBondingBlockHeight indexes the last validator unbonding block height
// [0x06a6b30651341e80276e0d2e19449250]
LastUnBondingBlockHeight = util.HashString("LastUnBondingBlockHeight")
// LastEventNonceByValidatorKey indexes lateset event nonce by validator
// [0xeefcb999cc3d7b80b052b55106a6ba5e]
LastEventNonceByValidatorKey = util.HashString("LastEventNonceByValidatorKey")
)
// ValsetKey returns the store key to retrieve a Valset from the index fields
func ValsetKey(
valsetNonce uint64,
) []byte {
return util.AppendBytes(util.HashString(ValsetKeyPrefix), util.UInt64Bytes(valsetNonce))
}
// GetLastEventByValidatorKey indexes latest event nonce by validator
// GetLastEventByValidatorKey returns the following key format
// prefix cosmos-validator
// [0x0][gravity1ahx7f8wyertuus9r20284ej0asrs085ceqtfnm]
func GetLastEventByValidatorKey(validator sdk.ValAddress, chainId string, contract string) []byte {
if err := sdk.VerifyAddressFormat(validator); err != nil {
panic(sdkerrors.Wrap(err, "invalid validator address"))
}
chainId = strings.ToLower(chainId)
contract = strings.ToLower(contract)
return util.AppendBytes(LastEventNonceByValidatorKey, []byte(chainId), []byte(contract), validator.Bytes())
}