Skip to content

Commit

Permalink
feat(get-rmrks): [as-derivative]
Browse files Browse the repository at this point in the history
Get RMRKs from `utility.asDerivative` calls.
  • Loading branch information
danforbes committed Jun 6, 2021
1 parent dee0587 commit 096048f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ export const isUtilityBatch = (call: TCall) =>
call.section === "utility" &&
(call.method === "batch" || call.method === "batchAll");

export const hasInnerCall = (call: TCall): boolean =>
call.section === "utility" && call.method === "asDerivative";

export const getInnerCall = (call: TCall) => {
const sectionMethod = `${call.section}.${call.method}`;
switch (sectionMethod) {
case ("utility.asDerivative"): {
return call.args[1];
}

default: {
throw new Error(`Cannot get inner call from ${sectionMethod}.`);
}
}
};

export const getBlockCallsFromSignedBlock = async (
signedBlock: SignedBlock,
prefixes: string[],
Expand Down Expand Up @@ -226,6 +242,19 @@ export const getBlockCallsFromSignedBlock = async (

blockCalls = blockCalls.concat(batchRoot);
}
} else if (hasInnerCall(extrinsic.method as TCall)) {
let method = api.createType("Call", getInnerCall(extrinsic.method as TCall));
while (hasInnerCall(method)) {
method = api.createType("Call", getInnerCall(method));
}

if (isSystemRemark(method, prefixes)) {
blockCalls.push({
call: "system.remark",
value: method.args.toString(),
caller: encodeAddress(extrinsic.signer.toString(), ss58Format),
});
}
}
extrinsicIndex++;
}
Expand Down

0 comments on commit 096048f

Please sign in to comment.