1 | import { isCompact } from '@polkadot/util';
|
2 | import { l } from './logging.js';
|
3 | export function filterEvents(txHash, { block: { extrinsics, header } }, allEvents, status) {
|
4 |
|
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 |
|
16 |
|
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 | }
|