As gettters, as{ContainedType} to EnumType (convenience) (#579)

* As as{ContainedType} to EnumType (convenience)

* Use as inside phase filter

* asFinalised in SubmittableExtrinsic

* Cleanup imports (lint)

* Cleanup imports (linting)
This commit is contained in:
Jaco Greeff
2019-01-12 16:05:21 +01:00
committed by GitHub
parent fa650277fe
commit 8f698d7964
8 changed files with 138 additions and 5 deletions
@@ -26,7 +26,7 @@ export default class SubmittableExtrinsic extends Extrinsic {
let events: Array<any> | undefined = undefined;
if (status.type === 'Finalised') {
const blockHash = status.value as Hash;
const blockHash = status.asFinalised;
const signedBlock: SignedBlock = await this._api.rpc.chain.getBlock(blockHash);
const allEvents: Array<EventRecord> = await this._api.query.system.events.at(blockHash) as any;
+2 -2
View File
@@ -9,7 +9,7 @@ import { ApiRxInterface } from './types';
import { Observable, of, combineLatest } from 'rxjs';
import { first, map, switchMap } from 'rxjs/operators';
import { Extrinsic, ExtrinsicStatus, Hash, Index, Method } from '@polkadot/types/index';
import { Extrinsic, ExtrinsicStatus, Index, Method } from '@polkadot/types/index';
import filterEvents from '../util/filterEvents';
@@ -30,7 +30,7 @@ export default class SubmittableExtrinsic extends Extrinsic {
});
}
const blockHash = status.value as Hash;
const blockHash = status.asFinalised;
return combineLatest(
this._api.rpc.chain.getBlock(blockHash),
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventRecord, Hash, SignedBlock, u32 } from '@polkadot/types/index';
import { EventRecord, Hash, SignedBlock } from '@polkadot/types/index';
import l from './logging';
@@ -22,6 +22,6 @@ export default function filterEvents (extHash: Hash, { block: { extrinsics, head
return allEvents.filter(({ phase }) =>
// only ApplyExtrinsic has the extrinsic index
phase.type === 'ApplyExtrinsic' && (phase.value as u32).eqn(index)
phase.type === 'ApplyExtrinsic' && phase.asApplyExtrinsic.eqn(index)
);
}
+14
View File
@@ -61,6 +61,20 @@ export class ValidityAttestation extends EnumType<Null | ImplicitCandidateSignat
ExplicitCandidateSignature // 2
}, value);
}
/**
* @description Returns the item as a [[ExplicitCandidateSignature]]
*/
get asExplicitCandidateSignature (): ExplicitCandidateSignature {
return this.value as ExplicitCandidateSignature;
}
/**
* @description Returns the item as a [[ImplicitCandidateSignature]]
*/
get asImplicitCandidateSignature (): ImplicitCandidateSignature {
return this.value as ImplicitCandidateSignature;
}
}
export class ValidityVote extends Tuple.with({ SessionKey, ValidityAttestation }) {
+28
View File
@@ -79,6 +79,34 @@ export class DigestItem extends EnumType<AuthoritiesChange | ChangesTrieRoot | O
Seal
}, value);
}
/**
* @description Returns the item as a [[AuthoritiesChange]]
*/
get asAuthoritiesChange (): AuthoritiesChange {
return this.value as AuthoritiesChange;
}
/**
* @description Returns the item as a [[ChangesTrieRoot]]
*/
get asChangesTrieRoot (): ChangesTrieRoot {
return this.value as ChangesTrieRoot;
}
/**
* @description Returns the item as a [[Other]]
*/
get asOther (): Other {
return this.value as Other;
}
/**
* @description Returns the item as a [[Seal]]
*/
get asSeal (): Seal {
return this.value as Seal;
}
}
/**
+14
View File
@@ -36,6 +36,20 @@ export class Phase extends EnumType<ApplyExtrinsic | Finalization> {
Finalization
}, value, index);
}
/**
* @description Returns the item as a [[ApplyExtrinsic]]
*/
get asApplyExtrinsic (): ApplyExtrinsic {
return this.value as ApplyExtrinsic;
}
/**
* @description Returns the item as a [[Finalization]]
*/
get asFinalization (): Finalization {
return this.value as Finalization;
}
}
/**
+49
View File
@@ -81,4 +81,53 @@ export default class ExtrinsicStatus extends EnumType<Future | Ready | Finalised
Invalid
}, value, index);
}
/**
* @description Returns the item as a [[Broadcast]]
*/
get asBroadcast (): Broadcast {
return this.value as Broadcast;
}
/**
* @description Returns the item as a [[Dropped]]
*/
get asDropped (): Dropped {
return this.value as Dropped;
}
/**
* @description Returns the item as a [[Finalised]]
*/
get asFinalised (): Finalised {
return this.value as Finalised;
}
/**
* @description Returns the item as a [[Future]]
*/
get asFuture (): Future {
return this.value as Future;
}
/**
* @description Returns the item as a [[Invalid]]
*/
get asInvalid (): Invalid {
return this.value as Invalid;
}
/**
* @description Returns the item as a [[Ready]]
*/
get asReady (): Ready {
return this.value as Ready;
}
/**
* @description Returns the item as a [[Usurped]]
*/
get asUsurped (): Usurped {
return this.value as Usurped;
}
}
+28
View File
@@ -127,6 +127,34 @@ export class MisbehaviorKind extends EnumType<BftProposeOutOfTurn | BftDoublePro
BftDoubleCommit
}, value, index);
}
/**
* @description Returns the item as a [[BftDoubleCommit]]
*/
get asBftDoubleCommit (): BftDoubleCommit {
return this.value as BftDoubleCommit;
}
/**
* @description Returns the item as a [[BftDoublePrepare]]
*/
get asBftDoublePrepare (): BftDoublePrepare {
return this.value as BftDoublePrepare;
}
/**
* @description Returns the item as a [[BftDoublePropose]]
*/
get asBftDoublePropose (): BftDoublePropose {
return this.value as BftDoublePropose;
}
/**
* @description Returns the item as a [[BftProposeOutOfTurn]]
*/
get asBftProposeOutOfTurn (): BftProposeOutOfTurn {
return this.value as BftProposeOutOfTurn;
}
}
type MisbehaviorReportValue = {