Adjust capability detection (#3473)
* Adjust capability detection * Adjust types * Fully known isU32
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
Changes:
|
||||
|
||||
- Re-add isPedantic check on storage decoding
|
||||
- Adjust capability detection (only on full-known historic `AccountInfo`)
|
||||
- Additional Xcm types
|
||||
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -438,27 +438,23 @@ export class RpcCore {
|
||||
? ''
|
||||
: ` entry ${entryIndex}:`;
|
||||
|
||||
if (meta.modifier.isOptional) {
|
||||
let inner = null;
|
||||
|
||||
if (!isEmpty) {
|
||||
try {
|
||||
inner = createTypeUnsafe(registry, type, [input], { blockHash, isPedantic: true });
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
const option = new Option(registry, createClass(registry, type), inner);
|
||||
|
||||
if (blockHash) {
|
||||
option.createdAtHash = registry.createType('Hash', blockHash);
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
try {
|
||||
if (meta.modifier.isOptional) {
|
||||
let inner = null;
|
||||
|
||||
if (!isEmpty) {
|
||||
inner = createTypeUnsafe(registry, type, [input], { blockHash, isPedantic: true });
|
||||
}
|
||||
|
||||
const option = new Option(registry, createClass(registry, type), inner);
|
||||
|
||||
if (blockHash) {
|
||||
option.createdAtHash = registry.createType('Hash', blockHash);
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
return createTypeUnsafe(registry, type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
@@ -467,9 +463,7 @@ export class RpcCore {
|
||||
: input
|
||||
], { blockHash, isPedantic: true });
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
|
||||
|
||||
return createTypeUnsafe(registry, 'Raw', [input], { blockHash });
|
||||
throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ export class MockProvider implements ProviderInterface {
|
||||
system_chain: (): string => 'mockChain',
|
||||
system_name: (): string => 'mockClient',
|
||||
system_properties: (): Record<string, number | string> => ({ ss58Format: 42 }),
|
||||
system_upgradedToTripleRefCount: () => this.registry.createType('bool', true),
|
||||
system_version: (): string => '9.8.7'
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user