NewAppAnteHandler
NewAppAnteHandler(existingHandler sdk.AnteHandler, decorators ...sdk.AnteDecorator) sdk.AnteHandler Constructs a new application AnteHandler by chaining a series of AnteDecorators. This function is used within the Maroo application setup to build the transaction validation pipeline. Each decorator in the chain wraps the next, allowing for a modular approach to validation logic like signature verification, fee deduction, and nonce checking.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
existingHandler | sdk.AnteHandler | ✓ | The final handler in the chain, which is often the core transaction execution logic. |
decorators | ...sdk.AnteDecorator | ✓ | A variadic list of AnteDecorator implementations that will be chained together in the order they are provided. |
Returns
Type:
sdk.AnteHandler A single AnteHandler function that represents the entire chain of decorators.
Examples
Basic AnteHandler Chain Construction
This example shows how to create a simple AnteHandler chain with a custom logging decorator and a final handler. The `NewAppAnteHandler` function links them together.
package main
import (
"fmt"
"github.com/cosmos/cosmos-sdk/types"
ante "github.com/delight-labs/maroo/ante"
)
// A simple decorator that just logs a message ype LoggingDecorator struct{}
func (ld LoggingDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (newCtx types.Context, err error) {
fmt.Println("LoggingDecorator: processing transaction")
return next(ctx, tx, simulate)
}
// A final handler that signifies the end of the chain
func finalHandler(ctx types.Context, tx types.Tx, simulate bool) (types.Context, error) {
fmt.Println("Final handler reached.")
return ctx, nil
}
func main() {
// Create decorators
logDecorator := LoggingDecorator{}
// Construct the AnteHandler chain
anteHandler := ante.NewAppAnteHandler(finalHandler, logDecorator)
// In a real app, this handler would be set on the BaseApp instance.
// Here we just call it to demonstrate the flow.
anteHandler(types.Context{}, nil, false)
}