github.com/Finschia/finschia-sdk@v0.48.1/x/bankplus/keeper/inactive.go (about)

     1  package keeper
     2  
     3  import (
     4  	sdk "github.com/Finschia/finschia-sdk/types"
     5  	"github.com/Finschia/finschia-sdk/x/bankplus/types"
     6  )
     7  
     8  // Keys for bankplus store but this prefix must not be overlap with bank key prefix.
     9  var inactiveAddrsKeyPrefix = []byte{0xa0}
    10  
    11  // inactiveAddrKey key of a specific inactiveAddr from store
    12  func inactiveAddrKey(addr sdk.AccAddress) []byte {
    13  	return append(inactiveAddrsKeyPrefix, addr.Bytes()...)
    14  }
    15  
    16  // isStoredInactiveAddr checks if the address is stored or not as blocked address
    17  //
    18  //nolint:deadcode,unused
    19  func (keeper BaseKeeper) isStoredInactiveAddr(ctx sdk.Context, address sdk.AccAddress) bool {
    20  	store := ctx.KVStore(keeper.storeKey)
    21  	bz := store.Get(inactiveAddrKey(address))
    22  	return bz != nil
    23  }
    24  
    25  // addToInactiveAddr adds a blocked address to the store.
    26  func (keeper BaseKeeper) addToInactiveAddr(ctx sdk.Context, address sdk.AccAddress) {
    27  	store := ctx.KVStore(keeper.storeKey)
    28  	blockedCAddr := types.InactiveAddr{Address: address.String()}
    29  	bz := keeper.cdc.MustMarshal(&blockedCAddr)
    30  	store.Set(inactiveAddrKey(address), bz)
    31  }
    32  
    33  // deleteFromInactiveAddr deletes blocked address from store
    34  func (keeper BaseKeeper) deleteFromInactiveAddr(ctx sdk.Context, address sdk.AccAddress) {
    35  	store := ctx.KVStore(keeper.storeKey)
    36  	store.Delete(inactiveAddrKey(address))
    37  }
    38  
    39  // loadAllInactiveAddrs loads all blocked address and set to `inactiveAddr`.
    40  // This function is executed when the app is initiated and save all inactive address in caches
    41  // in order to prevent to query to store in every time to send
    42  func (keeper BaseKeeper) loadAllInactiveAddrs(ctx sdk.Context) {
    43  	store := ctx.KVStore(keeper.storeKey)
    44  	iterator := sdk.KVStorePrefixIterator(store, inactiveAddrsKeyPrefix)
    45  
    46  	defer iterator.Close()
    47  	for ; iterator.Valid(); iterator.Next() {
    48  		var bAddr types.InactiveAddr
    49  		keeper.cdc.MustUnmarshal(iterator.Value(), &bAddr)
    50  
    51  		keeper.inactiveAddrs[bAddr.Address] = true
    52  	}
    53  }