/
keys.go
66 lines (50 loc) · 2.18 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
64
65
66
package types
import (
"bytes"
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 = "allocation"
// 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 allocation store, with <prefix><key> -> <value>
const (
_ = byte(iota)
// CellarKeyPrefix - <prefix><cellar_id> -> Cellar
CellarKeyPrefix
// AllocationPrecommitKeyPrefix - <prefix><val_address><cel_address> -> <hash>
AllocationPrecommitKeyPrefix // key for allocation precommits
// AllocationCommitForCellarKeyPrefix - <prefix><val_address><cel_address> -> <allocation_commit>
AllocationCommitForCellarKeyPrefix // key for allocation commits
// CommitPeriodStartKey - <prefix> -> int64(height)
CommitPeriodStartKey // key for commit period height start
// LatestInvalidationNonceKey - <prefix> -> uint64(latestNonce)
LatestInvalidationNonceKey
)
// GetAllocationPrecommitKey returns the key for a validators prevote for a cellar
func GetAllocationPrecommitKey(val sdk.ValAddress, cel common.Address) []byte {
return bytes.Join([][]byte{{AllocationPrecommitKeyPrefix}, val.Bytes(), cel.Bytes()}, []byte{})
}
// GetAllocationCommitForCellarKey returns the key for a validators vote for a given cellar
func GetAllocationCommitForCellarKey(val sdk.ValAddress, cel common.Address) []byte {
return append(GetAllocationCommitKeyPrefix(val), cel.Bytes()...)
}
// GetAllocationCommitKeyPrefix returns the key prefix for allocation commits for a validator
func GetAllocationCommitKeyPrefix(val sdk.ValAddress) []byte {
return append([]byte{AllocationCommitForCellarKeyPrefix}, val.Bytes()...)
}
// GetCellarUpdateKey - the pending cellar update by invalidation nonce
func GetCellarUpdateKey(invalidationNonce uint64) []byte {
return append([]byte{CellarKeyPrefix}, sdk.Uint64ToBigEndian(invalidationNonce)...)
}
// GetCellarKey - the cellar by id
func GetCellarKey(address common.Address) []byte {
return append([]byte{CellarKeyPrefix}, address.Bytes()...)
}