-
Notifications
You must be signed in to change notification settings - Fork 37
/
keys.go
63 lines (47 loc) · 1.77 KB
/
keys.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
53
54
55
56
57
58
59
60
61
62
63
package types
import (
"bytes"
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
)
const (
// ModuleName is the module name constant used in many places
ModuleName = "cork"
// StoreKey is the store key string for oracle
StoreKey = ModuleName
// RouterKey is the message route for oracle
RouterKey = ModuleName
// QuerierRoute is the querier route for oracle
QuerierRoute = ModuleName
)
// Keys for cork store, with <prefix><key> -> <value>
const (
_ = byte(iota)
// CorkForAddressKeyPrefix - <prefix><val_address><address> -> <cork>
CorkForAddressKeyPrefix // key for corks
// CommitPeriodStartKey - <prefix> -> int64(height)
CommitPeriodStartKey // key for commit period height start
// LatestInvalidationNonceKey - <prefix> -> uint64(latestNonce)
LatestInvalidationNonceKey
// CellarIDsKey - <prefix> -> []string
CellarIDsKey
// ScheduledCorkKeyPrefix - <prefix><block_height><val_address><address> -> <cork>
ScheduledCorkKeyPrefix
)
// GetCorkForValidatorAddressKey returns the key for a validators vote for a given address
func GetCorkForValidatorAddressKey(val sdk.ValAddress, contract common.Address) []byte {
return append(GetCorkValidatorKeyPrefix(val), contract.Bytes()...)
}
// GetCorkValidatorKeyPrefix returns the key prefix for cork commits for a validator
func GetCorkValidatorKeyPrefix(val sdk.ValAddress) []byte {
return append([]byte{CorkForAddressKeyPrefix}, val.Bytes()...)
}
func MakeCellarIDsKey() []byte {
return []byte{CellarIDsKey}
}
func GetScheduledCorkKey(blockHeight uint64, val sdk.ValAddress, contract common.Address) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, blockHeight)
return bytes.Join([][]byte{{ScheduledCorkKeyPrefix}, b, val.Bytes(), contract.Bytes()}, []byte{})
}