Skip to content

Commit

Permalink
return '__type' field back to decoded ink events (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgroul authored Jul 25, 2024
1 parent 53077b3 commit 9526749
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions common/changes/@subsquid/ink-abi/ink-abi-fix_2024-07-25-11-06.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/ink-abi",
"comment": "return `__type` field back to decoded events",
"type": "patch"
}
],
"packageName": "@subsquid/ink-abi"
}
2 changes: 2 additions & 0 deletions substrate/ink-abi/src/abi-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SelectorsMap {


export interface AbiEvent {
name: string
type: Ti
amountIndexed: number
signatureTopic?: Bytes
Expand Down Expand Up @@ -98,6 +99,7 @@ export class AbiDescription {
})

return {
name: normalizeLabel(e.label),
type: ti,
amountIndexed: e.args.reduce((val, e) => e.indexed ? val + 1 : val, 0),
signatureTopic: e.signature_topic as Bytes
Expand Down
15 changes: 12 additions & 3 deletions substrate/ink-abi/src/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ export class Abi {
throw new Error(`Unable to find event with index ${idx}`);
}

return this.scaleCodec.decode(event.type, src)
return {
__type: event.name,
...this.scaleCodec.decode(event.type, src)
}
}

decodeEventV5(data: Uint8Array | Bytes, topics: Bytes[]) {
let topic = topics[0]
if (topic) {
let event = this.events.find(e => e.signatureTopic == topic)
if (event) {
return this.scaleCodec.decodeBinary(event.type, data)
return {
__type: event.name,
...this.scaleCodec.decodeBinary(event.type, data)
}
}
}

Expand All @@ -86,7 +92,10 @@ export class Abi {

if (potentialEvents.length == 1) {
let event = potentialEvents[0]
return this.scaleCodec.decodeBinary(event.type, data)
return {
__type: event.name,
...this.scaleCodec.decodeBinary(event.type, data)
}
}

throw new Error('Unable to determine event')
Expand Down

0 comments on commit 9526749

Please sign in to comment.