Consistency in Derive* type names (#2106)

This commit is contained in:
Jaco Greeff
2020-03-27 15:34:41 +01:00
committed by GitHub
parent 97ab7fcf2f
commit bb14471e60
27 changed files with 167 additions and 167 deletions
+9 -9
View File
@@ -4,7 +4,7 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Balance, BlockNumber, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces';
import { DerivedSessionInfo, DerivedStakingAccount, DerivedStakingQuery, DerivedUnlocking } from '../types';
import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlocking } from '../types';
import BN from 'bn.js';
import { Observable, combineLatest } from 'rxjs';
@@ -28,7 +28,7 @@ function groupByEra (list: UnlockChunk[]): Record<string, BN> {
}
// calculate the remaining blocks in a specific unlock era
function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSessionInfo): BlockNumber {
function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DeriveSessionInfo): BlockNumber {
const remaining = era.sub(sessionInfo.currentEra);
// on the Rust side the current-era >= era-for-unlock (removal done on >)
@@ -41,7 +41,7 @@ function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSess
);
}
function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): DerivedUnlocking[] | undefined {
function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): DeriveUnlocking[] | undefined {
if (isUndefined(stakingLedger)) {
return undefined;
}
@@ -56,7 +56,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
// group the unlock chunks that have the same era and sum their values
const groupedResult = groupByEra(unlockingChunks);
const results = Object.entries(groupedResult).map(([eraString, value]): DerivedUnlocking => ({
const results = Object.entries(groupedResult).map(([eraString, value]): DeriveUnlocking => ({
value: api.registry.createType('Balance', value),
remainingBlocks: remainingBlocks(api, new BN(eraString), sessionInfo)
}));
@@ -64,7 +64,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
return results.length ? results : undefined;
}
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): Balance {
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance {
if (isUndefined(stakingLedger)) {
return api.registry.createType('Balance');
}
@@ -76,7 +76,7 @@ function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | unde
}, new BN(0)));
}
function parseResult (api: ApiInterfaceRx, sessionInfo: DerivedSessionInfo, query: DerivedStakingQuery): DerivedStakingAccount {
function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, query: DeriveStakingQuery): DeriveStakingAccount {
return {
...query,
redeemable: redeemableSum(api, query.stakingLedger, sessionInfo),
@@ -87,13 +87,13 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DerivedSessionInfo, quer
/**
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
*/
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DerivedStakingAccount> {
return memo((accountId: Uint8Array | string): Observable<DerivedStakingAccount> =>
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
return memo((accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
combineLatest([
api.derive.session.info(),
api.derive.staking.query(accountId)
]).pipe(
map(([sessionInfo, query]: [DerivedSessionInfo, DerivedStakingQuery]) =>
map(([sessionInfo, query]: [DeriveSessionInfo, DeriveStakingQuery]) =>
parseResult(api, sessionInfo, query))
));
}
@@ -4,27 +4,27 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId } from '@polkadot/types/interfaces';
import { DerivedStakingQuery, DerivedStakingElected } from '../types';
import { DeriveStakingQuery, DeriveStakingElected } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { memo } from '../util';
export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
return memo((): Observable<DerivedStakingElected> =>
export function electedInfo (api: ApiInterfaceRx): () => Observable<DeriveStakingElected> {
return memo((): Observable<DeriveStakingElected> =>
api.derive.staking.validators().pipe(
switchMap(({ nextElected }): Observable<[AccountId[], DerivedStakingQuery[]]> =>
switchMap(({ nextElected }): Observable<[AccountId[], DeriveStakingQuery[]]> =>
combineLatest([
of(nextElected),
combineLatest(
nextElected.map((accountId): Observable<DerivedStakingQuery> =>
nextElected.map((accountId): Observable<DeriveStakingQuery> =>
api.derive.staking.query(accountId)
)
)
])
),
map(([nextElected, info]): DerivedStakingElected => ({
map(([nextElected, info]): DeriveStakingElected => ({
info,
nextElected
}))
+4 -4
View File
@@ -4,7 +4,7 @@
import { AccountId, EraPoints, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedStakingOverview } from '../types';
import { DeriveStakingOverview } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
@@ -29,8 +29,8 @@ function retrievePointsPrev (api: ApiInterfaceRx, currentElected: AccountId[]):
/**
* @description Retrieve the staking overview, including elected and points earned
*/
export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> {
return memo((): Observable<DerivedStakingOverview> =>
export function overview (api: ApiInterfaceRx): () => Observable<DeriveStakingOverview> {
return memo((): Observable<DeriveStakingOverview> =>
combineLatest([
api.derive.session.indexes(),
api.derive.staking.validators()
@@ -45,7 +45,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
: of(api.registry.createType('EraRewardPoints'))
])
),
map(([info, eraPoints]): DerivedStakingOverview => ({
map(([info, eraPoints]): DeriveStakingOverview => ({
...info, eraPoints
}))
));
+8 -8
View File
@@ -5,7 +5,7 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, Exposure, Keys, Nominations, RewardDestination, ValidatorPrefs } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DerivedStakingQuery } from '../types';
import { DeriveStakingQuery } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
@@ -55,13 +55,13 @@ function retrieveCurr (api: ApiInterfaceRx, stashId: AccountId): Observable<Mult
);
}
function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKeys, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]]: [Vec<ITuple<[AccountId, Keys]>>, MultiResult]): Observable<DerivedStakingQuery> {
function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKeys, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]]: [Vec<ITuple<[AccountId, Keys]>>, MultiResult]): Observable<DeriveStakingQuery> {
const controllerId = controllerIdOpt.unwrapOr(null);
const nominators = nominatorsOpt.unwrapOr(null);
return controllerId
? api.query.staking.ledger(controllerId).pipe(
map((stakingLedgerOpt): DerivedStakingQuery => ({
map((stakingLedgerOpt): DeriveStakingQuery => ({
accountId: stashId,
controllerId,
exposure,
@@ -85,8 +85,8 @@ function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKey
/**
* @description From a stash, retrieve the controllerId and all relevant details
*/
export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DerivedStakingQuery> {
return memo((accountId: Uint8Array | string): Observable<DerivedStakingQuery> => {
export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingQuery> {
return memo((accountId: Uint8Array | string): Observable<DeriveStakingQuery> => {
const stashId = api.registry.createType('AccountId', accountId);
return combineLatest([
@@ -95,15 +95,15 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) =>
? retrieveCurr(api, stashId)
: retrievePrev(api, stashId)
]).pipe(
switchMap((result): Observable<DerivedStakingQuery> =>
switchMap((result): Observable<DeriveStakingQuery> =>
retrieveController(api, stashId, result)
)
);
});
}
export function queryMulti (api: ApiInterfaceRx): (...accountIds: (Uint8Array | string)[]) => Observable<DerivedStakingQuery[]> {
return memo((...accountIds: (Uint8Array | string)[]): Observable<DerivedStakingQuery[]> =>
export function queryMulti (api: ApiInterfaceRx): (...accountIds: (Uint8Array | string)[]) => Observable<DeriveStakingQuery[]> {
return memo((...accountIds: (Uint8Array | string)[]): Observable<DeriveStakingQuery[]> =>
combineLatest(
accountIds.map((accountId) => api.derive.staking.query(accountId))
)
+8 -8
View File
@@ -79,9 +79,9 @@ export interface DeriveStakerSlashes {
total: Balance;
}
export interface DerivedStakingElected {
export interface DeriveStakingElected {
nextElected: AccountId[];
info: DerivedStakingQuery[];
info: DeriveStakingQuery[];
}
export interface DeriveStakingValidators {
@@ -89,7 +89,7 @@ export interface DeriveStakingValidators {
validators: AccountId[];
}
export interface DerivedStakingStash {
export interface DeriveStakingStash {
controllerId?: AccountId;
exposure?: Exposure;
nominators?: AccountId[];
@@ -100,25 +100,25 @@ export interface DerivedStakingStash {
validatorPrefs?: ValidatorPrefs;
}
export interface DerivedStakingQuery extends DerivedStakingStash {
export interface DeriveStakingQuery extends DeriveStakingStash {
accountId: AccountId;
nextSessionIds: AccountId[];
sessionIds: AccountId[];
stakingLedger?: StakingLedger;
}
export interface DerivedStakingAccount extends DerivedStakingQuery {
export interface DeriveStakingAccount extends DeriveStakingQuery {
redeemable?: Balance;
unlocking?: DerivedUnlocking[];
unlocking?: DeriveUnlocking[];
}
export interface DerivedStakingOverview extends DeriveSessionIndexes {
export interface DeriveStakingOverview extends DeriveSessionIndexes {
eraPoints: EraRewardPoints;
nextElected: AccountId[];
validators: AccountId[];
}
export type DerivedUnlocking = {
export type DeriveUnlocking = {
remainingBlocks: BlockNumber;
value: Balance;
};