From a863e5eb958b8c40a5b21c87b36e225a9519b688 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 17 Mar 2020 19:22:16 +0100 Subject: [PATCH] Non-array nominators --- CHANGELOG.md | 2 +- packages/api-derive/src/staking/query.ts | 9 +++++++-- packages/api/src/submittable/createClass.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61a1bac84a..bd9b56fb8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.7.1 Mar 17, 2020 -- **Important** Current versions of Polkadot/Substrate have dropped support for linked maps on storage entries. If you are using these queries to retriev all entries, for instance `staking.{nominators,validators}()` and using an upgraded chain, you need to swap to retrieving entries via `.entries()` or `.keys()` for the keys. +- **Important** Current versions of Polkadot/Substrate have dropped support for linked maps on storage entries. If you are using these queries to retrieve all entries, for instance `staking.{nominators,validators}()` and using an upgraded chain, you need to swap to retrieving entries via `.entries()` or `.keys()` for the keys. - Pull in support and types for latest Polkadot/Substrate - Add support for the new Substrate `state_getKeysPaged` RPC, including use in storage keys - Move `derive.staking.controllers` to `derive.staking.stashes`, reflecting actual content diff --git a/packages/api-derive/src/staking/query.ts b/packages/api-derive/src/staking/query.ts index 89645c8ff4..34e87d2fc7 100644 --- a/packages/api-derive/src/staking/query.ts +++ b/packages/api-derive/src/staking/query.ts @@ -13,7 +13,7 @@ import { Option, Vec } from '@polkadot/types'; import { memo } from '../util'; -type MultiResult = [Option, Option>, RewardDestination, ITuple<[ValidatorPrefs]>, Option, Exposure]; +type MultiResult = [Option, Option> | Option, RewardDestination, ITuple<[ValidatorPrefs]>, Option, Exposure]; function unwrapSessionIds (stashId: AccountId, queuedKeys: [AccountId, Keys][], nextKeys: Option): { nextSessionIds: AccountId[]; sessionIds: AccountId[] } { const sessionIds = (queuedKeys.find(([currentId]): boolean => @@ -57,6 +57,7 @@ function retrieveCurr (api: ApiInterfaceRx, stashId: AccountId): Observable>, MultiResult]): Observable { const controllerId = controllerIdOpt.unwrapOr(null); + const nominators = nominatorsOpt.unwrapOr(null); return controllerId ? api.query.staking.ledger(controllerId).pipe( @@ -64,7 +65,11 @@ function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKey accountId: stashId, controllerId, exposure, - nominators: nominatorsOpt.unwrapOr([{ targets: [] }])[0].targets, + nominators: nominators + ? Array.isArray(nominators) + ? nominators[0].targets + : nominators.targets + : [], rewardDestination, stakingLedger: stakingLedgerOpt.unwrapOr(undefined), stashId, diff --git a/packages/api/src/submittable/createClass.ts b/packages/api/src/submittable/createClass.ts index bfe132f518..e0ef94c32d 100644 --- a/packages/api/src/submittable/createClass.ts +++ b/packages/api/src/submittable/createClass.ts @@ -166,9 +166,9 @@ export default function createClass ({ api, apiType, #makeSignOptions = (options: Partial, extras: { blockHash?: Hash; era?: ExtrinsicEra; nonce?: Index }): SignatureOptions => { return { blockHash: api.genesisHash, + genesisHash: api.genesisHash, ...options, ...extras, - genesisHash: api.genesisHash, runtimeVersion: api.runtimeVersion, version: api.extrinsicType } as SignatureOptions;