-
Notifications
You must be signed in to change notification settings - Fork 1
/
whitelist.go
92 lines (81 loc) · 2.87 KB
/
whitelist.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
package contract
import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/Timwood0x10/sei-chain/utils"
"github.com/Timwood0x10/sei-chain/x/dex/keeper"
"github.com/Timwood0x10/sei-chain/x/dex/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var DexWhitelistedKeys = []string{
types.LongBookKey,
types.ShortBookKey,
types.OrderKey,
types.AccountActiveOrdersKey,
types.CancelKey,
types.TwapKey,
types.PriceKey,
types.SettlementEntryKey,
types.NextOrderIDKey,
types.MatchResultKey,
types.LongOrderCountKey,
types.ShortOrderCountKey,
keeper.ContractPrefixKey,
}
var DexMemWhitelistedKeys = []string{
types.MemOrderKey,
types.MemDepositKey,
types.MemCancelKey,
}
var WasmWhitelistedKeys = []string{
string(wasmtypes.ContractStorePrefix),
}
func GetWhitelistMap(contractAddr string) map[string][]string {
res := map[string][]string{}
res[storetypes.NewKVStoreKey(types.StoreKey).Name()] = GetDexWhitelistedPrefixes(contractAddr)
res[storetypes.NewKVStoreKey(wasmtypes.StoreKey).Name()] = GetWasmWhitelistedPrefixes(contractAddr)
res[storetypes.NewKVStoreKey(types.MemStoreKey).Name()] = GetDexMemWhitelistedPrefixes(contractAddr)
return res
}
func GetPerPairWhitelistMap(contractAddr string, pair types.Pair) map[string][]string {
res := map[string][]string{}
res[storetypes.NewKVStoreKey(types.StoreKey).Name()] = GetDexPerPairWhitelistedPrefixes(contractAddr, pair)
res[storetypes.NewKVStoreKey(types.MemStoreKey).Name()] = GetDexMemPerPairWhitelistedPrefixes(contractAddr, pair)
return res
}
func GetDexWhitelistedPrefixes(contractAddr string) []string {
return utils.Map(DexWhitelistedKeys, func(key string) string {
return string(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
))
})
}
func GetDexMemWhitelistedPrefixes(contractAddr string) []string {
return utils.Map(DexMemWhitelistedKeys, func(key string) string {
return string(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
))
})
}
func GetWasmWhitelistedPrefixes(contractAddr string) []string {
addr, _ := sdk.AccAddressFromBech32(contractAddr)
return utils.Map(WasmWhitelistedKeys, func(key string) string {
return string(append(
[]byte(key), addr...,
))
})
}
func GetDexPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string {
return utils.Map(DexWhitelistedKeys, func(key string) string {
return string(append(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
), types.PairPrefix(pair.PriceDenom, pair.AssetDenom)...))
})
}
func GetDexMemPerPairWhitelistedPrefixes(contractAddr string, pair types.Pair) []string {
return utils.Map(DexMemWhitelistedKeys, func(key string) string {
return string(append(append(
types.KeyPrefix(key), types.AddressKeyPrefix(contractAddr)...,
), types.PairPrefix(pair.PriceDenom, pair.AssetDenom)...))
})
}