-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
61 lines (52 loc) · 1.82 KB
/
params.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
54
55
56
57
58
59
60
61
package keeper
import (
"strings"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
transferTypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
"github.com/furyaxyz/elysium/v2/x/elysium/types"
evmTypes "github.com/evmos/ethermint/x/evm/types"
)
// GetParams returns the total set of elysium parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params
}
// SetParams sets the total set of elysium parameters.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
if err := params.Validate(); err != nil {
return err
}
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(¶ms)
store.Set(types.ParamsKey, bz)
return nil
}
// GetEvmParams returns the total set of evm parameters.
func (k Keeper) GetEvmParams(ctx sdk.Context) evmTypes.Params {
return k.evmKeeper.GetParams(ctx)
}
// GetSourceChannelID returns the channel id for an ibc voucher
// The voucher has for format ibc/hash(path)
func (k Keeper) GetSourceChannelID(ctx sdk.Context, ibcVoucherDenom string) (channelID string, err error) {
// remove the ibc
hash := strings.Split(ibcVoucherDenom, "/")
if len(hash) != 2 {
return "", errors.Wrapf(types.ErrIbcElyDenomInvalid, "%s is invalid", ibcVoucherDenom)
}
hexDenomBytes, err := transferTypes.ParseHexHash(hash[1])
if err != nil {
return "", errors.Wrapf(types.ErrIbcElyDenomInvalid, "%s is invalid", ibcVoucherDenom)
}
denomTrace, exists := k.transferKeeper.GetDenomTrace(ctx, hexDenomBytes)
if !exists {
return "", errors.Wrapf(types.ErrIbcElyDenomInvalid, "%s is invalid", ibcVoucherDenom)
}
// the path has for format port/channelId
return strings.Split(denomTrace.Path, "/")[1], nil
}