Skip to content

Commit

Permalink
evm: add transactionStateDiffs to LogRequest (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgroul authored Nov 4, 2024
1 parent 03736c5 commit 62c3f89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/evm-processor",
"comment": "add transactionStateDiffs to LogRequest",
"type": "minor"
}
],
"packageName": "@subsquid/evm-processor"
}
8 changes: 8 additions & 0 deletions evm/evm-processor/src/ds-rpc/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {DataRequest} from '../interfaces/data-request'
function buildLogFilter(dataRequest: DataRequest): EntityFilter<Log, {
transaction?: boolean,
transactionLogs?: boolean,
transactionStateDiffs?: boolean,
transactionTraces?: boolean
}> {
let items = new EntityFilter()
Expand Down Expand Up @@ -139,6 +140,7 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void {

let logsByTransaction = groupBy(block.logs, log => log.transactionIndex)
let tracesByTransaction = groupBy(block.traces, trace => trace.transactionIndex)
let stateDiffsByTransaction = groupBy(block.stateDiffs, diff => diff.transactionIndex)

let include = new IncludeSet()

Expand All @@ -162,6 +164,12 @@ export function filterBlock(block: Block, dataRequest: DataRequest): void {
include.addTrace(trace)
}
}
if (rel.transactionStateDiffs) {
let stateDiffs = stateDiffsByTransaction.get(log.transactionIndex) ?? []
for (let diff of stateDiffs) {
include.addStateDiff(diff)
}
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions evm/evm-processor/src/ds-rpc/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ function stateDiffsRequested(req?: DataRequest): boolean {
if (tx.stateDiffs) return true
}
}
if (req.logs) {
for (let log of req.logs) {
if (log.transactionStateDiffs) return true
}
}
return false
}

Expand Down
1 change: 1 addition & 0 deletions evm/evm-processor/src/interfaces/data-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface LogRequest {
transaction?: boolean
transactionTraces?: boolean
transactionLogs?: boolean
transactionStateDiffs?: boolean
}


Expand Down

0 comments on commit 62c3f89

Please sign in to comment.