github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/erc20/keeper/params.go (about)

     1  package keeper
     2  
     3  import (
     4  	"strings"
     5  
     6  	sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types"
     7  	sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors"
     8  	"github.com/fibonacci-chain/fbc/x/erc20/types"
     9  )
    10  
    11  // GetParams returns the total set of erc20 parameters.
    12  func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
    13  	k.paramSpace.GetParamSet(ctx, &params)
    14  	return
    15  }
    16  
    17  // SetParams sets the erc20 parameters to the param space.
    18  func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
    19  	k.paramSpace.SetParamSet(ctx, &params)
    20  }
    21  
    22  // GetSourceChannelID returns the channel id for an ibc voucher
    23  // The voucher has for format ibc/hash(path)
    24  func (k Keeper) GetSourceChannelID(ctx sdk.Context, ibcVoucherDenom string) (channelID string, err error) {
    25  	hash := strings.Split(ibcVoucherDenom, "/")
    26  	if len(hash) != 2 {
    27  		return "", sdkerrors.Wrapf(types.ErrIbcDenomInvalid, "%s is invalid", ibcVoucherDenom)
    28  	}
    29  
    30  	path, err := k.transferKeeper.DenomPathFromHash(ctx, ibcVoucherDenom)
    31  	if err != nil {
    32  		return "", err
    33  	}
    34  
    35  	// the path has for format port/channelId
    36  	return strings.Split(path, "/")[1], nil
    37  }