Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add TxValidator interface #19950

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/appmodule/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ type HasEndBlocker interface {
EndBlock(context.Context) error
}

// HasTxValidation is the extension interface that modules should implement to run
// HasTxValidator is the extension interface that modules should implement to run
// custom logic for validating transactions.
// It was previously known as AnteHandler/Decorator.
type HasTxValidation[T transaction.Tx] interface {
type HasTxValidator[T transaction.Tx] interface {
Comment on lines +50 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the method TxValidator to ValidateTx to match the method name in the TxValidator interface. This will maintain consistency and clarity in the interface method naming.

-	TxValidator(ctx context.Context, tx T) error
+	ValidateTx(ctx context.Context, tx T) error

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// HasTxValidator is the extension interface that modules should implement to run
// custom logic for validating transactions.
// It was previously known as AnteHandler/Decorator.
type HasTxValidation[T transaction.Tx] interface {
type HasTxValidator[T transaction.Tx] interface {
// HasTxValidator is the extension interface that modules should implement to run
// custom logic for validating transactions.
// It was previously known as AnteHandler/Decorator.
type HasTxValidator[T transaction.Tx] interface {
ValidateTx(ctx context.Context, tx T) error

AppModule

// TxValidator is a method that will be run on each transaction.
Expand Down
13 changes: 13 additions & 0 deletions core/appmodule/v2/tx_validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package appmodule

import (
"context"

"cosmossdk.io/core/transaction"
)

// TxValidator represent the method that a TxValidator should implement.
// It was previously known as AnteHandler/Decorator.AnteHandle
type TxValidator[T transaction.Tx] interface {
ValidateTx(ctx context.Context, tx T) error
}
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding more detailed documentation for the TxValidator interface and its ValidateTx method to explain the expected behavior and potential error cases.

// TxValidator represents the method that a TxValidator should implement.
// It was previously known as AnteHandler/Decorator.AnteHandle
+// The ValidateTx method should perform all necessary checks to validate a transaction.
+// It should return an error if the transaction fails any of these checks.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// TxValidator represent the method that a TxValidator should implement.
// It was previously known as AnteHandler/Decorator.AnteHandle
type TxValidator[T transaction.Tx] interface {
ValidateTx(ctx context.Context, tx T) error
}
// TxValidator represents the method that a TxValidator should implement.
// It was previously known as AnteHandler/Decorator.AnteHandle
// The ValidateTx method should perform all necessary checks to validate a transaction.
// It should return an error if the transaction fails any of these checks.
type TxValidator[T transaction.Tx] interface {
ValidateTx(ctx context.Context, tx T) error
}

Loading