Expose blockNumber via filterEvents function (#5394)

* Expose `blockNumber` via filterEvents function

* Address eslint issues plus add guard for Compact type
This commit is contained in:
Ken Vu
2023-01-05 11:21:37 +02:00
committed by GitHub
parent f9df7a5c0d
commit e792eba587
3 changed files with 12 additions and 5 deletions
+5 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DispatchError, DispatchInfo, EventRecord, ExtrinsicStatus, Hash } from '@polkadot/types/interfaces';
import type { BlockNumber, DispatchError, DispatchInfo, EventRecord, ExtrinsicStatus, Hash } from '@polkadot/types/interfaces';
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
import type { SubmittableResultValue } from './types';
@@ -49,7 +49,9 @@ export class SubmittableResult implements ISubmittableResult {
public readonly txIndex?: number;
constructor ({ dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }: SubmittableResultValue) {
public readonly blockNumber?: BlockNumber;
constructor ({ blockNumber, dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }: SubmittableResultValue) {
this.dispatchError = dispatchError || extractError(events);
this.dispatchInfo = dispatchInfo || extractInfo(events);
this.events = events || [];
@@ -57,6 +59,7 @@ export class SubmittableResult implements ISubmittableResult {
this.status = status;
this.txHash = txHash;
this.txIndex = txIndex;
this.blockNumber = blockNumber;
}
public get isCompleted (): boolean {
+5 -2
View File
@@ -1,15 +1,18 @@
// Copyright 2017-2023 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { EventRecord, ExtrinsicStatus, H256, SignedBlock } from '@polkadot/types/interfaces';
import type { BlockNumber, EventRecord, ExtrinsicStatus, H256, SignedBlock } from '@polkadot/types/interfaces';
import { isCompact } from '@polkadot/util';
import { l } from './logging';
export function filterEvents (txHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): { events?: EventRecord[], txIndex?: number } {
export function filterEvents (txHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): { events?: EventRecord[], txIndex?: number, blockNumber?: BlockNumber } {
// extrinsics to hashes
for (const [txIndex, x] of extrinsics.entries()) {
if (x.hash.eq(txHash)) {
return {
blockNumber: isCompact<BlockNumber>(header.number) ? header.number.unwrap() : header.number,
events: allEvents.filter(({ phase }) =>
phase.isApplyExtrinsic &&
phase.asApplyExtrinsic.eqn(txIndex)