/
blacklisted.go
49 lines (39 loc) · 1.63 KB
/
blacklisted.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
package keeper
import (
"github.com/circlefin/noble-fiattokenfactory/x/fiattokenfactory/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SetBlacklisted set a specific blacklisted in the store from its index
func (k Keeper) SetBlacklisted(ctx sdk.Context, blacklisted types.Blacklisted) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlacklistedKeyPrefix))
b := k.cdc.MustMarshal(&blacklisted)
store.Set(types.BlacklistedKey(blacklisted.AddressBz), b)
}
// GetBlacklisted returns a blacklisted from its index
func (k Keeper) GetBlacklisted(ctx sdk.Context, addressBz []byte) (val types.Blacklisted, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlacklistedKeyPrefix))
b := store.Get(types.BlacklistedKey(addressBz))
if b == nil {
return val, false
}
k.cdc.MustUnmarshal(b, &val)
return val, true
}
// RemoveBlacklisted removes a blacklisted from the store
func (k Keeper) RemoveBlacklisted(ctx sdk.Context, addressBz []byte) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlacklistedKeyPrefix))
store.Delete(types.BlacklistedKey(addressBz))
}
// GetAllBlacklisted returns all blacklisted
func (k Keeper) GetAllBlacklisted(ctx sdk.Context) (list []types.Blacklisted) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BlacklistedKeyPrefix))
iterator := sdk.KVStorePrefixIterator(store, []byte{})
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var val types.Blacklisted
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}
return
}