diff --git a/CHANGELOG.md b/CHANGELOG.md index 21edc82a54..72c967e97d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes: - Re-add isPedantic check on storage decoding +- Adjust capability detection (only on full-known historic `AccountInfo`) - Additional Xcm types diff --git a/packages/api/src/base/capabilities.ts b/packages/api/src/base/capabilities.ts index d9174f0867..9d169ff2a8 100644 --- a/packages/api/src/base/capabilities.ts +++ b/packages/api/src/base/capabilities.ts @@ -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 { +function mapCapabilities ({ accountIdLength }: Constants, [leasePeriodsPerSlot, slotRangeCount]: ExtractedC, [systemRefcount32, systemRefcountDual, systemRefcountTriple, stakingVersion]: ExtractedQ, [keys]: ExtractedR): Partial { const types: Partial = {}; // 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, diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 24fca4d091..bc5d9da445 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -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}`); } } } diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 79744acb63..d5aeb8933f 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -69,6 +69,7 @@ export class MockProvider implements ProviderInterface { system_chain: (): string => 'mockChain', system_name: (): string => 'mockClient', system_properties: (): Record => ({ ss58Format: 42 }), + system_upgradedToTripleRefCount: () => this.registry.createType('bool', true), system_version: (): string => '9.8.7' };