-
Notifications
You must be signed in to change notification settings - Fork 30
/
inactive.go
53 lines (44 loc) · 1.87 KB
/
inactive.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
package keeper
import (
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/bankplus/types"
)
// Keys for bankplus store but this prefix must not be overlap with bank key prefix.
var inactiveAddrsKeyPrefix = []byte{0xa0}
// inactiveAddrKey key of a specific inactiveAddr from store
func inactiveAddrKey(addr sdk.AccAddress) []byte {
return append(inactiveAddrsKeyPrefix, addr.Bytes()...)
}
// isStoredInactiveAddr checks if the address is stored or not as blocked address
//
//nolint:deadcode,unused
func (keeper BaseKeeper) isStoredInactiveAddr(ctx sdk.Context, address sdk.AccAddress) bool {
store := ctx.KVStore(keeper.storeKey)
bz := store.Get(inactiveAddrKey(address))
return bz != nil
}
// addToInactiveAddr adds a blocked address to the store.
func (keeper BaseKeeper) addToInactiveAddr(ctx sdk.Context, address sdk.AccAddress) {
store := ctx.KVStore(keeper.storeKey)
blockedCAddr := types.InactiveAddr{Address: address.String()}
bz := keeper.cdc.MustMarshal(&blockedCAddr)
store.Set(inactiveAddrKey(address), bz)
}
// deleteFromInactiveAddr deletes blocked address from store
func (keeper BaseKeeper) deleteFromInactiveAddr(ctx sdk.Context, address sdk.AccAddress) {
store := ctx.KVStore(keeper.storeKey)
store.Delete(inactiveAddrKey(address))
}
// loadAllInactiveAddrs loads all blocked address and set to `inactiveAddr`.
// This function is executed when the app is initiated and save all inactive address in caches
// in order to prevent to query to store in every time to send
func (keeper BaseKeeper) loadAllInactiveAddrs(ctx sdk.Context) {
store := ctx.KVStore(keeper.storeKey)
iterator := sdk.KVStorePrefixIterator(store, inactiveAddrsKeyPrefix)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
var bAddr types.InactiveAddr
keeper.cdc.MustUnmarshal(iterator.Value(), &bAddr)
keeper.inactiveAddrs[bAddr.Address] = true
}
}