UNPKG

1.16 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.filterEvents = void 0;
4const util_1 = require("@polkadot/util");
5const logging_js_1 = require("./logging.js");
6function filterEvents(txHash, { block: { extrinsics, header } }, allEvents, status) {
7 // extrinsics to hashes
8 for (const [txIndex, x] of extrinsics.entries()) {
9 if (x.hash.eq(txHash)) {
10 return {
11 blockNumber: (0, util_1.isCompact)(header.number) ? header.number.unwrap() : header.number,
12 events: allEvents.filter(({ phase }) => phase.isApplyExtrinsic &&
13 phase.asApplyExtrinsic.eqn(txIndex)),
14 txIndex
15 };
16 }
17 }
18 // if we do get the block after finalized, it _should_ be there
19 // only warn on filtering with isInBlock (finalization finalizes after)
20 if (status.isInBlock) {
21 const allHashes = extrinsics.map((x) => x.hash.toHex());
22 logging_js_1.l.warn(`block ${header.hash.toHex()}: Unable to find extrinsic ${txHash.toHex()} inside ${allHashes.join(', ')}`);
23 }
24 return {};
25}
26exports.filterEvents = filterEvents;