Remove support for pre-v2 staking (#2980)

* Remove support for pre-v2 staking

* Adjust with util array functions

* Remove old enumset support

* Empty controller

* withController flag
This commit is contained in:
Jaco Greeff
2020-12-24 08:32:03 +01:00
committed by GitHub
parent 47f2ee725f
commit d6b2b4a1a3
24 changed files with 239 additions and 402 deletions
+1 -31
View File
@@ -7,16 +7,11 @@ import type { ActiveEraInfo, EraIndex, Moment, SessionIndex } from '@polkadot/ty
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSessionIndexes } from '../types';
import { isFunction } from '@polkadot/util';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
function isEraOpt (era: Option<EraIndex> | EraIndex): era is Option<EraIndex> {
return isFunction((era as Option<EraIndex>).unwrapOrDefault);
}
// parse into Indexes
function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorCount]: [EraIndex, Option<Moment>, EraIndex, SessionIndex, u32]): DeriveSessionIndexes {
return {
@@ -28,29 +23,6 @@ function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorC
};
}
// query for previous V2
function queryNoActive (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
return api.queryMulti<[Option<EraIndex> | EraIndex, SessionIndex, u32]>([
api.query.staking.currentEra,
api.query.session.currentIndex,
api.query.staking.validatorCount
]).pipe(
map(([currentEraOpt, currentIndex, validatorCount]): DeriveSessionIndexes => {
const currentEra = isEraOpt(currentEraOpt)
? currentEraOpt.unwrapOrDefault()
: currentEraOpt;
return parse([
currentEra,
api.registry.createType('Option<Moment>'),
currentEra,
currentIndex,
validatorCount
]);
})
);
}
// query based on latest
function query (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
return api.queryMulti<[Option<ActiveEraInfo>, Option<EraIndex>, SessionIndex, u32]>([
@@ -87,9 +59,7 @@ function empty (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
return memo(instanceId, (): Observable<DeriveSessionIndexes> =>
api.query.session && api.query.staking
? isFunction(api.query.staking.activeEra)
? query(api)
: queryNoActive(api)
? query(api)
: empty(api)
);
}
+1 -18
View File
@@ -7,7 +7,6 @@ import type { SessionIndex } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
import { isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
@@ -57,29 +56,13 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultS
);
}
function queryBabeNoHistory (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultSlotsFlat]> {
return combineLatest([
api.derive.session.info(),
api.queryMulti<ResultSlotsFlat>([
api.query.babe.currentSlot,
api.query.babe.epochIndex,
api.query.babe.genesisSlot,
api.query.staking.currentEraStartSessionIndex
])
]);
}
/**
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
*/
export function progress (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionProgress> {
return memo(instanceId, (): Observable<DeriveSessionProgress> =>
api.consts.babe
? (
isFunction(api.query.staking.erasStartSessionIndex)
? queryBabe(api) // 2.x with Babe
: queryBabeNoHistory(api)
).pipe(
? queryBabe(api).pipe(
map(([info, slots]: [DeriveSessionInfo, ResultSlotsFlat]): DeriveSessionProgress =>
createDerive(api, info, slots)
)