-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/auth/tx): extend app module + docs (#21409)
(cherry picked from commit 355f4d7)
- Loading branch information
1 parent
49bcd45
commit 1ad452d
Showing
4 changed files
with
83 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package tx | ||
|
||
import ( | ||
"context" | ||
|
||
appmodulev2 "cosmossdk.io/core/appmodule/v2" | ||
"cosmossdk.io/core/transaction" | ||
"cosmossdk.io/x/auth/ante" | ||
) | ||
|
||
var ( | ||
_ appmodulev2.AppModule = AppModule{} | ||
_ appmodulev2.HasTxValidator[transaction.Tx] = AppModule{} | ||
) | ||
|
||
// AppModule is a module that only implements tx validators. | ||
// The goal of this module is to allow extensible registration of tx validators provided by chains without requiring a new modules. | ||
// Additionally, it registers tx validators that do not really have a place in other modules. | ||
// This module is only useful for chains using server/v2. Ante/Post handlers are setup via baseapp options in depinject. | ||
type AppModule struct { | ||
sigVerification ante.SigVerificationDecorator | ||
// txValidators contains tx validator that can be injected into the module via depinject. | ||
// tx validators should be module based, but it can happen that you do not want to create a new module | ||
// and simply depinject-it. | ||
txValidators []appmodulev2.TxValidator[transaction.Tx] | ||
} | ||
|
||
// NewAppModule creates a new AppModule object. | ||
func NewAppModule( | ||
sigVerification ante.SigVerificationDecorator, | ||
txValidators ...appmodulev2.TxValidator[transaction.Tx], | ||
) AppModule { | ||
return AppModule{ | ||
sigVerification: sigVerification, | ||
txValidators: txValidators, | ||
} | ||
} | ||
|
||
// IsAppModule implements appmodule.AppModule. | ||
func (a AppModule) IsAppModule() {} | ||
|
||
// IsOnePerModuleType implements appmodule.AppModule. | ||
func (a AppModule) IsOnePerModuleType() {} | ||
|
||
// TxValidator implements appmodule.HasTxValidator. | ||
func (a AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error { | ||
for _, txValidator := range a.txValidators { | ||
if err := txValidator.ValidateTx(ctx, tx); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return a.sigVerification.ValidateTx(ctx, tx) | ||
} |