-
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
- Loading branch information
1 parent
19e0de5
commit 3a0df27
Showing
4 changed files
with
73 additions
and
27 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,53 @@ | ||
package tx | ||
|
||
import ( | ||
"context" | ||
|
||
appmodulev2 "cosmossdk.io/core/appmodule/v2" | ||
"cosmossdk.io/core/transaction" | ||
"cosmossdk.io/x/auth/ante" | ||
) | ||
|
||
// TxValidator is appmodulev2.HasTxValidator without the AppModule requirement. | ||
type TxValidator = func(context.Context, transaction.Tx) error | ||
|
||
var ( | ||
_ appmodulev2.AppModule = AppModule{} | ||
_ appmodulev2.HasTxValidator[transaction.Tx] = AppModule{} | ||
) | ||
|
||
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 []TxValidator | ||
} | ||
|
||
// NewAppModule creates a new AppModule object. | ||
func NewAppModule( | ||
sigVerification ante.SigVerificationDecorator, | ||
txValidators ...TxValidator, | ||
) 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 _, validator := range a.txValidators { | ||
if err := validator(ctx, tx); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return a.sigVerification.ValidateTx(ctx, tx) | ||
} |