github.com/KiraCore/sekai@v0.3.43/x/layer2/keeper/token_mint.go (about)

     1  package keeper
     2  
     3  import (
     4  	"github.com/KiraCore/sekai/x/layer2/types"
     5  	sdk "github.com/cosmos/cosmos-sdk/types"
     6  )
     7  
     8  func Pow10(decimal uint64) sdk.Int {
     9  	res := sdk.OneInt()
    10  	for i := 0; i < int(decimal); i++ {
    11  		res = res.Mul(sdk.NewInt(10))
    12  	}
    13  	return res
    14  }
    15  
    16  func (k Keeper) SetTokenInfo(ctx sdk.Context, info types.TokenInfo) {
    17  	bz := k.cdc.MustMarshal(&info)
    18  	store := ctx.KVStore(k.storeKey)
    19  	store.Set(types.TokenInfoKey(info.Denom), bz)
    20  }
    21  
    22  func (k Keeper) DeleteTokenInfo(ctx sdk.Context, denom string) {
    23  	store := ctx.KVStore(k.storeKey)
    24  	store.Delete(types.TokenInfoKey(denom))
    25  }
    26  
    27  func (k Keeper) GetTokenInfo(ctx sdk.Context, denom string) types.TokenInfo {
    28  	store := ctx.KVStore(k.storeKey)
    29  	bz := store.Get(types.TokenInfoKey(denom))
    30  	if bz == nil {
    31  		return types.TokenInfo{}
    32  	}
    33  
    34  	info := types.TokenInfo{}
    35  	k.cdc.MustUnmarshal(bz, &info)
    36  	return info
    37  }
    38  
    39  func (k Keeper) GetTokenInfos(ctx sdk.Context) []types.TokenInfo {
    40  	store := ctx.KVStore(k.storeKey)
    41  
    42  	infos := []types.TokenInfo{}
    43  	it := sdk.KVStorePrefixIterator(store, types.PrefixTokenInfoKey)
    44  	defer it.Close()
    45  
    46  	for ; it.Valid(); it.Next() {
    47  		info := types.TokenInfo{}
    48  		k.cdc.MustUnmarshal(it.Value(), &info)
    49  		infos = append(infos, info)
    50  	}
    51  	return infos
    52  }