Skip to content

Commit 981138b

Browse files
committed
Adds transaction data improvement
1 parent c409b9c commit 981138b

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/tools/get-transaction-data.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,27 @@ const main = async () => {
2828
? await api.rpc.chain.getBlockHash(argv.at)
2929
: await api.rpc.chain.getBlockHash();
3030
const block = await api.rpc.chain.getBlock(blockHash);
31+
const apiAt = await api.at(blockHash);
3132

3233
block.block.extrinsics.forEach((ex, index) => {
33-
console.log(index, `${ex.method.section.toString()}.${ex.method.method.toString()} [${ex.hash.toHex()}]\n${ex.method.method.toString() == "setValidationData" ? "..." : ex.toHex()}`);
34+
const { method, signature, isSigned, signer, nonce } = ex;
35+
console.log(index, `${ex.method.section.toString()}.${ex.method.method.toString()} [${ex.hash.toHex()}]`);
36+
// if (method.args.length > 0) {
37+
// console.log(` Args: ${method.args.map((arg) => arg.toHex()).join(', ')}`);
38+
// }
39+
40+
if (method.section === 'sudo' && method.method.startsWith('sudo')) {
41+
// Handle sudo extrinsics
42+
const nestedCall = method.args[0]; // The "call" is the first argument in sudo methods
43+
const { section, method: nestedMethod, args: nestedArgs } = apiAt.registry.createType('Call', nestedCall);
44+
45+
console.log(` Nested Call: ${section}.${nestedMethod}`);
46+
const nestedDecodedArgs = nestedArgs.map((arg: any) => arg.toHuman());
47+
console.log(` Nested Args: ${JSON.stringify(nestedDecodedArgs, null, 2)}`);
48+
}
49+
console.log(`${ex.method.method.toString() == "setValidationData" ? "..." : ex.toHex()}`);
50+
51+
3452
});
3553

3654
await api.disconnect();

src/utils/monitoring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export const getFeeMultiplier = async (api: ApiPromise, blockHash: string): Prom
255255
return feeMultiplierCache[blockHash];
256256
};
257257

258-
export const getBlockDetails = async (api: ApiPromise, blockHash: BlockHash) => {
258+
export const getBlockDetails = async (api: ApiPromise, blockHash: BlockHash | string) => {
259259
debug(`Querying ${blockHash}`);
260260
const maxBlockWeight = (api.consts.system.blockWeights.maxBlock as any).toBigInt
261261
? (api.consts.system.blockWeights.maxBlock as any).toBigInt()

src/utils/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export const mapExtrinsics = async (
4848
return event;
4949
});
5050

51-
const unadjustedWeightFee = (
51+
const unadjustedWeightFee = dispatchInfo ? (
5252
(await api.call.transactionPaymentApi.queryWeightToFee(dispatchInfo.weight)) as any
53-
).toBigInt();
53+
).toBigInt() : 0n;
5454
const lengthFee = (
5555
(await api.call.transactionPaymentApi.queryLengthToFee(extrinsic.encodedLength)) as any
5656
).toBigInt();

0 commit comments

Comments
 (0)