-
Notifications
You must be signed in to change notification settings - Fork 30
/
keys.go
230 lines (186 loc) · 10.7 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the service module
ModuleName = "service"
// StoreKey is the string store representation
StoreKey string = ModuleName
// QuerierRoute is the querier route for the service module
QuerierRoute string = ModuleName
// RouterKey is the msg router key for the service module
RouterKey string = ModuleName
// DefaultParamspace is the default name for parameter store
DefaultParamspace = ModuleName
// DepositAccName is the root string for the service deposit account address
DepositAccName = "service_deposit_account"
// RequestAccName is the root string for the service request account address
RequestAccName = "service_request_account"
// FeeCollectorName is the root string for the service fee collector address used for testing
FeeCollectorName = "service_fee_collector"
)
var (
// Separator for string key
Delimiter = []byte{0x00}
// Keys for store prefixes
ServiceDefinitionKey = []byte{0x01} // prefix for service definition
ServiceBindingKey = []byte{0x02} // prefix for service binding
OwnerServiceBindingKey = []byte{0x03} // prefix for owner service binding
OwnerKey = []byte{0x04} // prefix for the owner of a provider
OwnerProviderKey = []byte{0x05} // prefix for the provider with an owner
PricingKey = []byte{0x06} // prefix for pricing
WithdrawAddrKey = []byte{0x07} // prefix for withdrawal address
RequestContextKey = []byte{0x08} // prefix for request context
ExpiredRequestBatchKey = []byte{0x09} // prefix for expired request batch
NewRequestBatchKey = []byte{0x10} // prefix for new request batch
ExpiredRequestBatchHeightKey = []byte{0x11} // prefix for expired request batch height
NewRequestBatchHeightKey = []byte{0x12} // prefix for new request batch height
RequestKey = []byte{0x13} // prefix for request
ActiveRequestKey = []byte{0x14} // prefix for active request
ActiveRequestByIDKey = []byte{0x15} // prefix for active requests by ID
ResponseKey = []byte{0x16} // prefix for response
RequestVolumeKey = []byte{0x17} // prefix for request volume
EarnedFeesKey = []byte{0x18} // prefix for provider earned fees
OwnerEarnedFeesKey = []byte{0x19} // prefix for owner earned fees
InternalCounterKey = []byte{0x20} // prefix for internal counter key
)
// GetServiceDefinitionKey gets the key for the service definition with the specified service name
// VALUE: service/ServiceDefinition
func GetServiceDefinitionKey(serviceName string) []byte {
return append(ServiceDefinitionKey, []byte(serviceName)...)
}
// GetServiceBindingKey gets the key for the service binding with the specified service name and provider
// VALUE: service/ServiceBinding
func GetServiceBindingKey(serviceName string, provider sdk.AccAddress) []byte {
return append(ServiceBindingKey, getStringsKey([]string{serviceName, provider.String()})...)
}
// GetOwnerServiceBindingKey gets the key for the service binding with the specified owner
// VALUE: []byte{}
func GetOwnerServiceBindingKey(owner sdk.AccAddress, serviceName string, provider sdk.AccAddress) []byte {
return append(append(append(append(OwnerServiceBindingKey, owner.Bytes()...), []byte(serviceName)...), Delimiter...), provider.Bytes()...)
}
// GetOwnerKey gets the key for the specified provider
// VALUE: sdk.AccAddress
func GetOwnerKey(provider sdk.AccAddress) []byte {
return append(OwnerKey, provider.Bytes()...)
}
// GetOwnerProviderKey gets the key for the specified owner and provider
// VALUE: []byte{}
func GetOwnerProviderKey(owner, provider sdk.AccAddress) []byte {
return append(append(OwnerProviderKey, owner.Bytes()...), provider.Bytes()...)
}
// GetPricingKey gets the key for the pricing of the specified binding
// VALUE: service/Pricing
func GetPricingKey(serviceName string, provider sdk.AccAddress) []byte {
return append(PricingKey, getStringsKey([]string{serviceName, provider.String()})...)
}
// GetWithdrawAddrKey gets the key for the withdrawal address of the specified provider
// VALUE: withdrawal address ([]byte)
func GetWithdrawAddrKey(provider sdk.AccAddress) []byte {
return append(WithdrawAddrKey, provider.Bytes()...)
}
// GetBindingsSubspace gets the key prefix for iterating through all bindings of the specified service name
func GetBindingsSubspace(serviceName string) []byte {
return append(append(ServiceBindingKey, []byte(serviceName)...), Delimiter...)
}
// GetOwnerBindingsSubspace gets the key prefix for iterating through all bindings of the specified service name and owner
func GetOwnerBindingsSubspace(owner sdk.AccAddress, serviceName string) []byte {
return append(append(append(OwnerServiceBindingKey, owner.Bytes()...), []byte(serviceName)...), Delimiter...)
}
// GetOwnerProvidersSubspace gets the key prefix for iterating through providers of the specified owner
func GetOwnerProvidersSubspace(owner sdk.AccAddress) []byte {
return append(OwnerProviderKey, owner.Bytes()...)
}
// GetRequestContextKey returns the key for the request context with the specified ID
func GetRequestContextKey(requestContextID []byte) []byte {
return append(RequestContextKey, requestContextID...)
}
// GetExpiredRequestBatchKey returns the key for the request batch expiration of the specified request context
func GetExpiredRequestBatchKey(requestContextID []byte, batchExpirationHeight int64) []byte {
reqBatchExpiration := append(sdk.Uint64ToBigEndian(uint64(batchExpirationHeight)), requestContextID...)
return append(ExpiredRequestBatchKey, reqBatchExpiration...)
}
// GetNewRequestBatchKey returns the key for the new batch request of the specified request context in the given height
func GetNewRequestBatchKey(requestContextID []byte, requestBatchHeight int64) []byte {
newBatchRequest := append(sdk.Uint64ToBigEndian(uint64(requestBatchHeight)), requestContextID...)
return append(NewRequestBatchKey, newBatchRequest...)
}
// GetExpiredRequestBatchSubspace returns the key prefix for iterating through the expired request batch queue in the specified height
func GetExpiredRequestBatchSubspace(batchExpirationHeight int64) []byte {
return append(ExpiredRequestBatchKey, sdk.Uint64ToBigEndian(uint64(batchExpirationHeight))...)
}
// GetNewRequestBatchSubspace returns the key prefix for iterating through the new request batch queue in the specified height
func GetNewRequestBatchSubspace(requestBatchHeight int64) []byte {
return append(NewRequestBatchKey, sdk.Uint64ToBigEndian(uint64(requestBatchHeight))...)
}
// GetExpiredRequestBatchHeightKey returns the key for the current request batch expiration height of the specified request context
func GetExpiredRequestBatchHeightKey(requestContextID []byte) []byte {
return append(ExpiredRequestBatchHeightKey, requestContextID...)
}
// GetNewRequestBatchHeightKey returns the key for the new request batch height of the specified request context
func GetNewRequestBatchHeightKey(requestContextID []byte) []byte {
return append(NewRequestBatchHeightKey, requestContextID...)
}
// GetRequestKey returns the key for the request with the specified request ID
func GetRequestKey(requestID []byte) []byte {
return append(RequestKey, requestID...)
}
// GetRequestSubspaceByReqCtx returns the key prefix for iterating through the requests of the specified request context
func GetRequestSubspaceByReqCtx(requestContextID []byte, batchCounter uint64) []byte {
return append(append(RequestKey, requestContextID...), sdk.Uint64ToBigEndian(batchCounter)...)
}
// GetActiveRequestKey returns the key for the active request with the specified request ID in the given height
func GetActiveRequestKey(serviceName string, provider sdk.AccAddress, expirationHeight int64, requestID []byte) []byte {
activeRequest := append(append(append(getStringsKey([]string{serviceName, provider.String()}), Delimiter...), sdk.Uint64ToBigEndian(uint64(expirationHeight))...), requestID...)
return append(ActiveRequestKey, activeRequest...)
}
// GetActiveRequestSubspace returns the key prefix for iterating through the active requests for the specified provider
func GetActiveRequestSubspace(serviceName string, provider sdk.AccAddress) []byte {
return append(append(ActiveRequestKey, getStringsKey([]string{serviceName, provider.String()})...), Delimiter...)
}
// GetActiveRequestKeyByID returns the key for the active request with the specified request ID
func GetActiveRequestKeyByID(requestID []byte) []byte {
return append(ActiveRequestByIDKey, requestID...)
}
// GetActiveRequestSubspaceByReqCtx returns the key prefix for iterating through the active requests for the specified request context
func GetActiveRequestSubspaceByReqCtx(requestContextID []byte, batchCounter uint64) []byte {
return append(append(ActiveRequestByIDKey, requestContextID...), sdk.Uint64ToBigEndian(batchCounter)...)
}
// GetRequestVolumeKey returns the key for the request volume for the specified consumer and binding
func GetRequestVolumeKey(consumer sdk.AccAddress, serviceName string, provider sdk.AccAddress) []byte {
return append(RequestVolumeKey, getStringsKey([]string{consumer.String(), serviceName, provider.String()})...)
}
// GetResponseKey returns the key for the response for the given request ID
func GetResponseKey(requestID []byte) []byte {
return append(ResponseKey, requestID...)
}
// GetResponseSubspaceByReqCtx returns the key prefix for iterating throuth responses for the specified request context and batch counter
func GetResponseSubspaceByReqCtx(requestContextID []byte, batchCounter uint64) []byte {
return append(append(ResponseKey, requestContextID...), sdk.Uint64ToBigEndian(batchCounter)...)
}
// GetEarnedFeesKey gets the key for the earned fees of the specified provider and denom
func GetEarnedFeesKey(provider sdk.AccAddress, denom string) []byte {
return append(append(EarnedFeesKey, provider.Bytes()...), []byte(denom)...)
}
// GetEarnedFeesSubspace gets the subspace for the earned fees of the specified provider
func GetEarnedFeesSubspace(provider sdk.AccAddress) []byte {
return append(EarnedFeesKey, provider.Bytes()...)
}
// GetOwnerEarnedFeesKey returns the key for the earned fees of the specified owner and denom
func GetOwnerEarnedFeesKey(owner sdk.AccAddress, denom string) []byte {
return append(append(OwnerEarnedFeesKey, owner.Bytes()...), []byte(denom)...)
}
// GetOwnerEarnedFeesSubspace gets the subspace for the earned fees of the specified owner
func GetOwnerEarnedFeesSubspace(owner sdk.AccAddress) []byte {
return append(OwnerEarnedFeesKey, owner.Bytes()...)
}
func getStringsKey(ss []string) (result []byte) {
for _, s := range ss {
result = append(append(result, []byte(s)...), Delimiter...)
}
if len(result) > 0 {
return result[0 : len(result)-1]
}
return
}