-
Notifications
You must be signed in to change notification settings - Fork 126
/
params.go
72 lines (59 loc) · 1.72 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
62
63
64
65
66
67
68
69
70
71
72
package keeper
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/haqq-network/haqq/x/feemarket/types"
)
// GetParams returns the total set of fee market parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if len(bz) == 0 {
var p types.Params
k.ss.GetParamSetIfExists(ctx, &p)
return p
}
k.cdc.MustUnmarshal(bz, ¶ms)
return params
}
// SetParams sets the fee market params in a single key
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(¶ms)
if err != nil {
return err
}
store.Set(types.ParamsKey, bz)
return nil
}
// ----------------------------------------------------------------------------
// Parent Base Fee
// Required by EIP1559 base fee calculation.
// ----------------------------------------------------------------------------
// GetBaseFeeEnabled returns true if base fee is enabled
func (k Keeper) GetBaseFeeEnabled(ctx sdk.Context) bool {
params := k.GetParams(ctx)
return !params.NoBaseFee && ctx.BlockHeight() >= params.EnableHeight
}
// GetBaseFee gets the base fee from the store
func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
params := k.GetParams(ctx)
if params.NoBaseFee {
return nil
}
baseFee := params.BaseFee.BigInt()
if baseFee == nil || baseFee.Sign() == 0 {
// try v1 format
return k.GetBaseFeeV1(ctx)
}
return baseFee
}
// SetBaseFee set's the base fee in the store
func (k Keeper) SetBaseFee(ctx sdk.Context, baseFee *big.Int) {
params := k.GetParams(ctx)
params.BaseFee = sdk.NewIntFromBigInt(baseFee)
err := k.SetParams(ctx, params)
if err != nil {
return
}
}