/
keys.go
129 lines (109 loc) · 4.3 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
package types
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
// ModuleName is the name of the dex module
ModuleName = "dex"
// DefaultParamspace defines default param space
DefaultParamspace = ModuleName
// DefaultCodespace defines default code space
DefaultCodespace = ModuleName
// QuerierRoute is the querier route for the dex module
QuerierRoute = ModuleName
// RouterKey is the msg router key for the dex module
RouterKey = ModuleName
// StoreKey is the string store representation
StoreKey = ModuleName
// TokenPairStoreKey is the token pair store key
TokenPairStoreKey = "token_pair"
// QueryProductsDelisting defines delisting query route path
QueryProductsDelisting = "products_delisting"
// QueryProducts defines products query route path
QueryProducts = "products"
// QueryDeposits defines deposits query route path
QueryDeposits = "deposits"
// QueryMatchOrder defines match-order query route path
QueryMatchOrder = "match-order"
// QueryParameters defines QueryParameters = "params" query route path
QueryParameters = "params"
// QueryOperator defines operator query route path
QueryOperator = "operator"
// QueryOperators defines operators query route path
QueryOperators = "operators"
)
var (
lenTime = len(sdk.FormatTimeBytes(time.Now()))
// TokenPairKey is the store key for token pair
TokenPairKey = []byte{0x01}
// MaxTokenPairIDKey is the store key for token pair max ID
MaxTokenPairIDKey = []byte{0x02}
// TokenPairLockKeyPrefix is the store key for token pair prefix
TokenPairLockKeyPrefix = []byte{0x03}
// DEXOperatorKeyPrefix is the store key prefix for DEXOperator
DEXOperatorKeyPrefix = []byte{0x04}
// DEXOperatorTokenPairCntPrefix is the store key prefix for DEXOperator's tokenpair count
DEXOperatorTokenPairCntPrefix = []byte{0x05}
// WithdrawAddressKeyPrefix is the store key for withdraw address
WithdrawAddressKeyPrefix = []byte{0x53}
// WithdrawTimeKeyPrefix is the store key for withdraw time
WithdrawTimeKeyPrefix = []byte{0x54}
// UserTokenPairKeyPrefix is the store key for user token pair num
UserTokenPairKeyPrefix = []byte{0x06}
//the prefix of the confirm ownership key
PrefixConfirmOwnershipKey = []byte{0x07}
)
// GetUserTokenPairAddressPrefix returns token pair address prefix key
func GetUserTokenPairAddressPrefix(owner sdk.AccAddress) []byte {
return append(UserTokenPairKeyPrefix, owner.Bytes()...)
}
// GetUserTokenPairAddress returns token pair address key
func GetUserTokenPairAddress(owner sdk.AccAddress, assertPair string) []byte {
return append(GetUserTokenPairAddressPrefix(owner), []byte(assertPair)...)
}
// GetTokenPairAddress returns store key of token pair
func GetTokenPairAddress(key string) []byte {
return append(TokenPairKey, []byte(key)...)
}
// GetWithdrawAddressKey returns key of withdraw address
func GetWithdrawAddressKey(addr sdk.AccAddress) []byte {
return append(WithdrawAddressKeyPrefix, addr.Bytes()...)
}
// GetWithdrawTimeKey returns key of withdraw time
func GetWithdrawTimeKey(completeTime time.Time) []byte {
bz := sdk.FormatTimeBytes(completeTime)
return append(WithdrawTimeKeyPrefix, bz...)
}
// GetWithdrawTimeAddressKey returns withdraw time address key
func GetWithdrawTimeAddressKey(completeTime time.Time, addr sdk.AccAddress) []byte {
return append(GetWithdrawTimeKey(completeTime), addr.Bytes()...)
}
//SplitWithdrawTimeKey splits the key and returns the complete time and address
func SplitWithdrawTimeKey(key []byte) (time.Time, sdk.AccAddress) {
if len(key[1:]) != lenTime+sdk.AddrLen {
panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key[1:]), lenTime+sdk.AddrLen))
}
endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime])
if err != nil {
panic(err)
}
delAddr := sdk.AccAddress(key[1+lenTime:])
return endTime, delAddr
}
// GetLockProductKey returns key of token pair
func GetLockProductKey(product string) []byte {
return append(TokenPairLockKeyPrefix, []byte(product)...)
}
// GetKey returns keys between index 1 to the end
func GetKey(it sdk.Iterator) string {
return string(it.Key()[1:])
}
// GetOperatorAddressKey returns key of operator address
func GetOperatorAddressKey(addr sdk.AccAddress) []byte {
return append(DEXOperatorKeyPrefix, addr.Bytes()...)
}
func GetConfirmOwnershipKey(product string) []byte {
return append(PrefixConfirmOwnershipKey, []byte(product)...)
}