-
Notifications
You must be signed in to change notification settings - Fork 44
/
keys.go
62 lines (47 loc) · 1.43 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
package types
import "encoding/binary"
const (
// ModuleName defines the module name
ModuleName = "perpetual"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_perpetual"
// ParamsKey is the prefix for parameters of perpetual module
ParamsKey = "perpetual_params"
)
const MaxPageLimit = 100
const (
InfinitePriceString = "infinite"
TakeProfitPriceDefault = "10000000000000000000000000000000000000000" // 10^40
)
var (
MTPPrefix = []byte{0x01}
MTPCountPrefix = []byte{0x02}
OpenMTPCountPrefix = []byte{0x04}
WhitelistPrefix = []byte{0x05}
)
func KeyPrefix(p string) []byte {
return []byte(p)
}
// GetUint64Bytes returns the byte representation of the ID
func GetUint64Bytes(ID uint64) []byte {
IDBz := make([]byte, 8)
binary.BigEndian.PutUint64(IDBz, ID)
return IDBz
}
// GetUint64FromBytes returns ID in uint64 format from a byte array
func GetUint64FromBytes(bz []byte) uint64 {
return binary.BigEndian.Uint64(bz)
}
func GetWhitelistKey(address string) []byte {
return append(WhitelistPrefix, []byte(address)...)
}
func GetMTPKey(address string, id uint64) []byte {
return append(MTPPrefix, append([]byte(address), GetUint64Bytes(id)...)...)
}
func GetMTPPrefixForAddress(address string) []byte {
return append(MTPPrefix, []byte(address)...)
}