diff --git a/CHANGELOG.md b/CHANGELOG.md index 19d8ebee59..ddaab9503f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # 1.7.0-beta.x +- Add support for new Substrate `state_getKeysPaged` RPC - Re-add fixed (with tests) checks for query args -- Add `staking.nextElected(): AccountId[]` derive, returning the validators for the next session +- Move `derive.staking.controllers` to `derive.staking.stashes`, reflecting actual content +- Cater for adjusted storage (non-linked maps) for `derive.staking.stashes` (with old-compat) +- Expanded `derive.staking.*` derives, including addition of `derive.staking.own*` # 1.6.2 Mar 12, 2020 diff --git a/packages/api-derive/src/index.spec.ts b/packages/api-derive/src/index.spec.ts index 096ccfa76b..9a8360f584 100644 --- a/packages/api-derive/src/index.spec.ts +++ b/packages/api-derive/src/index.spec.ts @@ -61,7 +61,7 @@ describe('derive', (): void => { testFunction(api)('session', 'sessionProgress', []); testFunction(api)('staking', 'account', []); - testFunction(api)('staking', 'controllers', []); + testFunction(api)('staking', 'stashes', []); }); describe('custom', (): void => { diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts deleted file mode 100644 index a65a2d2199..0000000000 --- a/packages/api-derive/src/staking/controllers.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017-2020 @polkadot/api-derive authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { ApiInterfaceRx } from '@polkadot/api/types'; -import { AccountId, ValidatorPrefs } from '@polkadot/types/interfaces'; -import { ITuple } from '@polkadot/types/types'; - -import { Observable, combineLatest, of } from 'rxjs'; -import { switchMap } from 'rxjs/operators'; -import { Option, Vec } from '@polkadot/types'; - -import { memo } from '../util'; - -type DeriveControllers = [AccountId[], Option[]]; - -/** - * @description From the list of stash accounts, retrieve the list of controllers - */ -export function controllers (api: ApiInterfaceRx): () => Observable { - return memo((): Observable<[AccountId[], Option[]]> => - api.query.staking.validators, Vec]>>().pipe( - switchMap(([stashIds]): Observable => - combineLatest([ - of(stashIds), - // for V2, don't return all the controllers, we call bonded at a later point - api.consts.session - ? of([]) - : api.query.staking.bonded.multi>(stashIds) - ]) - ) - )); -} diff --git a/packages/api-derive/src/staking/index.ts b/packages/api-derive/src/staking/index.ts index 0895d13997..3509a96d8e 100644 --- a/packages/api-derive/src/staking/index.ts +++ b/packages/api-derive/src/staking/index.ts @@ -9,7 +9,6 @@ export * from './erasPoints'; export * from './erasPrefs'; export * from './erasRewards'; export * from './erasSlashes'; -export * from './controllers'; export * from './electedInfo'; export * from './overview'; export * from './ownExposure'; @@ -19,4 +18,5 @@ export * from './stakerExposure'; export * from './stakerPoints'; export * from './stakerRewards'; export * from './stakerSlashes'; +export * from './stashes'; export * from './validators'; diff --git a/packages/api-derive/src/staking/stashes.ts b/packages/api-derive/src/staking/stashes.ts new file mode 100644 index 0000000000..5a9d0cede3 --- /dev/null +++ b/packages/api-derive/src/staking/stashes.ts @@ -0,0 +1,28 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { AccountId, ValidatorPrefs } from '@polkadot/types/interfaces'; +import { ITuple } from '@polkadot/types/types'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { Vec } from '@polkadot/types'; + +import { memo } from '../util'; + +/** + * @description Retrieve the list of all validator stashes + */ +export function stashes (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => + api.query.staking.validators.creator.meta.type.asMap.linked.isTrue + ? api.query.staking.validators, Vec]>>().pipe( + map(([stashIds]) => stashIds) + ) + : api.query.staking.validators.keys().pipe( + map((keys) => keys.map((key) => key.args[0] as AccountId)) + ) + ); +}