-
Notifications
You must be signed in to change notification settings - Fork 17
/
keys.go
66 lines (48 loc) · 1.47 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 "fmt"
const (
// ModuleName defines the module name
ModuleName = "beam"
// ModuleVersion defines the current module version
ModuleVersion = 3
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey is the message route for slashing
RouterKey = ModuleName
// QuerierRoute defines the module's query routing key
QuerierRoute = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_capability"
// MemStoreQueueSeparator Used to separate content in the by-height-open-beams queue
MemStoreQueueSeparator = ","
)
var (
BeamsPrefix = []byte{0x01}
OpenBeamsQueuePrefix = []byte{0x02}
ClosedBeamsQueuePrefix = []byte{0x03}
OpenBeamsByBlockQueuePrefix = []byte{0x04}
)
func StringKeyToBytes(key string) []byte {
return []byte(key)
}
func BytesKeyToString(key []byte) string {
return string(key)
}
func IntKeyToString(key int) string {
return fmt.Sprintf("%d", key)
}
func GetBeamKey(beamID string) []byte {
return append(BeamsPrefix, StringKeyToBytes(beamID)...)
}
func GetOpenBeamQueueKey(beamID string) []byte {
return append(OpenBeamsQueuePrefix, StringKeyToBytes(beamID)...)
}
func GetClosedBeamQueueKey(beamID string) []byte {
return append(ClosedBeamsQueuePrefix, StringKeyToBytes(beamID)...)
}
func GetOpenBeamsByBlockQueueKey(height int) []byte {
return append(OpenBeamsByBlockQueuePrefix, IntKeyToString(height)...)
}
func SplitBeamKey(key []byte) []byte {
return key[1:]
}