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:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user