github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/dex/types/keys.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "time" 6 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 ) 9 10 const ( 11 // ModuleName is the name of the dex module 12 ModuleName = "dex" 13 // DefaultParamspace defines default param space 14 DefaultParamspace = ModuleName 15 // DefaultCodespace defines default code space 16 DefaultCodespace = ModuleName 17 // QuerierRoute is the querier route for the dex module 18 QuerierRoute = ModuleName 19 // RouterKey is the msg router key for the dex module 20 RouterKey = ModuleName 21 // StoreKey is the string store representation 22 StoreKey = ModuleName 23 // TokenPairStoreKey is the token pair store key 24 TokenPairStoreKey = "token_pair" 25 26 // QueryProductsDelisting defines delisting query route path 27 QueryProductsDelisting = "products_delisting" 28 // QueryProducts defines products query route path 29 QueryProducts = "products" 30 // QueryDeposits defines deposits query route path 31 QueryDeposits = "deposits" 32 // QueryMatchOrder defines match-order query route path 33 QueryMatchOrder = "match-order" 34 // QueryParameters defines QueryParameters = "params" query route path 35 QueryParameters = "params" 36 // QueryOperator defines operator query route path 37 QueryOperator = "operator" 38 // QueryOperators defines operators query route path 39 QueryOperators = "operators" 40 ) 41 42 var ( 43 lenTime = len(sdk.FormatTimeBytes(time.Now())) 44 45 // TokenPairKey is the store key for token pair 46 TokenPairKey = []byte{0x01} 47 // MaxTokenPairIDKey is the store key for token pair max ID 48 MaxTokenPairIDKey = []byte{0x02} 49 // TokenPairLockKeyPrefix is the store key for token pair prefix 50 TokenPairLockKeyPrefix = []byte{0x03} 51 52 // DEXOperatorKeyPrefix is the store key prefix for DEXOperator 53 DEXOperatorKeyPrefix = []byte{0x04} 54 55 // DEXOperatorTokenPairCntPrefix is the store key prefix for DEXOperator's tokenpair count 56 DEXOperatorTokenPairCntPrefix = []byte{0x05} 57 58 // WithdrawAddressKeyPrefix is the store key for withdraw address 59 WithdrawAddressKeyPrefix = []byte{0x53} 60 // WithdrawTimeKeyPrefix is the store key for withdraw time 61 WithdrawTimeKeyPrefix = []byte{0x54} 62 // UserTokenPairKeyPrefix is the store key for user token pair num 63 UserTokenPairKeyPrefix = []byte{0x06} 64 //the prefix of the confirm ownership key 65 PrefixConfirmOwnershipKey = []byte{0x07} 66 ) 67 68 // GetUserTokenPairAddressPrefix returns token pair address prefix key 69 func GetUserTokenPairAddressPrefix(owner sdk.AccAddress) []byte { 70 return append(UserTokenPairKeyPrefix, owner.Bytes()...) 71 } 72 73 // GetUserTokenPairAddress returns token pair address key 74 func GetUserTokenPairAddress(owner sdk.AccAddress, assertPair string) []byte { 75 return append(GetUserTokenPairAddressPrefix(owner), []byte(assertPair)...) 76 } 77 78 // GetTokenPairAddress returns store key of token pair 79 func GetTokenPairAddress(key string) []byte { 80 return append(TokenPairKey, []byte(key)...) 81 } 82 83 // GetWithdrawAddressKey returns key of withdraw address 84 func GetWithdrawAddressKey(addr sdk.AccAddress) []byte { 85 return append(WithdrawAddressKeyPrefix, addr.Bytes()...) 86 } 87 88 // GetWithdrawTimeKey returns key of withdraw time 89 func GetWithdrawTimeKey(completeTime time.Time) []byte { 90 bz := sdk.FormatTimeBytes(completeTime) 91 return append(WithdrawTimeKeyPrefix, bz...) 92 } 93 94 // GetWithdrawTimeAddressKey returns withdraw time address key 95 func GetWithdrawTimeAddressKey(completeTime time.Time, addr sdk.AccAddress) []byte { 96 return append(GetWithdrawTimeKey(completeTime), addr.Bytes()...) 97 } 98 99 // SplitWithdrawTimeKey splits the key and returns the complete time and address 100 func SplitWithdrawTimeKey(key []byte) (time.Time, sdk.AccAddress) { 101 if len(key[1:]) != lenTime+sdk.AddrLen { 102 panic(fmt.Sprintf("unexpected key length (%d ≠ %d)", len(key[1:]), lenTime+sdk.AddrLen)) 103 } 104 endTime, err := sdk.ParseTimeBytes(key[1 : 1+lenTime]) 105 if err != nil { 106 panic(err) 107 } 108 delAddr := sdk.AccAddress(key[1+lenTime:]) 109 return endTime, delAddr 110 } 111 112 // GetLockProductKey returns key of token pair 113 func GetLockProductKey(product string) []byte { 114 return append(TokenPairLockKeyPrefix, []byte(product)...) 115 } 116 117 // GetKey returns keys between index 1 to the end 118 func GetKey(it sdk.Iterator) string { 119 return string(it.Key()[1:]) 120 } 121 122 // GetOperatorAddressKey returns key of operator address 123 func GetOperatorAddressKey(addr sdk.AccAddress) []byte { 124 return append(DEXOperatorKeyPrefix, addr.Bytes()...) 125 } 126 127 func GetConfirmOwnershipKey(product string) []byte { 128 return append(PrefixConfirmOwnershipKey, []byte(product)...) 129 }