Adjust capability detection (#3473)

* Adjust capability detection

* Adjust types

* Fully known isU32
This commit is contained in:
Jaco
2021-05-03 15:24:31 +02:00
committed by GitHub
parent c8c535834e
commit a6fcba95de
4 changed files with 22 additions and 31 deletions
+3 -8
View File
@@ -11,7 +11,7 @@ import { combineLatest, Observable, of } from '@polkadot/x-rxjs';
import { map, take } from '@polkadot/x-rxjs/operators';
// the order and types needs to map with the all array setup below
type ExtractedQ = [u32 | null, bool | null, bool | null, bool | null, Releases | null];
type ExtractedQ = [bool | null, bool | null, bool | null, Releases | null];
type ExtractedR = [Raw | null];
@@ -42,7 +42,7 @@ interface Constants {
const NumberMap = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];
function mapCapabilities ({ accountIdLength }: Constants, [leasePeriodsPerSlot, slotRangeCount]: ExtractedC, [systemBlockNumber, systemRefcount32, systemRefcountDual, systemRefcountTriple, stakingVersion]: ExtractedQ, [keys]: ExtractedR): Partial<DetectedTypes> {
function mapCapabilities ({ accountIdLength }: Constants, [leasePeriodsPerSlot, slotRangeCount]: ExtractedC, [systemRefcount32, systemRefcountDual, systemRefcountTriple, stakingVersion]: ExtractedQ, [keys]: ExtractedR): Partial<DetectedTypes> {
const types: Partial<DetectedTypes> = {};
// AccountInfo
@@ -50,12 +50,8 @@ function mapCapabilities ({ accountIdLength }: Constants, [leasePeriodsPerSlot,
types.AccountInfo = 'AccountInfoWithTripleRefCount';
} else if (systemRefcountDual && systemRefcountDual.isTrue) {
types.AccountInfo = 'AccountInfoWithDualRefCount';
} else if (systemBlockNumber && !systemBlockNumber.isEmpty) {
} else if (systemRefcount32 && systemRefcount32.isTrue) {
types.AccountInfo = 'AccountInfoWithRefCount';
if (!systemRefcount32 || systemRefcount32.isFalse) {
types.RefCount = 'u8';
}
}
// ValidatorPrefs
@@ -139,7 +135,6 @@ export function detectedCapabilities (api: ApiInterfaceRx, blockHash?: Uint8Arra
api.consts.auctions?.slotRangeCount
]);
const queries = filterEntries([
api.query.system?.number,
api.query.system?.upgradedToU32RefCount,
api.query.system?.upgradedToDualRefCount,
api.query.system?.upgradedToTripleRefCount,