-
Notifications
You must be signed in to change notification settings - Fork 38
/
keys.go
68 lines (57 loc) · 1.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
package swap
import (
"encoding/binary"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
Int64Size = 8
)
var (
HashKey = []byte{0x01}
SwapCreatorQueueKey = []byte{0x02}
SwapRecipientQueueKey = []byte{0x03}
SwapCloseTimeKey = []byte{0x04}
SwapIndexKey = []byte{0x05}
)
func BuildHashKey(randomNumberHash []byte) []byte {
return append(HashKey, randomNumberHash...)
}
func BuildSwapCreatorKey(addr sdk.AccAddress, index int64) []byte {
// prefix + addr + index
key := make([]byte, 1+sdk.AddrLen+Int64Size)
copy(key[:1], SwapCreatorQueueKey)
copy(key[1:1+sdk.AddrLen], addr)
binary.BigEndian.PutUint64(key[1+sdk.AddrLen:], uint64(index))
return key
}
func BuildSwapCreatorQueueKey(addr sdk.AccAddress) []byte {
key := make([]byte, 1+sdk.AddrLen)
copy(key[:1], SwapCreatorQueueKey)
copy(key[1:1+sdk.AddrLen], addr)
return key
}
func BuildSwapRecipientKey(addr sdk.AccAddress, index int64) []byte {
// prefix + addr + index
key := make([]byte, 1+sdk.AddrLen+Int64Size)
copy(key[:1], SwapRecipientQueueKey)
copy(key[1:1+sdk.AddrLen], addr)
binary.BigEndian.PutUint64(key[1+sdk.AddrLen:], uint64(index))
return key
}
func BuildSwapRecipientQueueKey(addr sdk.AccAddress) []byte {
key := make([]byte, 1+sdk.AddrLen)
copy(key[:1], SwapRecipientQueueKey)
copy(key[1:1+sdk.AddrLen], addr)
return key
}
func BuildCloseTimeKey(unixTime int64, index int64) []byte {
// prefix + unixTime + index
key := make([]byte, 1+Int64Size+Int64Size)
copy(key[:1], SwapCloseTimeKey)
binary.BigEndian.PutUint64(key[1:1+Int64Size], uint64(unixTime))
binary.BigEndian.PutUint64(key[1+Int64Size:], uint64(index))
return key
}
func BuildCloseTimeQueueKey() []byte {
return SwapCloseTimeKey
}