Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to load sibling calls #312

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/substrate-processor",
"comment": "allow to request sibling calls",
"type": "minor"
}
],
"packageName": "@subsquid/substrate-processor"
}
6 changes: 6 additions & 0 deletions substrate/substrate-processor/src/ds-rpc-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function filterBlock(block: Block, dataRequest: DataRequest): void {
if (rel.extrinsic) {
include.addExtrinsic(call.extrinsic)
}
if (rel.siblings) {
for (let sibling of call.siblings) {
include.addCall(sibling)
}
}
}
}

Expand All @@ -175,6 +180,7 @@ function filterBlock(block: Block, dataRequest: DataRequest): void {
call.extrinsic = undefined
}
call.subcalls = call.subcalls.filter(sub => include.calls.has(sub))
call.siblings = call.siblings.filter(sib => include.calls.has(sib))
call.events = call.events.filter(event => include.events.has(event))
return true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface CallRelations {
extrinsic?: boolean
stack?: boolean
events?: boolean
siblings?: boolean
}


Expand Down
1 change: 1 addition & 0 deletions substrate/substrate-processor/src/interfaces/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type Call<F extends FieldSelection = {}> = Simplify<
parentCall?: Call<F>
getParentCall(): Call<F>
subcalls: Call<F>[]
siblings: Call<F>[]
events: Event<F>[]
}
>
Expand Down
28 changes: 28 additions & 0 deletions substrate/substrate-processor/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class Call {
#extrinsic?: Extrinsic
#parentCall?: Call
#subcalls?: Call[]
#siblings?: Call[]
#events?: Event[]
#ethereumTransactTo?: Bytes
#ethereumTransactSighash?: Bytes
Expand Down Expand Up @@ -219,6 +220,15 @@ export class Call {
this.#subcalls = calls
}

get siblings(): Call[] {
Copy link
Contributor

@belopash belopash Jul 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this new field looks a bit unnatural. You already can achieve the same by using call.parentCall.subcalls

this.#siblings = this.#siblings || []
return this.#siblings
}

set siblings(calls: Call[]) {
this.#siblings = calls
}

get events(): Event[] {
this.#events = this.#events || []
return this.#events
Expand Down Expand Up @@ -405,6 +415,9 @@ export function setUpItems(block: Block): void {
rec.parentCall = prev
populateSubcalls(prev, rec)
}
if (isSibling(prev, rec)) {
populateSiblings(prev, rec)
}
}
}

Expand Down Expand Up @@ -462,6 +475,15 @@ function populateSubcalls(parent: Call | undefined, child: Call): void {
}


function populateSiblings(prev: Call, call: Call) {
call.siblings.unshift(prev, ...prev.siblings)
for (let sibling of prev.siblings) {
sibling.siblings.unshift(call)
}
prev.siblings.unshift(call)
}


function callCompare(a: Call, b: Call) {
return a.extrinsicIndex - b.extrinsicIndex || addressCompare(a.address, b.address)
}
Expand All @@ -487,3 +509,9 @@ function isSubcall(parent: CallKey, call: CallKey): boolean {
}
return true
}


function isSibling(a: CallKey, b: CallKey): boolean {
if (a.extrinsicIndex != b.extrinsicIndex) return false
return a.address.length == b.address.length
}
Loading