-
Notifications
You must be signed in to change notification settings - Fork 31
/
keys.go
65 lines (51 loc) · 1.68 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
package types
import (
"encoding/binary"
servicetypes "github.com/irisnet/irismod/modules/service/types"
)
// nolint
const (
// module name
ModuleName = "oracle"
// StoreKey is the default store key for oracle
StoreKey = ModuleName
// RouterKey is the message route for oracle
RouterKey = ModuleName
// QuerierRoute is the querier route for the oracle store.
QuerierRoute = StoreKey
)
var (
// Keys for store prefixes
delimiter = []byte{0x00}
PrefixFeedKey = []byte{0x01}
PrefixReqCtxIdKey = []byte{0x02}
PrefixFeedValueKey = []byte{0x03}
PrefixFeedRunningStateKey = []byte{0x04}
PrefixFeedPauseStateKey = []byte{0x05}
)
func GetFeedKey(feedName string) []byte {
return append(append(PrefixFeedKey, delimiter...), []byte(feedName)...)
}
func GetFeedPrefixKey() []byte {
return append(PrefixFeedKey, delimiter...)
}
func GetReqCtxIDKey(requestContextID []byte) []byte {
return append(append(PrefixReqCtxIdKey, delimiter...), requestContextID...)
}
func GetFeedValueKey(feedName string, batchCounter uint64) []byte {
key := make([]byte, 8)
binary.BigEndian.PutUint64(key[:], batchCounter)
return append(GetFeedValuePrefixKey(feedName), key...)
}
func GetFeedValuePrefixKey(feedName string) []byte {
return append(append(PrefixFeedValueKey, []byte(feedName)...), delimiter...)
}
func GetFeedStateKey(feedName string, state servicetypes.RequestContextState) []byte {
return append(append(GetFeedStatePrefixKey(state), delimiter...), []byte(feedName)...)
}
func GetFeedStatePrefixKey(state servicetypes.RequestContextState) []byte {
if state == servicetypes.RUNNING {
return PrefixFeedRunningStateKey
}
return PrefixFeedPauseStateKey
}