-
Notifications
You must be signed in to change notification settings - Fork 6
/
key_claim.go
39 lines (29 loc) · 1.66 KB
/
key_claim.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
package types
import "encoding/binary"
var _ binary.ByteOrder
const (
// ClaimPrimaryKeyPrefix is the prefix to retrieve the entire Claim object (the primary store)
// TODO_TECHDEBT: consider renaming to ClaimSessionIDPrefix.
ClaimPrimaryKeyPrefix = "Claim/primary_key/"
// ClaimSupplierAddressPrefix is the key to retrieve a Claim's Primary Key from the Address index
ClaimSupplierAddressPrefix = "Claim/address/"
// ClaimSessionEndHeightPrefix is the key to retrieve a Claim's Primary Key from the Height index
ClaimSessionEndHeightPrefix = "Claim/height/"
)
// ClaimPrimaryKey returns the primary store key used to retrieve a Claim by creating a composite key of the sessionId and supplierAddr.
func ClaimPrimaryKey(sessionId, supplierAddr string) []byte {
// We are guaranteed uniqueness of the primary key if it's a composite of the (sessionId, supplierAddr)
// because every supplier can only have one claim per session.
return KeyComposite([]byte(sessionId), []byte(supplierAddr))
}
// ClaimSupplierAddressKey returns the key used to iterate through claims given a supplier Address.
func ClaimSupplierAddressKey(supplierAddr string, primaryKey []byte) []byte {
return KeyComposite([]byte(supplierAddr), primaryKey)
}
// ClaimSupplierEndSessionHeightKey returns the key used to iterate through claims given a session end height.
func ClaimSupplierEndSessionHeightKey(sessionEndHeight int64, primaryKey []byte) []byte {
heightBz := make([]byte, 8)
binary.BigEndian.PutUint64(heightBz, uint64(sessionEndHeight))
return KeyComposite(heightBz, primaryKey)
}
// TODO_TECHDEBT(@olshanks): add helpers for composing query-side key prefixes & document key/value prefix design.