Skip to content

Commit

Permalink
Merge pull request #8 from paritytech/mh-queryInfo-nonce
Browse files Browse the repository at this point in the history
Extrinsic queryInfo, account nonce
  • Loading branch information
maciejhirsz committed Feb 5, 2020
2 parents 9b6a269 + b13c760 commit f9037e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-rpc-proxy",
"version": "0.0.0",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 9 additions & 3 deletions src/ApiHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export default class ApiHandler {
});

const defaultSuccess = typeof events === 'string' ? events : false;
const extrinsics = block.extrinsics.map((extrinsic) => {
const queryInfo = await Promise.all(block.extrinsics.map((extrinsic) => {
return api.rpc.payment.queryInfo(extrinsic.toHex(), hash);
}));
const extrinsics = block.extrinsics.map((extrinsic, idx) => {
const { method, nonce, signature, signer, isSigned, tip, args } = extrinsic;
const hash = u8aToHex(blake2AsU8a(extrinsic.toU8a(), 256));
const info = queryInfo[idx];

return {
method: `${method.sectionName}.${method.methodName}`,
Expand All @@ -60,6 +64,7 @@ export default class ApiHandler {
args,
tip,
hash,
info,
events: [] as SantiziedEvent[],
success: defaultSuccess,
};
Expand Down Expand Up @@ -105,19 +110,20 @@ export default class ApiHandler {
async fetchBalance(hash: BlockHash, address: string) {
const { api } = this;

const [header, free, reserved, locks] = await Promise.all([
const [header, free, reserved, locks, nonce] = await Promise.all([
api.rpc.chain.getHeader(hash),
api.query.balances.freeBalance.at(hash, address),
api.query.balances.reservedBalance.at(hash, address),
api.query.balances.locks.at(hash, address),
api.query.system.accountNonce.at(hash, address),
]);

const at = {
hash,
height: header.number,
};

return { at, free, reserved, locks };
return { at, nonce, free, reserved, locks };
}

async fetchEvents(hash: BlockHash): Promise<EventRecord[] | string> {
Expand Down

0 comments on commit f9037e6

Please sign in to comment.