Skip to content

Commit

Permalink
add DeliverTx hook (#521)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context

## Testing performed to validate your change
  • Loading branch information
codchen authored Jun 27, 2024
1 parent ae5ac34 commit 2a87e89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ func (app *BaseApp) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx, tx sdk
resultStr = "failed"
}
}
for _, hook := range app.deliverTxHooks {
hook(ctx, tx, checksum, res)
}
return
}

Expand Down
9 changes: 9 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type (
// an older version of the software. In particular, if a module changed the substore key name
// (or removed a substore) between two versions of the software.
StoreLoader func(ms sdk.CommitMultiStore) error

DeliverTxHook func(sdk.Context, sdk.Tx, [32]byte, abci.ResponseDeliverTx)
)

// BaseApp reflects the ABCI application implementation.
Expand Down Expand Up @@ -172,6 +174,8 @@ type BaseApp struct { //nolint: maligned

concurrencyWorkers int
occEnabled bool

deliverTxHooks []DeliverTxHook
}

type appStore struct {
Expand Down Expand Up @@ -279,6 +283,7 @@ func NewBaseApp(
},
commitLock: &sync.Mutex{},
checkTxStateLock: &sync.RWMutex{},
deliverTxHooks: []DeliverTxHook{},
}

app.TracingInfo.SetContext(context.Background())
Expand Down Expand Up @@ -1203,3 +1208,7 @@ func (app *BaseApp) GetCheckCtx() sdk.Context {
defer app.checkTxStateLock.RUnlock()
return app.checkState.ctx
}

func (app *BaseApp) RegisterDeliverTxHook(hook DeliverTxHook) {
app.deliverTxHooks = append(app.deliverTxHooks, hook)
}

0 comments on commit 2a87e89

Please sign in to comment.