## Description We decided to remove middlewares, and revert to antehandlers (exactly like in v045) for this release. A better middleware solution will be implemented after v046. ref: https://github.com/cosmos/cosmos-sdk/issues/11955 This PR is part 2 of 2: - part 1: Revert baseapp and middlewares to v0.45.4 - part 2: Add posthandler, tips, priority Depends on: - [x] #11979 --- Suggestion for reviewers: - Apart from correctness, I would also like someone to review **exhaustiveness**. I.e. all changes we made in v046 into the [middleware folder](https://github.com/cosmos/cosmos-sdk/tree/v0.46.0-beta2/x/auth/middleware) are reflected in this PR, and that I didn't forget anything. I found the following ones: - add a TxFeeChecker in DeductFee - add a ExtensionChecker in ExtCheckerDecorator - add a TipDecorator --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package baseapp
|
|
|
|
import (
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
)
|
|
|
|
// SimCheck defines a CheckTx helper function that used in tests and simulations.
|
|
func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
|
|
// runTx expects tx bytes as argument, so we encode the tx argument into
|
|
// bytes. Note that runTx will actually decode those bytes again. But since
|
|
// this helper is only used in tests/simulation, it's fine.
|
|
bz, err := txEncoder(tx)
|
|
if err != nil {
|
|
return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
|
|
}
|
|
gasInfo, result, _, _, err := app.runTx(runTxModeCheck, bz)
|
|
return gasInfo, result, err
|
|
}
|
|
|
|
// Simulate executes a tx in simulate mode to get result and gas info.
|
|
func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) {
|
|
gasInfo, result, _, _, err := app.runTx(runTxModeSimulate, txBytes)
|
|
return gasInfo, result, err
|
|
}
|
|
|
|
func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
|
|
// See comment for Check().
|
|
bz, err := txEncoder(tx)
|
|
if err != nil {
|
|
return sdk.GasInfo{}, nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err)
|
|
}
|
|
gasInfo, result, _, _, err := app.runTx(runTxModeDeliver, bz)
|
|
return gasInfo, result, err
|
|
}
|
|
|
|
// Context with current {check, deliver}State of the app used by tests.
|
|
func (app *BaseApp) NewContext(isCheckTx bool, header tmproto.Header) sdk.Context {
|
|
if isCheckTx {
|
|
return sdk.NewContext(app.checkState.ms, header, true, app.logger).
|
|
WithMinGasPrices(app.minGasPrices)
|
|
}
|
|
|
|
return sdk.NewContext(app.deliverState.ms, header, false, app.logger)
|
|
}
|
|
|
|
func (app *BaseApp) NewUncachedContext(isCheckTx bool, header tmproto.Header) sdk.Context {
|
|
return sdk.NewContext(app.cms, header, isCheckTx, app.logger)
|
|
}
|
|
|
|
func (app *BaseApp) GetContextForDeliverTx(txBytes []byte) sdk.Context {
|
|
return app.getContextForTx(runTxModeDeliver, txBytes)
|
|
}
|