Skip to content

Commit

Permalink
feat(feemarket): add interface and basic mock (#2)
Browse files Browse the repository at this point in the history
* add interface

* mock

* md

* md

* md

* lint fix

* move files

* nit fix
  • Loading branch information
Alex Johnson authored Nov 9, 2023
1 parent a72d769 commit a2e34a7
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
Empty file added x/feemarket/plugins/README.md
Empty file.
83 changes: 83 additions & 0 deletions x/feemarket/plugins/mock/feemarket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package mock

import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/skip-mev/feemarket/x/feemarket/types"
)

var _ types.FeeMarketImplementation = &MockFeeMarket{}

type MockFeeMarket struct{} //nolint

// ValidateBasic is a no-op.
func (fm *MockFeeMarket) ValidateBasic() error {
return nil
}

// Init which initializes the fee market (in InitGenesis)
func (fm *MockFeeMarket) Init(_ sdk.Context) error {
return nil
}

// Export which exports the fee market (in ExportGenesis)
func (fm *MockFeeMarket) Export(_ sdk.Context) (json.RawMessage, error) {
return nil, nil
}

// BeginBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the BeginBlock chain.
func (fm *MockFeeMarket) BeginBlockUpdateHandler(_ sdk.Context) types.UpdateHandler {
return func(ctx sdk.Context) error {
return nil
}
}

// EndBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the EndBlock chain.
func (fm *MockFeeMarket) EndBlockUpdateHandler(_ sdk.Context) types.UpdateHandler {
return func(ctx sdk.Context) error {
return nil
}
}

// GetFeeMarketInfo retrieves the fee market's information about
// how to pay for a transaction (min gas price, min tip,
// where the fees are being distributed, etc.).
func (fm *MockFeeMarket) GetFeeMarketInfo(_ sdk.Context) map[string]string {
return nil
}

// GetID returns the identifier of the fee market
func (fm *MockFeeMarket) GetID() string {
return "mock"
}

// FeeAnteHandler will be called in the module AnteHandler.
// Performs no actions.
func (fm *MockFeeMarket) FeeAnteHandler(
_ sdk.Context,
_ sdk.Tx,
_ bool,
next sdk.AnteHandler,
) sdk.AnteHandler {
return func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
return next(ctx, tx, simulate)
}
}

// FeePostHandler will be called in the module PostHandler
// if PostHandlers are implemented. Performs no actions.
func (fm *MockFeeMarket) FeePostHandler(
_ sdk.Context,
_ sdk.Tx,
_,
_ bool,
next sdk.PostHandler,
) sdk.PostHandler {
return func(ctx sdk.Context, tx sdk.Tx, simulate, success bool) (newCtx sdk.Context, err error) {
return next(ctx, tx, simulate, success)
}
}
70 changes: 70 additions & 0 deletions x/feemarket/types/feemarket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package types

import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// FeeMarketImplementation represents the interface of various FeeMarket types implemented
// by other modules or packages.
type FeeMarketImplementation interface {
// proto.Message TODO: add

// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
ValidateBasic() error

// ------------------- Fee Market Parameters ------------------- //

// Init which initializes the fee market (in InitGenesis)
Init(ctx sdk.Context) error

// Export which exports the fee market (in ExportGenesis)
Export(ctx sdk.Context) (json.RawMessage, error)

// BeginBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the BeginBlock chain.
BeginBlockUpdateHandler(ctx sdk.Context) UpdateHandler

// EndBlockUpdateHandler allows the fee market to be updated
// after every block. This will be added to the EndBlock chain.
EndBlockUpdateHandler(ctx sdk.Context) UpdateHandler

// ------------------- Fee Market Queries ------------------- //

// GetFeeMarketInfo retrieves the fee market's information about
// how to pay for a transaction (min gas price, min tip,
// where the fees are being distributed, etc.).
GetFeeMarketInfo(ctx sdk.Context) map[string]string

// GetID returns the identifier of the fee market
GetID() string

// ------------------- Fee Market Extraction ------------------- //

// FeeAnteHandler will be called in the module AnteHandler,
// this is where the fee market would extract and distribute
// fees from a given transaction
FeeAnteHandler(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) sdk.AnteHandler

// FeePostHandler will be called in the module PostHandler
// if PostHandlers are implemented. This is another place
// the fee market might refund users
FeePostHandler(
ctx sdk.Context,
tx sdk.Tx,
simulate,
success bool,
next sdk.PostHandler,
) sdk.PostHandler
}

// UpdateHandler is responsible for updating the parameters of the
// fee market plugin. Fees can optionally also be extracted here.
type UpdateHandler func(ctx sdk.Context) error

0 comments on commit a2e34a7

Please sign in to comment.