UNPKG

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