// Package ante provides ante handler implementations for transaction processing // in the Sonr blockchain. It supports both Cosmos SDK and Ethereum transactions. package ante import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" ) // NewAnteHandler returns an ante handler responsible for attempting to route an // Ethereum or SDK transaction to an internal ante handler for performing // transaction-level processing (e.g. fee payment, signature verification) before // being passed onto it's respective handler. // // The handler inspects the transaction type and extension options to determine // the appropriate processing path: // - Ethereum transactions with ExtensionOptionsEthereumTx // - Cosmos SDK transactions with ExtensionOptionDynamicFeeTx // - Standard Cosmos SDK transactions func NewAnteHandler(options HandlerOptions) sdk.AnteHandler { return func( ctx sdk.Context, tx sdk.Tx, sim bool, ) (newCtx sdk.Context, err error) { var anteHandler sdk.AnteHandler txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx) if ok { opts := txWithExtensions.GetExtensionOptions() if len(opts) > 0 { switch typeURL := opts[0].GetTypeUrl(); typeURL { case "/cosmos.evm.vm.v1.ExtensionOptionsEthereumTx": // handle as *evmtypes.MsgEthereumTx anteHandler = newMonoEVMAnteHandler(options) case "/cosmos.evm.vm.v1.ExtensionOptionDynamicFeeTx": // cosmos-sdk tx with dynamic fee extension anteHandler = NewCosmosAnteHandler(options) default: return ctx, errorsmod.Wrapf( errortypes.ErrUnknownExtensionOptions, "rejecting tx with unsupported extension option: %s", typeURL, ) } return anteHandler(ctx, tx, sim) } } // handle as totally normal Cosmos SDK tx switch tx.(type) { case sdk.Tx: anteHandler = NewCosmosAnteHandler(options) default: return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx) } return anteHandler(ctx, tx, sim) } }