/
keys.go
77 lines (59 loc) · 2.33 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
package types
import "encoding/binary"
const (
// module name
ModuleName = "beacon"
// StoreKey to be used when creating the KVStore
StoreKey = ModuleName
DefaultParamspace = ModuleName
// QuerierRoute is the querier route for the BEACON store.
QuerierRoute = StoreKey
)
var (
// key used to store the current highest BEACON ID
HighestBeaconIDKey = []byte{0x20}
// RegisteredBeaconPrefix prefix for registered BEACON store
RegisteredBeaconPrefix = []byte{0x01}
// RecordedBeaconTimestampPrefix prefix for BEACON Timestamps store
RecordedBeaconTimestampPrefix = []byte{0x02}
// BeaconStorageLimitPrefix prefix for BEACON storage limit store
BeaconStorageLimitPrefix = []byte{0x03}
)
// GetBeaconIDBytes returns the byte representation of the BeaconID
// used for getting the highest Beacon ID from the database
func GetBeaconIDBytes(beaconID uint64) (beaconIDBz []byte) {
beaconIDBz = make([]byte, 8)
binary.BigEndian.PutUint64(beaconIDBz, beaconID)
return
}
// GetBeaconIDFromBytes returns BeaconID in uint64 format from a byte array
// used for getting the highest Beacon ID from the database
func GetBeaconIDFromBytes(bz []byte) (beaconID uint64) {
return binary.BigEndian.Uint64(bz)
}
// BeaconKey gets a specific purchase order ID key for use in the store
func BeaconKey(beaconID uint64) []byte {
return append(RegisteredBeaconPrefix, GetBeaconIDBytes(beaconID)...)
}
// BeaconAllTimestampsKey gets the key for a specific BEACON's timestamps
func BeaconAllTimestampsKey(beaconID uint64) []byte {
return append(RecordedBeaconTimestampPrefix, GetBeaconIDBytes(beaconID)...)
}
// BeaconTimestampKey gets the key for a single BEACON's specific timestamp ID
func BeaconTimestampKey(beaconID, timestampID uint64) []byte {
blocksKey := BeaconAllTimestampsKey(beaconID)
timestampIdBz := GetTimestampIDBytes(timestampID)
return append(blocksKey, timestampIdBz...)
}
func GetTimestampIDBytes(timestampID uint64) (timestampIDBz []byte) {
timestampIDBz = make([]byte, 8)
binary.BigEndian.PutUint64(timestampIDBz, timestampID)
return
}
func GetTimestampIDFromBytes(bz []byte) (timestampID uint64) {
return binary.BigEndian.Uint64(bz)
}
// BeaconStorageLimitKey gets the key for a single BEACON's specific storage limit
func BeaconStorageLimitKey(beaconID uint64) []byte {
return append(BeaconStorageLimitPrefix, GetBeaconIDBytes(beaconID)...)
}