imp: NewAnteHandler returns error if input not valid (#1173)
make NewAnteHandler safer too use, and closer to cosmos-sdk api. extracted from https://github.com/evmos/ethermint/pull/1168
This commit is contained in:
parent
969794c5b4
commit
ea81e15d04
@ -23,7 +23,10 @@ const (
|
|||||||
// Ethereum or SDK transaction to an internal ante handler for performing
|
// Ethereum or SDK transaction to an internal ante handler for performing
|
||||||
// transaction-level processing (e.g. fee payment, signature verification) before
|
// transaction-level processing (e.g. fee payment, signature verification) before
|
||||||
// being passed onto it's respective handler.
|
// being passed onto it's respective handler.
|
||||||
func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
|
||||||
|
if err := options.validate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return func(
|
return func(
|
||||||
ctx sdk.Context, tx sdk.Tx, sim bool,
|
ctx sdk.Context, tx sdk.Tx, sim bool,
|
||||||
) (newCtx sdk.Context, err error) {
|
) (newCtx sdk.Context, err error) {
|
||||||
@ -62,7 +65,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return anteHandler(ctx, tx, sim)
|
return anteHandler(ctx, tx, sim)
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Recover(logger tmlog.Logger, err *error) {
|
func Recover(logger tmlog.Logger, err *error) {
|
||||||
|
@ -28,7 +28,7 @@ type HandlerOptions struct {
|
|||||||
MaxTxGasWanted uint64
|
MaxTxGasWanted uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (options HandlerOptions) Validate() error {
|
func (options HandlerOptions) validate() error {
|
||||||
if options.AccountKeeper == nil {
|
if options.AccountKeeper == nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func (suite *AnteTestSuite) SetupTest() {
|
|||||||
|
|
||||||
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
||||||
|
|
||||||
options := ante.HandlerOptions{
|
anteHandler, err := ante.NewAnteHandler(ante.HandlerOptions{
|
||||||
AccountKeeper: suite.app.AccountKeeper,
|
AccountKeeper: suite.app.AccountKeeper,
|
||||||
BankKeeper: suite.app.BankKeeper,
|
BankKeeper: suite.app.BankKeeper,
|
||||||
EvmKeeper: suite.app.EvmKeeper,
|
EvmKeeper: suite.app.EvmKeeper,
|
||||||
@ -114,11 +114,10 @@ func (suite *AnteTestSuite) SetupTest() {
|
|||||||
FeeMarketKeeper: suite.app.FeeMarketKeeper,
|
FeeMarketKeeper: suite.app.FeeMarketKeeper,
|
||||||
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
|
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
|
||||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||||
}
|
})
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
suite.Require().NoError(options.Validate())
|
suite.anteHandler = anteHandler
|
||||||
|
|
||||||
suite.anteHandler = ante.NewAnteHandler(options)
|
|
||||||
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
app/app.go
10
app/app.go
@ -570,7 +570,7 @@ func NewEthermintApp(
|
|||||||
// use Ethermint's custom AnteHandler
|
// use Ethermint's custom AnteHandler
|
||||||
|
|
||||||
maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
|
maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
|
||||||
options := ante.HandlerOptions{
|
anteHandler, err := ante.NewAnteHandler(ante.HandlerOptions{
|
||||||
AccountKeeper: app.AccountKeeper,
|
AccountKeeper: app.AccountKeeper,
|
||||||
BankKeeper: app.BankKeeper,
|
BankKeeper: app.BankKeeper,
|
||||||
EvmKeeper: app.EvmKeeper,
|
EvmKeeper: app.EvmKeeper,
|
||||||
@ -580,13 +580,11 @@ func NewEthermintApp(
|
|||||||
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
|
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
|
||||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
||||||
MaxTxGasWanted: maxGasWanted,
|
MaxTxGasWanted: maxGasWanted,
|
||||||
}
|
})
|
||||||
|
if err != nil {
|
||||||
if err := options.Validate(); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
app.SetAnteHandler(anteHandler)
|
||||||
app.SetAnteHandler(ante.NewAnteHandler(options))
|
|
||||||
app.SetEndBlocker(app.EndBlocker)
|
app.SetEndBlocker(app.EndBlocker)
|
||||||
|
|
||||||
if loadLatest {
|
if loadLatest {
|
||||||
|
Loading…
Reference in New Issue
Block a user