Skip to content

Commit 0067d72

Browse files
vm: add block/tx to afterTx, afterBlock event
1 parent a06ebde commit 0067d72

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

packages/vm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ Our `TypeScript` VM is implemented as an [AsyncEventEmitter](https://github.com/
130130
You can subscribe to the following events:
131131

132132
- `beforeBlock`: Emits a `Block` right before running it.
133-
- `afterBlock`: Emits `RunBlockResult` right after running a block.
133+
- `afterBlock`: Emits `AfterBlockEvent` right after running a block.
134134
- `beforeTx`: Emits a `Transaction` right before running it.
135-
- `afterTx`: Emits a `RunTxResult` right after running a transaction.
135+
- `afterTx`: Emits a `AfterTxEvent` right after running a transaction.
136136
- `beforeMessage`: Emits a `Message` right after running it.
137137
- `afterMessage`: Emits an `EVMResult` right after running a message.
138138
- `step`: Emits an `InterpreterStep` right before running an EVM step.

packages/vm/lib/runBlock.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ export interface PostByzantiumTxReceipt extends TxReceipt {
104104
status: 0 | 1
105105
}
106106

107+
export interface AfterBlockEvent extends RunBlockResult {
108+
// The block which just finished processing
109+
block: Block
110+
}
111+
107112
/**
108113
* @ignore
109114
*/
@@ -183,14 +188,20 @@ export default async function runBlock(this: VM, opts: RunBlockOpts): Promise<Ru
183188

184189
const { receipts, results } = result
185190

191+
const afterBlockEvent: AfterBlockEvent = {
192+
receipts,
193+
results,
194+
block,
195+
}
196+
186197
/**
187198
* The `afterBlock` event
188199
*
189200
* @event Event: afterBlock
190-
* @type {Object}
191-
* @property {Object} result emits the results of processing a block
201+
* @type {AfterBlockEvent}
202+
* @property {AfterBlockEvent} result emits the results of processing a block
192203
*/
193-
await this._emit('afterBlock', { receipts, results })
204+
await this._emit('afterBlock', afterBlockEvent)
194205

195206
return { receipts, results }
196207
}

packages/vm/lib/runTx.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export interface RunTxResult extends EVMResult {
4747
gasRefund?: BN
4848
}
4949

50+
export interface AfterTxEvent extends RunTxResult {
51+
/**
52+
* The transaction which just got finished
53+
*/
54+
transaction: Transaction
55+
}
56+
5057
/**
5158
* @ignore
5259
*/
@@ -199,7 +206,8 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
199206
* @type {Object}
200207
* @property {Object} result result of the transaction
201208
*/
202-
await this._emit('afterTx', results)
209+
const event: AfterTxEvent = { transaction: tx, ...results }
210+
await this._emit('afterTx', event)
203211

204212
return results
205213
}

0 commit comments

Comments
 (0)