Skip to content

Commit 23ac1fb

Browse files
authored
feat: utility batch call walker (#47)
* feat: utility batch call walker * fix: fix * fix: fix * fix: fix * fix: style
1 parent 23863f7 commit 23ac1fb

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

hydradx.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ dataSources:
7474
kind: substrate/EventHandler
7575
filter:
7676
module: system
77-
method: Remarked
77+
method: Remarked

polkadot.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,3 @@ dataSources:
7575
filter:
7676
module: system
7777
method: Remarked
78-

src/mappings/handlers/multisigRemarkHandler.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@ import { u8aToHex } from "@polkadot/util";
66
import { MultisigRemarkArgs } from "../types";
77
import { validateAddress } from "../../utils/validateAddress";
88
import { isJsonStringArgs } from "../../utils/isJson";
9+
import { CreateCallVisitorBuilder, CreateCallWalk, VisitedCall } from "subquery-call-visitor";
10+
import { Bytes } from "@polkadot/types";
911

12+
const callWalk = CreateCallWalk()
13+
const multisigVisitor = CreateCallVisitorBuilder()
14+
.on('system', 'remark', handleMultisigRemarkCall)
15+
.ignoreFailedCalls(true)
16+
.build();
1017

11-
export async function handleMultisigRemarkEventHandler(event: SubstrateEvent): Promise<void> {
12-
if (!event) return;
18+
export async function handleMultisigRemarkEventHandler(event: SubstrateEvent) {
19+
if (!event || !event.extrinsic) return;
1320

14-
const extrinsic = event.extrinsic?.extrinsic;
21+
callWalk.walk(event.extrinsic, multisigVisitor)
22+
}
1523

16-
if (!extrinsic) return;
24+
export async function handleMultisigRemarkCall(call: VisitedCall): Promise<void> {
25+
if (!call || !call.call || !call.call.args) return;
1726

18-
if (!isJsonStringArgs(extrinsic)) return;
27+
if (!isJsonStringArgs(call.call.args as Bytes[])) return;
1928

20-
const args = extrinsic.args[0]?.toHuman() as unknown as string;
29+
const args = call.call.args[0]?.toHuman() as unknown as string;
2130

2231
let parsedArgs: MultisigRemarkArgs;
2332
try {

src/utils/isJson.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Bytes } from "@polkadot/types";
2-
import { Extrinsic } from "@polkadot/types/interfaces";
32

4-
export const isJsonStringArgs = (extrinsic: Extrinsic) => {
3+
export const isJsonStringArgs = (args: Bytes[]) => {
54
//123 is { and 125 is } :)
6-
return (extrinsic.args[0] as Bytes).at(-1) === 125 && (extrinsic.args[0] as Bytes).at(0) === 123;
5+
return (args[0] as Bytes).at(-1) === 125 && (args[0] as Bytes).at(0) === 123;
76
}

westend-asset-hub.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ dataSources:
7373
kind: substrate/EventHandler
7474
filter:
7575
module: system
76-
method: Remarked
76+
method: Remarked

westend.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ dataSources:
7575
kind: substrate/EventHandler
7676
filter:
7777
module: system
78-
method: Remarked
78+
method: Remarked

0 commit comments

Comments
 (0)