2021-08-26 10:08:11 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
|
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
|
|
|
2022-04-11 08:09:39 +00:00
|
|
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
2021-08-26 10:08:11 +00:00
|
|
|
"github.com/tharsis/ethermint/x/feemarket/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Keeper grants access to the Fee Market module state.
|
|
|
|
type Keeper struct {
|
|
|
|
// Protobuf codec
|
|
|
|
cdc codec.BinaryCodec
|
|
|
|
// Store key required for the Fee Market Prefix KVStore.
|
2022-04-11 08:09:39 +00:00
|
|
|
storeKey storetypes.StoreKey
|
2021-08-26 10:08:11 +00:00
|
|
|
// module specific parameter space that can be configured through governance
|
|
|
|
paramSpace paramtypes.Subspace
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewKeeper generates new fee market module keeper
|
|
|
|
func NewKeeper(
|
2022-04-11 08:09:39 +00:00
|
|
|
cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace,
|
2021-08-26 10:08:11 +00:00
|
|
|
) Keeper {
|
|
|
|
// set KeyTable if it has not already been set
|
|
|
|
if !paramSpace.HasKeyTable() {
|
|
|
|
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
|
|
|
|
}
|
|
|
|
|
|
|
|
return Keeper{
|
|
|
|
cdc: cdc,
|
|
|
|
storeKey: storeKey,
|
|
|
|
paramSpace: paramSpace,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Logger returns a module-specific logger.
|
|
|
|
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
|
|
|
return ctx.Logger().With("module", types.ModuleName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Parent Block Gas Used
|
|
|
|
// Required by EIP1559 base fee calculation.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// GetBlockGasUsed returns the last block gas used value from the store.
|
|
|
|
func (k Keeper) GetBlockGasUsed(ctx sdk.Context) uint64 {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
bz := store.Get(types.KeyPrefixBlockGasUsed)
|
|
|
|
if len(bz) == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return sdk.BigEndianToUint64(bz)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetBlockGasUsed gets the block gas consumed to the store.
|
|
|
|
// CONTRACT: this should be only called during EndBlock.
|
|
|
|
func (k Keeper) SetBlockGasUsed(ctx sdk.Context, gas uint64) {
|
|
|
|
store := ctx.KVStore(k.storeKey)
|
|
|
|
gasBz := sdk.Uint64ToBigEndian(gas)
|
|
|
|
store.Set(types.KeyPrefixBlockGasUsed, gasBz)
|
|
|
|
}
|