Skip to content

Commit

Permalink
Adds transaction data improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Nov 29, 2024
1 parent c409b9c commit 981138b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/tools/get-transaction-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,27 @@ const main = async () => {
? await api.rpc.chain.getBlockHash(argv.at)
: await api.rpc.chain.getBlockHash();
const block = await api.rpc.chain.getBlock(blockHash);
const apiAt = await api.at(blockHash);

block.block.extrinsics.forEach((ex, index) => {
console.log(index, `${ex.method.section.toString()}.${ex.method.method.toString()} [${ex.hash.toHex()}]\n${ex.method.method.toString() == "setValidationData" ? "..." : ex.toHex()}`);
const { method, signature, isSigned, signer, nonce } = ex;
console.log(index, `${ex.method.section.toString()}.${ex.method.method.toString()} [${ex.hash.toHex()}]`);
// if (method.args.length > 0) {
// console.log(` Args: ${method.args.map((arg) => arg.toHex()).join(', ')}`);
// }

if (method.section === 'sudo' && method.method.startsWith('sudo')) {
// Handle sudo extrinsics
const nestedCall = method.args[0]; // The "call" is the first argument in sudo methods
const { section, method: nestedMethod, args: nestedArgs } = apiAt.registry.createType('Call', nestedCall);

console.log(` Nested Call: ${section}.${nestedMethod}`);
const nestedDecodedArgs = nestedArgs.map((arg: any) => arg.toHuman());
console.log(` Nested Args: ${JSON.stringify(nestedDecodedArgs, null, 2)}`);
}
console.log(`${ex.method.method.toString() == "setValidationData" ? "..." : ex.toHex()}`);


});

await api.disconnect();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const getFeeMultiplier = async (api: ApiPromise, blockHash: string): Prom
return feeMultiplierCache[blockHash];
};

export const getBlockDetails = async (api: ApiPromise, blockHash: BlockHash) => {
export const getBlockDetails = async (api: ApiPromise, blockHash: BlockHash | string) => {
debug(`Querying ${blockHash}`);
const maxBlockWeight = (api.consts.system.blockWeights.maxBlock as any).toBigInt
? (api.consts.system.blockWeights.maxBlock as any).toBigInt()
Expand Down
4 changes: 2 additions & 2 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export const mapExtrinsics = async (
return event;
});

const unadjustedWeightFee = (
const unadjustedWeightFee = dispatchInfo ? (
(await api.call.transactionPaymentApi.queryWeightToFee(dispatchInfo.weight)) as any
).toBigInt();
).toBigInt() : 0n;
const lengthFee = (
(await api.call.transactionPaymentApi.queryLengthToFee(extrinsic.encodedLength)) as any
).toBigInt();
Expand Down

0 comments on commit 981138b

Please sign in to comment.