Skip to content

Commit

Permalink
Add DeliverTx callback
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jul 24, 2024
1 parent 8653b19 commit ee91f65
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
5 changes: 5 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,11 @@ func (app *BaseApp) runTx(ctx sdk.Context, mode runTxMode, tx sdk.Tx, checksum [
// gas there too.
ctx = newCtx.WithMultiStore(ms)
}
defer func() {
if newCtx.DeliverTxCallback() != nil {
newCtx.DeliverTxCallback()(ctx.WithGasMeter(sdk.NewInfiniteGasMeterWithMultiplier(ctx)))
}

Check warning on line 951 in baseapp/baseapp.go

View check run for this annotation

Codecov / codecov/patch

baseapp/baseapp.go#L950-L951

Added lines #L950 - L951 were not covered by tests
}()

events := ctx.EventManager().Events()

Expand Down
54 changes: 32 additions & 22 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,29 @@ but please do not over-use it. We try to keep all data structured
and standard additions here would be better just to add to the Context struct
*/
type Context struct {
ctx context.Context
ms MultiStore
header tmproto.Header
headerHash tmbytes.HexBytes
chainID string
txBytes []byte
txSum [32]byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
occEnabled bool
blockGasMeter GasMeter
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
minGasPrice DecCoins
consParams *tmproto.ConsensusParams
eventManager *EventManager
evmEventManager *EVMEventManager
priority int64 // The tx priority, only relevant in CheckTx
pendingTxChecker abci.PendingTxChecker // Checker for pending transaction, only relevant in CheckTx
checkTxCallback func(Context, error) // callback to make at the end of CheckTx. Input param is the error (nil-able) of `runMsgs`
expireTxHandler func() // callback that the mempool invokes when a tx is expired
ctx context.Context
ms MultiStore
header tmproto.Header
headerHash tmbytes.HexBytes
chainID string
txBytes []byte
txSum [32]byte
logger log.Logger
voteInfo []abci.VoteInfo
gasMeter GasMeter
occEnabled bool
blockGasMeter GasMeter
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
minGasPrice DecCoins
consParams *tmproto.ConsensusParams
eventManager *EventManager
evmEventManager *EVMEventManager
priority int64 // The tx priority, only relevant in CheckTx
pendingTxChecker abci.PendingTxChecker // Checker for pending transaction, only relevant in CheckTx
checkTxCallback func(Context, error) // callback to make at the end of CheckTx. Input param is the error (nil-able) of `runMsgs`
deliverTxCallback func(Context) // callback to make at the end of DeliverTx.
expireTxHandler func() // callback that the mempool invokes when a tx is expired

txBlockingChannels acltypes.MessageAccessOpsChannelMapping
txCompletionChannels acltypes.MessageAccessOpsChannelMapping
Expand Down Expand Up @@ -169,6 +170,10 @@ func (c Context) CheckTxCallback() func(Context, error) {
return c.checkTxCallback
}

func (c Context) DeliverTxCallback() func(Context) {
return c.deliverTxCallback

Check warning on line 174 in types/context.go

View check run for this annotation

Codecov / codecov/patch

types/context.go#L173-L174

Added lines #L173 - L174 were not covered by tests
}

func (c Context) TxCompletionChannels() acltypes.MessageAccessOpsChannelMapping {
return c.txCompletionChannels
}
Expand Down Expand Up @@ -448,6 +453,11 @@ func (c Context) WithCheckTxCallback(checkTxCallback func(Context, error)) Conte
return c
}

func (c Context) WithDeliverTxCallback(deliverTxCallback func(Context)) Context {
c.deliverTxCallback = deliverTxCallback
return c

Check warning on line 458 in types/context.go

View check run for this annotation

Codecov / codecov/patch

types/context.go#L456-L458

Added lines #L456 - L458 were not covered by tests
}

func (c Context) WithExpireTxHandler(expireTxHandler func()) Context {
c.expireTxHandler = expireTxHandler
return c
Expand Down

0 comments on commit ee91f65

Please sign in to comment.