diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d41cd12b0..29e44838fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # 0.52.1 +- Support linked maps for new staking interfaces +- Add derive.staking.controllers to retrieve all active controllers - Check for single instances for api and types as they are loaded (assertSingletonPackage) - Add Key type as per latest substrate master diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts new file mode 100644 index 0000000000..2372a3127a --- /dev/null +++ b/packages/api-derive/src/staking/controllers.ts @@ -0,0 +1,35 @@ +// Copyright 2017-2019 @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 { Observable, combineLatest, of } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; +import { ApiInterface$Rx } from '@polkadot/api/types'; +import { AccountId, Option } from '@polkadot/types'; + +import { drr } from '../util/drr'; + +function allBonds (api: ApiInterface$Rx, stashIds: Array) { + return combineLatest( + stashIds.map((id) => + (api.query.staking.bonded(id) as Observable>) + ) + ); +} + +/** + * @description From the list of stash accounts, retrieve the list of controllers + */ +export function controllers (api: ApiInterface$Rx) { + return (): Observable<[Array, Array>]> => + (api.query.staking.validators() as any as Observable<[Array, any]>) + .pipe( + switchMap(([stashIds]) => + combineLatest( + of(stashIds), + allBonds(api, stashIds) + ) + ), + drr() + ); +} diff --git a/packages/api-derive/src/staking/index.ts b/packages/api-derive/src/staking/index.ts index 3cfa052f6c..591ca27977 100644 --- a/packages/api-derive/src/staking/index.ts +++ b/packages/api-derive/src/staking/index.ts @@ -2,4 +2,5 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +export * from './controllers'; export * from './intentionsBalances';