-
Notifications
You must be signed in to change notification settings - Fork 58
/
blacklist.go
52 lines (42 loc) · 1.68 KB
/
blacklist.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
package keeper
import (
"cosmossdk.io/store/prefix"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-apps/modules/rate-limiting/v8/types"
)
// Adds a denom to a blacklist to prevent all IBC transfers with this denom
func (k Keeper) AddDenomToBlacklist(ctx sdk.Context, denom string) {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.DenomBlacklistKeyPrefix)
key := types.KeyPrefix(denom)
store.Set(key, []byte{1})
}
// Removes a denom from a blacklist to re-enable IBC transfers for that denom
func (k Keeper) RemoveDenomFromBlacklist(ctx sdk.Context, denom string) {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.DenomBlacklistKeyPrefix)
key := types.KeyPrefix(denom)
store.Delete(key)
}
// Check if a denom is currently blacklisted
func (k Keeper) IsDenomBlacklisted(ctx sdk.Context, denom string) bool {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.DenomBlacklistKeyPrefix)
key := types.KeyPrefix(denom)
value := store.Get(key)
found := len(value) != 0
return found
}
// Get all the blacklisted denoms
func (k Keeper) GetAllBlacklistedDenoms(ctx sdk.Context) []string {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.DenomBlacklistKeyPrefix)
iterator := store.Iterator(nil, nil)
defer iterator.Close()
allBlacklistedDenoms := []string{}
for ; iterator.Valid(); iterator.Next() {
allBlacklistedDenoms = append(allBlacklistedDenoms, string(iterator.Key()))
}
return allBlacklistedDenoms
}