Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yihuang <huang@crypto.com> Co-authored-by: mmsqe <mavis@crypto.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io> Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com> Co-authored-by: FT <140458077+zeevick10@users.noreply.github.com> Co-authored-by: VolodymyrBg <aqdrgg19@gmail.com> Co-authored-by: GarmashAlex <garmasholeksii@gmail.com> Co-authored-by: kilavvy <140459108+kilavvy@users.noreply.github.com> Co-authored-by: Maxim Evtush <154841002+maximevtush@users.noreply.github.com> Co-authored-by: fuder.eth <139509124+vtjl10@users.noreply.github.com> Co-authored-by: leopardracer <136604165+leopardracer@users.noreply.github.com> Co-authored-by: MozirDmitriy <dmitriymozir@gmail.com> Co-authored-by: Avory <avorycorelli@gmail.com> Co-authored-by: mmsqe <tqd0800210105@gmail.com> Co-authored-by: julienrbrt <julien@rbrt.fr> Co-authored-by: Aaron <aaronc@users.noreply.github.com> Co-authored-by: Vlad J <vladjdk@gmail.com> Co-authored-by: Thomas Nguy <thomas.nguy@crypto.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package txnrunner
|
|
|
|
import (
|
|
"context"
|
|
|
|
abci "github.com/cometbft/cometbft/abci/types"
|
|
|
|
storetypes "cosmossdk.io/store/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
)
|
|
|
|
var _ sdk.TxRunner = DefaultRunner{}
|
|
|
|
func NewDefaultRunner(txDecoder sdk.TxDecoder) *DefaultRunner {
|
|
return &DefaultRunner{
|
|
txDecoder: txDecoder,
|
|
}
|
|
}
|
|
|
|
// DefaultRunner is the default TxnRunner implementation which executes the transactions in a block sequentially.
|
|
type DefaultRunner struct {
|
|
txDecoder sdk.TxDecoder
|
|
}
|
|
|
|
func (d DefaultRunner) Run(ctx context.Context, _ storetypes.MultiStore, txs [][]byte, deliverTx sdk.DeliverTxFunc) ([]*abci.ExecTxResult, error) {
|
|
// Fallback to the default execution logic
|
|
txResults := make([]*abci.ExecTxResult, 0, len(txs))
|
|
for i, rawTx := range txs {
|
|
var response *abci.ExecTxResult
|
|
|
|
if _, err := d.txDecoder(rawTx); err == nil {
|
|
response = deliverTx(rawTx, nil, i, nil)
|
|
} else {
|
|
// In the case where a transaction included in a block proposal is malformed,
|
|
// we still want to return a default response to comet. This is because comet
|
|
// expects a response for each transaction included in a block proposal.
|
|
response = sdkerrors.ResponseExecTxResultWithEvents(
|
|
sdkerrors.ErrTxDecode,
|
|
0,
|
|
0,
|
|
nil,
|
|
false,
|
|
)
|
|
}
|
|
|
|
// check after every tx if we should abort
|
|
select {
|
|
case <-ctx.Done():
|
|
return nil, ctx.Err()
|
|
default:
|
|
// continue
|
|
}
|
|
|
|
txResults = append(txResults, response)
|
|
}
|
|
return txResults, nil
|
|
}
|