Expose txIndex on extrinsic results (#4556)

* Expose txIndex on extrinsic results

* CHANGELOG

* optional txIndex

* Adjust result
This commit is contained in:
Jaco
2022-02-10 10:20:57 +02:00
committed by GitHub
parent 898d1593f3
commit f169ca08a8
6 changed files with 19 additions and 9 deletions
+2
View File
@@ -5,11 +5,13 @@
Contributed:
- Add `isHistoric` flag to ETH RPCs (Thanks to https://github.com/stwiname)
- Align contract instantiate types with Substrate (Thanks to https://github.com/kwingram25)
Changes:
- Adjust map header output type with lookup id
- Re-enable all `BitVec` tests for `toU8a`
- Expose `txIndex` as event index on extrinsic results
- Allow inspection of Codec encoding (experimental)
- Allow inspection of storage key encoding (experimental)
@@ -66,6 +66,7 @@ export interface SubmittableResultValue {
internalError?: Error;
status: ExtrinsicStatus;
txHash: Hash;
txIndex?: number;
}
export interface SubmittableExtrinsic<ApiType extends ApiTypes, R extends ISubmittableResult = ISubmittableResult> extends Extrinsic {
+4 -1
View File
@@ -47,13 +47,16 @@ export class SubmittableResult implements ISubmittableResult {
public readonly txHash: Hash;
constructor ({ dispatchError, dispatchInfo, events, internalError, status, txHash }: SubmittableResultValue) {
public readonly txIndex?: number;
constructor ({ dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }: SubmittableResultValue) {
this.dispatchError = dispatchError || extractError(events);
this.dispatchInfo = dispatchInfo || extractInfo(events);
this.events = events || [];
this.internalError = internalError;
this.status = status;
this.txHash = txHash;
this.txIndex = txIndex;
}
public get isCompleted (): boolean {
+1 -1
View File
@@ -248,7 +248,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorate
return api.derive.tx.events(blockHash).pipe(
map(({ block, events }): ISubmittableResult =>
this.#transformResult(new SubmittableResult({
events: filterEvents(txHash, block, events, status),
...filterEvents(txHash, block, events, status),
status,
txHash
}))
+10 -7
View File
@@ -5,14 +5,17 @@ import type { EventRecord, ExtrinsicStatus, H256, SignedBlock } from '@polkadot/
import { l } from './logging';
export function filterEvents (txHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): EventRecord[] | undefined {
export function filterEvents (txHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): { events?: EventRecord[], txIndex?: number } {
// extrinsics to hashes
for (const [index, x] of extrinsics.entries()) {
for (const [txIndex, x] of extrinsics.entries()) {
if (x.hash.eq(txHash)) {
return allEvents.filter(({ phase }) =>
// only ApplyExtrinsic has the extrinsic index
phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(index)
);
return {
events: allEvents.filter(({ phase }) =>
phase.isApplyExtrinsic &&
phase.asApplyExtrinsic.eqn(txIndex)
),
txIndex
};
}
}
@@ -24,5 +27,5 @@ export function filterEvents (txHash: H256, { block: { extrinsics, header } }: S
l.warn(`block ${header.hash.toHex()}: Unable to find extrinsic ${txHash.toHex()} inside ${allHashes.join(', ')}`);
}
return undefined;
return {};
}
+1
View File
@@ -22,6 +22,7 @@ export interface ISubmittableResult {
readonly isInBlock: boolean;
readonly isWarning: boolean;
readonly txHash: Hash;
readonly txIndex?: number;
filterRecords (section: string, method: string): EventRecord[];
findRecord (section: string, method: string): EventRecord | undefined;