/
keys.go
55 lines (44 loc) · 1.75 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
package types
import "encoding/binary"
const (
ModuleName = "staketia"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the routing key
RouterKey = ModuleName
// Module Account for Fee Collection
FeeAddress = "staketia_fee_address"
)
var (
// Prefix store keys
HostZoneKey = []byte("host-zone")
DelegationRecordsKeyPrefix = []byte("delegation-records-active")
DelegationRecordsArchiveKeyPrefix = []byte("delegation-records-archive")
UnbondingRecordsKeyPrefix = []byte("unbonding-records-active")
UnbondingRecordsArchiveKeyPrefix = []byte("unbonding-records-archive")
RedemptionRecordsKeyPrefix = []byte("redemption-records")
SlashRecordsKeyPrefix = []byte("slash-records")
SlashRecordStoreKeyPrefix = []byte("slash-record-id")
TransferInProgressRecordIdKeyPrefix = []byte("transfer-in-progress")
ChannelIdBufferFixedLength int = 16
)
// Serializes an string to use as a prefix when needed
func StringKey(p string) []byte {
return []byte(p)
}
// Serializes an int to use as a prefix when needed
func IntKey(i uint64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, i)
return bz
}
// Builds the redemption record key from an unbonding record ID and address
func RedemptionRecordKey(unbondingRecordId uint64, redeemerAddress string) []byte {
return append(IntKey(unbondingRecordId), StringKey(redeemerAddress)...)
}
// Builds the transfer-in-progress record key from the channelId and sequence number
func TransferInProgressRecordKey(channelId string, sequence uint64) []byte {
channelIdBz := make([]byte, ChannelIdBufferFixedLength)
copy(channelIdBz[:], channelId)
return append(channelIdBz, IntKey(sequence)...)
}