Disbale identity (#2016)
This commit is contained in:
@@ -79,7 +79,7 @@ function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [Accou
|
||||
|
||||
function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observable<DeriveAccountRegistration> {
|
||||
return ((
|
||||
accountId && api.query.identity?.identityOf
|
||||
accountId && api.query.identity?.identityOfFALSE
|
||||
? api.queryMulti([
|
||||
[api.query.identity.identityOf, accountId],
|
||||
[api.query.identity.superOf, accountId]
|
||||
|
||||
@@ -29,13 +29,13 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
|
||||
return memo((): Observable<DerivedFees> =>
|
||||
of([
|
||||
// deprecated - remove
|
||||
(api.consts.balances.creationFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances.transferFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.creationFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.transferFee as Balance) || createType(api.registry, 'Balance'),
|
||||
|
||||
// current
|
||||
api.consts.balances.existentialDeposit,
|
||||
api.consts.transactionPayment.transactionBaseFee,
|
||||
api.consts.transactionPayment.transactionByteFee
|
||||
(api.consts.balances?.existentialDeposit as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionBaseFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionByteFee as Balance) || createType(api.registry, 'Balance')
|
||||
]).pipe(
|
||||
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DerivedFees => ({
|
||||
creationFee,
|
||||
|
||||
@@ -28,7 +28,7 @@ function parse ([hashes, proposals, votes]: Result): DerivedCollectiveProposal[]
|
||||
|
||||
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposal[]> {
|
||||
return (): Observable<DerivedCollectiveProposal[]> =>
|
||||
api.query[section]
|
||||
api.query[section]?.proposals
|
||||
? api.query[section].proposals().pipe(
|
||||
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||
hashes.length
|
||||
|
||||
@@ -63,7 +63,7 @@ function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Resul
|
||||
|
||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||
return memo((): Observable<DeriveProposal[]> =>
|
||||
api.query.democracy?.publicProps
|
||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
switchMap((proposals) =>
|
||||
combineLatest([
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Balance, EraIndex, Exposure, RewardPoint } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraExposure, DeriveEraExposures, DeriveEraPointsAll } from '../types';
|
||||
import { Exposure } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraExposure, DeriveEraExposures, DeriveEraPointsAll, DeriveEraValPoints } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
@@ -12,51 +12,40 @@ import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryClipped (api: ApiInterfaceRx, withActive?: boolean): Observable<[EraIndex, RewardPoint, Balance, [AccountId, Exposure, RewardPoint][]][]> {
|
||||
return api.derive.staking.erasPoints(withActive).pipe(
|
||||
switchMap((allPoints): Observable<[DeriveEraPointsAll[], [StorageKey, Exposure][][]]> =>
|
||||
combineLatest([
|
||||
of(allPoints),
|
||||
combineLatest(
|
||||
// we could just do entries over the full set, however the set can be quite large - split it into
|
||||
// batches - may need to re-visit this, or alternatively use pages keys for exceptionally large sets
|
||||
allPoints.map(({ era }): Observable<[StorageKey, Exposure][]> =>
|
||||
api.query.staking.erasStakers.entries(era)
|
||||
)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([allPoints, erasStakers]): [EraIndex, RewardPoint, Balance, [AccountId, Exposure, RewardPoint][]][] =>
|
||||
allPoints.map(({ all, era, eraPoints, eraReward }, index): [EraIndex, RewardPoint, Balance, [AccountId, Exposure, RewardPoint][]] => [
|
||||
era,
|
||||
eraPoints,
|
||||
eraReward,
|
||||
erasStakers[index].map(([key, exposure]): [AccountId, Exposure, RewardPoint] => [
|
||||
key.args[1] as AccountId,
|
||||
exposure,
|
||||
all[key.args[1].toString()]
|
||||
])
|
||||
])
|
||||
)
|
||||
);
|
||||
function mapValidators (stakers: [StorageKey, Exposure][], validators: DeriveEraValPoints): DeriveEraExposures {
|
||||
return stakers.reduce((result: DeriveEraExposures, [key, exposure]): DeriveEraExposures => {
|
||||
const validatorId = key.args[1].toString();
|
||||
|
||||
result[validatorId] = {
|
||||
exposure,
|
||||
points: validators[validatorId]
|
||||
};
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraExposure[]> {
|
||||
return memo((withActive?: boolean): Observable<DeriveEraExposure[]> =>
|
||||
queryClipped(api, withActive).pipe(
|
||||
map((clipped): DeriveEraExposure[] =>
|
||||
clipped.map(([era, eraPoints, eraReward, validators]): DeriveEraExposure => ({
|
||||
all: validators.reduce((all: DeriveEraExposures, [validtorId, exposure, points]): DeriveEraExposures => {
|
||||
all[validtorId.toString()] = {
|
||||
exposure,
|
||||
points
|
||||
};
|
||||
|
||||
return all;
|
||||
}, {}),
|
||||
api.derive.staking.erasPoints(withActive).pipe(
|
||||
switchMap((allPoints): Observable<[DeriveEraPointsAll[], [StorageKey, Exposure][][]]> =>
|
||||
combineLatest([
|
||||
of(allPoints),
|
||||
combineLatest(
|
||||
// we could just do entries over the full set, however the set can be quite large - split it into
|
||||
// batches - may need to re-visit this, or alternatively use pages keys for exceptionally large sets
|
||||
allPoints.map(({ era }): Observable<[StorageKey, Exposure][]> =>
|
||||
api.query.staking.erasStakers.entries(era)
|
||||
)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([allPoints, erasStakers]): DeriveEraExposure[] =>
|
||||
allPoints.map(({ era, eraPoints, eraReward, validators }, index): DeriveEraExposure => ({
|
||||
era,
|
||||
eraPoints,
|
||||
eraReward
|
||||
eraReward,
|
||||
validators: mapValidators(erasStakers[index], validators)
|
||||
}))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ActiveEraInfo, Balance, EraIndex, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPointsAll } from '../types';
|
||||
import { ActiveEraInfo, Balance, EraIndex, EraRewardPoints } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPointsAll, DeriveEraValPoints } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
@@ -36,6 +36,16 @@ function getAvailableIndexes (api: ApiInterfaceRx, withActive?: boolean): Observ
|
||||
: of([]);
|
||||
}
|
||||
|
||||
function mapValidators ({ individual }: EraRewardPoints): DeriveEraValPoints {
|
||||
return [...individual.entries()]
|
||||
.filter(([, points]): boolean => points.gtn(0))
|
||||
.reduce((result: DeriveEraValPoints, [validatorId, points]): DeriveEraValPoints => {
|
||||
result[validatorId.toString()] = points;
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraPointsAll[]> {
|
||||
return memo((withActive?: boolean): Observable<DeriveEraPointsAll[]> =>
|
||||
getAvailableIndexes(api, withActive).pipe(
|
||||
@@ -52,16 +62,10 @@ export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean) => Obse
|
||||
),
|
||||
map(([eras, points, rewards]): DeriveEraPointsAll[] =>
|
||||
eras.map((era, index): DeriveEraPointsAll => ({
|
||||
all: [...points[index].individual.entries()]
|
||||
.filter(([, points]): boolean => points.gtn(0))
|
||||
.reduce((all: Record<string, RewardPoint>, [validatorId, points]): Record<string, RewardPoint> => {
|
||||
all[validatorId.toString()] = points;
|
||||
|
||||
return all;
|
||||
}, {}),
|
||||
era,
|
||||
eraPoints: points[index].total,
|
||||
eraReward: rewards[index].unwrapOrDefault()
|
||||
eraReward: rewards[index].unwrapOrDefault(),
|
||||
validators: mapValidators(points[index])
|
||||
}))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Exposure } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraRewardsAll } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -10,25 +11,27 @@ import { map } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function includeExposure (validatorId: string, { others }: Exposure, nominators: Record<string, [string, number][]>): void {
|
||||
others.forEach(({ who }, index): void => {
|
||||
const nominatorId = who.toString();
|
||||
|
||||
nominators[nominatorId] = nominators[nominatorId] || [];
|
||||
nominators[nominatorId].push([validatorId, index]);
|
||||
});
|
||||
}
|
||||
|
||||
export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraRewardsAll[]> {
|
||||
return memo((withActive?: boolean): Observable<DeriveEraRewardsAll[]> =>
|
||||
api.derive.staking.erasExposure(withActive).pipe(
|
||||
map((exposures): DeriveEraRewardsAll[] =>
|
||||
exposures.map(({ all, era, eraPoints, eraReward }): DeriveEraRewardsAll =>
|
||||
exposures.map(({ era, eraPoints, eraReward, validators }): DeriveEraRewardsAll =>
|
||||
Object
|
||||
.entries(all)
|
||||
.reduce((rewards: DeriveEraRewardsAll, [validatorId, data]): DeriveEraRewardsAll => {
|
||||
rewards.validators[validatorId] = data;
|
||||
|
||||
data.exposure.others.forEach(({ who }, index): void => {
|
||||
const nominatorId = who.toString();
|
||||
|
||||
rewards.nominators[nominatorId] = rewards.nominators[nominatorId] || [];
|
||||
rewards.nominators[nominatorId].push([validatorId, index]);
|
||||
});
|
||||
.entries(validators)
|
||||
.reduce((rewards: DeriveEraRewardsAll, [validatorId, { exposure }]): DeriveEraRewardsAll => {
|
||||
includeExposure(validatorId, exposure, rewards.nominators);
|
||||
|
||||
return rewards;
|
||||
}, { era, eraPoints, eraReward, nominators: {}, validators: {} })
|
||||
}, { era, eraPoints, eraReward, nominators: {}, validators })
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -41,7 +41,9 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
of({ ...indexes, nextElected, validators }),
|
||||
api.query.staking.erasRewardPoints
|
||||
? api.query.staking.erasRewardPoints<EraRewardPoints>(indexes.activeEra)
|
||||
: retrievePointsPrev(api, indexes.activeEra, nextElected)
|
||||
: api.query.staking.currentEraPointsEarned
|
||||
? retrievePointsPrev(api, indexes.activeEra, nextElected)
|
||||
: of(createType(api.registry, 'EraRewardPoints'))
|
||||
])
|
||||
),
|
||||
map(([info, eraPoints]): DerivedStakingOverview => ({
|
||||
|
||||
@@ -11,8 +11,10 @@ interface EraPointInfo {
|
||||
eraReward: Balance;
|
||||
}
|
||||
|
||||
export type DeriveEraValPoints = Record<string, RewardPoint>;
|
||||
|
||||
export interface DeriveEraPointsAll extends EraPointInfo {
|
||||
all: Record<string, RewardPoint>;
|
||||
validators: DeriveEraValPoints;
|
||||
}
|
||||
|
||||
export interface DeriveEraPoints extends EraPointInfo {
|
||||
@@ -25,7 +27,7 @@ export type DeriveEraExposures = Record<string, {
|
||||
}>;
|
||||
|
||||
export interface DeriveEraExposure extends EraPointInfo {
|
||||
all: DeriveEraExposures;
|
||||
validators: DeriveEraExposures;
|
||||
}
|
||||
|
||||
export interface DeriveEraRewardsAll extends EraPointInfo {
|
||||
|
||||
@@ -5,11 +5,23 @@
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
describe.skip('misc quick tests', (): void => {
|
||||
it.skip('retrieves balances correctly', async (): Promise<void> => {
|
||||
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
|
||||
const api = await new ApiPromise({ provider }).isReady;
|
||||
|
||||
console.error(JSON.stringify(
|
||||
await api.query.system.account('FPzukZw2mphWsXDqdkNzLaxnanjZEWH9i2vqwobTdtde5me')
|
||||
));
|
||||
console.error(JSON.stringify(
|
||||
await api.query.system.account('HUewJvzVuEeyaxH2vx9XiyAPKrpu1Zj5r5Pi9VrGiBVty7q')
|
||||
));
|
||||
});
|
||||
|
||||
it.skip('handles doublemap entries', async (): Promise<void> => {
|
||||
const api = await new ApiPromise().isReady;
|
||||
const activeEra = await api.query.staking.activeEra();
|
||||
|
||||
console.log(JSON.stringify(
|
||||
console.error(JSON.stringify(
|
||||
await api.query.staking.erasStakers.entries(activeEra.unwrapOrDefault().index)
|
||||
));
|
||||
});
|
||||
@@ -18,7 +30,7 @@ describe.skip('misc quick tests', (): void => {
|
||||
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
|
||||
const api = await new ApiPromise({ provider }).isReady;
|
||||
|
||||
console.log(JSON.stringify(
|
||||
console.error(JSON.stringify(
|
||||
await api.query.society.defenderVotes('Dab4bfYTZRUDMWjYAUQuFbDreQ9mt7nULWu3Dw7jodbzVe9')
|
||||
));
|
||||
});
|
||||
|
||||
@@ -64,6 +64,7 @@ const TYPES_POLKADOT_VERSIONED: OverrideVersionedType[] = [
|
||||
|
||||
const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [
|
||||
{
|
||||
// 1020 is first CC3
|
||||
minmax: [1019, 1031],
|
||||
types: {
|
||||
Address: 'GenericAddress',
|
||||
@@ -87,6 +88,7 @@ const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
// actual at 1045 (1043-1044 is dev)
|
||||
minmax: [1043, 1045],
|
||||
types: {
|
||||
Address: 'GenericAddress',
|
||||
@@ -97,6 +99,7 @@ const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
// actual at 1050 (1046-1049 is dev)
|
||||
minmax: [1046, undefined],
|
||||
types: {
|
||||
// Indices optional, not in transaction
|
||||
|
||||
Reference in New Issue
Block a user