Add isInBlock, isRetracted (...) to status enum (#1852)
This commit is contained in:
@@ -107,7 +107,7 @@ export function decorateMethod <Method extends AnyFunction> (method: Method): Me
|
||||
* )
|
||||
* // subscribe to overall result
|
||||
* .subscribe(({ status }) => {
|
||||
* if (status.isFinalized) {
|
||||
* if (status.isInBlock) {
|
||||
* console.log('Completed at block hash', status.asFinalized.toHex());
|
||||
* }
|
||||
* });
|
||||
|
||||
@@ -16,17 +16,21 @@ export default class SubmittableResult implements SubmittableResultImpl {
|
||||
}
|
||||
|
||||
public get isCompleted (): boolean {
|
||||
return this.isError || this.isFinalized;
|
||||
return this.isError || this.status.isInBlock || this.status.isFinalized;
|
||||
}
|
||||
|
||||
public get isError (): boolean {
|
||||
return this.status.isDropped || this.status.isInvalid || this.status.isUsurped;
|
||||
return this.status.isDropped || this.status.isFinalityTimeout || this.status.isInvalid || this.status.isRetracted || this.status.isUsurped;
|
||||
}
|
||||
|
||||
public get isFinalized (): boolean {
|
||||
return this.status.isFinalized;
|
||||
}
|
||||
|
||||
public get isInBlock (): boolean {
|
||||
return this.status.isInBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Filters EventRecords for the specified method & section (there could be multiple)
|
||||
*/
|
||||
|
||||
@@ -256,11 +256,13 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
|
||||
}
|
||||
|
||||
private _statusObservable (status: ExtrinsicStatus): Observable<SubmittableResultImpl> {
|
||||
if (!status.isFinalized) {
|
||||
if (!status.isFinalized && !status.isInBlock) {
|
||||
return of(new SubmittableResult({ status }));
|
||||
}
|
||||
|
||||
const blockHash = status.asFinalized;
|
||||
const blockHash = status.isInBlock
|
||||
? status.asInBlock
|
||||
: status.asFinalized;
|
||||
|
||||
return combineLatest([
|
||||
this._api.rpc.chain.getBlock(blockHash),
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface SubmittableResultImpl {
|
||||
readonly isCompleted: boolean;
|
||||
readonly isError: boolean;
|
||||
readonly isFinalized: boolean;
|
||||
readonly isInBlock: boolean;
|
||||
|
||||
filterRecords (section: string, method: string): EventRecord[];
|
||||
findRecord (section: string, method: string): EventRecord | undefined;
|
||||
|
||||
@@ -11,7 +11,7 @@ export const logEvents = (done: () => {}): (r: SubmittableResult) => void =>
|
||||
({ events, status }: SubmittableResult): void => {
|
||||
console.log('Transaction status:', status.type);
|
||||
|
||||
if (status.isFinalized) {
|
||||
if (status.isInBlock) {
|
||||
console.log('Completed at block hash', status.value.toHex());
|
||||
console.log('Events:');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user