UNPKG

889 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/api authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { l } from "./logging.js";
4export function filterEvents(txHash, {
5 block: {
6 extrinsics,
7 header
8 }
9}, allEvents, status) {
10 // extrinsics to hashes
11 for (const [txIndex, x] of extrinsics.entries()) {
12 if (x.hash.eq(txHash)) {
13 return {
14 events: allEvents.filter(({
15 phase
16 }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(txIndex)),
17 txIndex
18 };
19 }
20 } // if we do get the block after finalized, it _should_ be there
21 // only warn on filtering with isInBlock (finalization finalizes after)
22
23
24 if (status.isInBlock) {
25 const allHashes = extrinsics.map(x => x.hash.toHex());
26 l.warn(`block ${header.hash.toHex()}: Unable to find extrinsic ${txHash.toHex()} inside ${allHashes.join(', ')}`);
27 }
28
29 return {};
30}
\No newline at end of file