-
Notifications
You must be signed in to change notification settings - Fork 58
/
whitelist.go
56 lines (46 loc) · 2.13 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
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 an pair of sender and receiver addresses to the whitelist to allow all
// IBC transfers between those addresses to skip all flow calculations
func (k Keeper) SetWhitelistedAddressPair(ctx sdk.Context, whitelist types.WhitelistedAddressPair) {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.AddressWhitelistKeyPrefix)
key := types.GetAddressWhitelistKey(whitelist.Sender, whitelist.Receiver)
value := k.cdc.MustMarshal(&whitelist)
store.Set(key, value)
}
// Removes a whitelisted address pair so that it's transfers are counted in the quota
func (k Keeper) RemoveWhitelistedAddressPair(ctx sdk.Context, sender, receiver string) {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.AddressWhitelistKeyPrefix)
key := types.GetAddressWhitelistKey(sender, receiver)
store.Delete(key)
}
// Check if a sender/receiver address pair is currently whitelisted
func (k Keeper) IsAddressPairWhitelisted(ctx sdk.Context, sender, receiver string) bool {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.AddressWhitelistKeyPrefix)
key := types.GetAddressWhitelistKey(sender, receiver)
value := store.Get(key)
found := len(value) != 0
return found
}
// Get all the whitelisted addresses
func (k Keeper) GetAllWhitelistedAddressPairs(ctx sdk.Context) []types.WhitelistedAddressPair {
adapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(adapter, types.AddressWhitelistKeyPrefix)
iterator := store.Iterator(nil, nil)
defer iterator.Close()
allWhitelistedAddresses := []types.WhitelistedAddressPair{}
for ; iterator.Valid(); iterator.Next() {
whitelist := types.WhitelistedAddressPair{}
k.cdc.MustUnmarshal(iterator.Value(), &whitelist)
allWhitelistedAddresses = append(allWhitelistedAddresses, whitelist)
}
return allWhitelistedAddresses
}