Detect session.validators for derive extraction (#1562)

* Detect session.validators for derive extraction

* Add comment

* Indexed extraction without session
This commit is contained in:
Jaco Greeff
2019-11-10 12:25:34 +01:00
committed by GitHub
parent 06418913e5
commit 3c47c3fdc3
3 changed files with 24 additions and 13 deletions
+12 -7
View File
@@ -6,19 +6,24 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { EraIndex, SessionIndex } from '@polkadot/types/interfaces';
import { DeriveSessionIndexes } from '../types';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { u32 } from '@polkadot/types';
import { createType, u32 as U32 } from '@polkadot/types';
import { drr } from '../util';
export function indexes (api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
return (): Observable<DeriveSessionIndexes> =>
api.queryMulti<[SessionIndex, EraIndex, u32]>([
api.query.session.currentIndex,
api.query.staking.currentEra,
api.query.staking.validatorCount
]).pipe(
(
// Some chains (eg. very limited node-template), does not have session
api.query.session && api.query.staking
? api.queryMulti<[SessionIndex, EraIndex, U32]>([
api.query.session.currentIndex,
api.query.staking.currentEra,
api.query.staking.validatorCount
])
: of([createType('SessionIndex', 1), createType('EraIndex', 1), new U32()])
).pipe(
map(([currentIndex, currentEra, validatorCount]): DeriveSessionIndexes => ({
currentIndex, currentEra, validatorCount
})),