Derive controllers from stashes (#806)
* Derive controllers from stashes * Fix combineLatest import
This commit is contained in:
@@ -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<AccountId>) {
|
||||
return combineLatest(
|
||||
stashIds.map((id) =>
|
||||
(api.query.staking.bonded(id) as Observable<Option<AccountId>>)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the list of stash accounts, retrieve the list of controllers
|
||||
*/
|
||||
export function controllers (api: ApiInterface$Rx) {
|
||||
return (): Observable<[Array<AccountId>, Array<Option<AccountId>>]> =>
|
||||
(api.query.staking.validators() as any as Observable<[Array<AccountId>, any]>)
|
||||
.pipe(
|
||||
switchMap(([stashIds]) =>
|
||||
combineLatest(
|
||||
of(stashIds),
|
||||
allBonds(api, stashIds)
|
||||
)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user