Add new staking types, support derives (#1828)

* Add new staking types

* StakingLedgerTo213 - StakingLedgerTo223

* StakingLedgerTo223 in polkadot (dev)

* Add derive activeEra

* Map Ponts -> RewardPoints

* StakingLedger override CHANGELOG

* Cleanups

* Apparent CC dupes (don't see it, but cleanup useul)

* Cleanup result formatting for indexes

* Map nextElected -> validators

* Fix StakingLedger to current

* Merge CHANGELOG

* Mention derive staking updates

* Mark derive changes as breaking
This commit is contained in:
Jaco Greeff
2020-02-24 16:52:48 +01:00
committed by GitHub
parent 64aa4dcc1c
commit cbc14cc291
14 changed files with 394 additions and 206 deletions
+24 -6
View File
@@ -2,15 +2,31 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EraPoints } from '@polkadot/types/interfaces';
import { AccountId, EraIndex, EraPoints, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedStakingOverview } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { createType } from '@polkadot/types';
import { memo } from '../util';
function retrievePointsPrev (api: ApiInterfaceRx, activeEra: EraIndex, currentElected: AccountId[]): Observable<EraRewardPoints> {
return api.query.staking.currentEraPointsEarned<EraPoints>(activeEra).pipe(
map(({ individual, total }): EraRewardPoints =>
createType(api.registry, 'EraRewardPoints', {
total,
individual: new Map<AccountId, RewardPoint>(
individual
.map((points): RewardPoint => createType(api.registry, 'RewardPoint', points))
.map((points, index): [AccountId, RewardPoint] => [currentElected[index], points])
)
})
)
);
}
/**
* @description Retrieve the staking overview, including elected and points earned
*/
@@ -20,14 +36,16 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
api.derive.session.indexes(),
api.derive.staking.validators()
]).pipe(
switchMap(([{ currentEra, currentIndex, validatorCount }, { currentElected, validators }]) =>
switchMap(([indexes, { nextElected, validators }]) =>
combineLatest([
of({ currentElected, currentEra, currentIndex, validators, validatorCount }),
api.query.staking.currentEraPointsEarned<EraPoints>(currentEra)
of({ ...indexes, nextElected, validators }),
api.query.staking.erasRewardPoints
? api.query.staking.erasRewardPoints<EraRewardPoints>(indexes.activeEra)
: retrievePointsPrev(api, indexes.activeEra, nextElected)
])
),
map(([{ currentElected, currentEra, currentIndex, validators, validatorCount }, eraPoints]): DerivedStakingOverview => ({
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
map(([info, eraPoints]): DerivedStakingOverview => ({
...info, eraPoints
}))
));
}