-
Notifications
You must be signed in to change notification settings - Fork 41
/
keys.go
97 lines (80 loc) · 4.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the module.
ModuleName = "oracle"
// Version defines the current version the IBC oracle module supports
Version = "bandchain-1"
// StoreKey to be used when creating the KVStore.
StoreKey = ModuleName
// QuerierRoute is the querier route for the oracle module
QuerierRoute = ModuleName
// RouterKey is the msg router key for the oracle module
RouterKey = ModuleName
// PortID is the default port id that oracle module binds to.
PortID = ModuleName
)
var (
// RollingSeedSizeInBytes is the size of rolling block hash for random seed.
RollingSeedSizeInBytes = 32
// GlobalStoreKeyPrefix is the prefix for global primitive state variables.
GlobalStoreKeyPrefix = []byte{0x00}
// RollingSeedStoreKey is the key that keeps the seed based on the first 8-bit of the most recent 32 block hashes.
RollingSeedStoreKey = append(GlobalStoreKeyPrefix, []byte("RollingSeed")...)
// RequestCountStoreKey is the key that keeps the total request count.
RequestCountStoreKey = append(GlobalStoreKeyPrefix, []byte("RequestCount")...)
// RequestLastExpiredStoreKey is the key that keeps the ID of the last expired request, or 0 if none.
RequestLastExpiredStoreKey = append(GlobalStoreKeyPrefix, []byte("RequestLastExpired")...)
// PendingResolveListStoreKey is the key that keeps the list of pending-resolve requests.
PendingResolveListStoreKey = append(GlobalStoreKeyPrefix, []byte("PendingList")...)
// DataSourceCountStoreKey is the key that keeps the total data source count.
DataSourceCountStoreKey = append(GlobalStoreKeyPrefix, []byte("DataSourceCount")...)
// OracleScriptCountStoreKey is the key that keeps the total oracle sciprt count.
OracleScriptCountStoreKey = append(GlobalStoreKeyPrefix, []byte("OracleScriptCount")...)
// RequestStoreKeyPrefix is the prefix for request store.
RequestStoreKeyPrefix = []byte{0x01}
// ReportStoreKeyPrefix is the prefix for report store.
ReportStoreKeyPrefix = []byte{0x02}
// DataSourceStoreKeyPrefix is the prefix for data source store.
DataSourceStoreKeyPrefix = []byte{0x03}
// OracleScriptStoreKeyPrefix is the prefix for oracle script store.
OracleScriptStoreKeyPrefix = []byte{0x04}
// ValidatorStatusKeyPrefix is the prefix for validator status store.
ValidatorStatusKeyPrefix = []byte{0x05}
// ResultStoreKeyPrefix is the prefix for request result store.
ResultStoreKeyPrefix = []byte{0xff}
// PortKey defines the key to store the port ID in store
PortKey = []byte{0xf0}
)
// RequestStoreKey returns the key to retrieve a specific request from the store.
func RequestStoreKey(requestID RequestID) []byte {
return append(RequestStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(requestID))...)
}
// ReportStoreKey returns the key to retrieve all data reports for a request.
func ReportStoreKey(requestID RequestID) []byte {
return append(ReportStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(requestID))...)
}
// DataSourceStoreKey returns the key to retrieve a specific data source from the store.
func DataSourceStoreKey(dataSourceID DataSourceID) []byte {
return append(DataSourceStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(dataSourceID))...)
}
// OracleScriptStoreKey returns the key to retrieve a specific oracle script from the store.
func OracleScriptStoreKey(oracleScriptID OracleScriptID) []byte {
return append(OracleScriptStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(oracleScriptID))...)
}
// ValidatorStatusStoreKey returns the key to a validator's status.
func ValidatorStatusStoreKey(v sdk.ValAddress) []byte {
return append(ValidatorStatusKeyPrefix, v.Bytes()...)
}
// ResultStoreKey returns the key to a request result in the store.
func ResultStoreKey(requestID RequestID) []byte {
return append(ResultStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(requestID))...)
}
// ReportsOfValidatorPrefixKey returns the prefix key to get all reports for a request from a validator.
func ReportsOfValidatorPrefixKey(reqID RequestID, val sdk.ValAddress) []byte {
buf := append(ReportStoreKeyPrefix, sdk.Uint64ToBigEndian(uint64(reqID))...)
buf = append(buf, val.Bytes()...)
return buf
}