-
Notifications
You must be signed in to change notification settings - Fork 40
/
keys.go
107 lines (83 loc) · 3.13 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
98
99
100
101
102
103
104
105
106
107
package types
import (
"encoding/binary"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
hub "github.com/sentinel-official/hub/types"
)
const (
ModuleName = "subscription"
QuerierRoute = ModuleName
)
var (
ParamsSubspace = ModuleName
RouterKey = ModuleName
StoreKey = ModuleName
)
var (
EventModuleName = sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
)
)
var (
CountKey = []byte{0x00}
SubscriptionKeyPrefix = []byte{0x10}
SubscriptionForNodeKeyPrefix = []byte{0x11}
SubscriptionForPlanKeyPrefix = []byte{0x12}
ActiveSubscriptionForAddressKeyPrefix = []byte{0x20}
InactiveSubscriptionForAddressKeyPrefix = []byte{0x21}
InactiveSubscriptionAtKeyPrefix = []byte{0x30}
QuotaKeyPrefix = []byte{0x40}
)
func SubscriptionKey(id uint64) []byte {
return append(SubscriptionKeyPrefix, sdk.Uint64ToBigEndian(id)...)
}
func GetSubscriptionForNodeKeyPrefix(address hub.NodeAddress) []byte {
return append(SubscriptionForNodeKeyPrefix, address.Bytes()...)
}
func SubscriptionForNodeKey(address hub.NodeAddress, id uint64) []byte {
return append(GetSubscriptionForNodeKeyPrefix(address), sdk.Uint64ToBigEndian(id)...)
}
func GetSubscriptionForPlanKeyPrefix(id uint64) []byte {
return append(SubscriptionForPlanKeyPrefix, sdk.Uint64ToBigEndian(id)...)
}
func SubscriptionForPlanKey(p, s uint64) []byte {
return append(GetSubscriptionForPlanKeyPrefix(p), sdk.Uint64ToBigEndian(s)...)
}
func GetActiveSubscriptionForAddressKeyPrefix(address sdk.AccAddress) []byte {
return append(ActiveSubscriptionForAddressKeyPrefix, address.Bytes()...)
}
func ActiveSubscriptionForAddressKey(address sdk.AccAddress, i uint64) []byte {
return append(GetActiveSubscriptionForAddressKeyPrefix(address), sdk.Uint64ToBigEndian(i)...)
}
func GetInactiveSubscriptionForAddressKeyPrefix(address sdk.AccAddress) []byte {
return append(InactiveSubscriptionForAddressKeyPrefix, address.Bytes()...)
}
func InactiveSubscriptionForAddressKey(address sdk.AccAddress, i uint64) []byte {
return append(GetInactiveSubscriptionForAddressKeyPrefix(address), sdk.Uint64ToBigEndian(i)...)
}
func GetInactiveSubscriptionAtKeyPrefix(at time.Time) []byte {
return append(InactiveSubscriptionAtKeyPrefix, sdk.FormatTimeBytes(at)...)
}
func InactiveSubscriptionAtKey(at time.Time, id uint64) []byte {
return append(GetInactiveSubscriptionAtKeyPrefix(at), sdk.Uint64ToBigEndian(id)...)
}
func GetQuotaKeyPrefix(id uint64) []byte {
return append(QuotaKeyPrefix, sdk.Uint64ToBigEndian(id)...)
}
func QuotaKey(id uint64, address sdk.AccAddress) []byte {
return append(GetQuotaKeyPrefix(id), address.Bytes()...)
}
func IDFromSubscriptionForNodeKey(key []byte) uint64 {
return binary.BigEndian.Uint64(key[1+sdk.AddrLen:])
}
func IDFromSubscriptionForPlanKey(key []byte) uint64 {
return binary.BigEndian.Uint64(key[1+8:])
}
func IDFromStatusSubscriptionForAddressKey(key []byte) uint64 {
return binary.BigEndian.Uint64(key[1+sdk.AddrLen:])
}
func IDFromInactiveSubscriptionAtKey(key []byte) uint64 {
return binary.BigEndian.Uint64(key[1+29:])
}