Remove double-up-drr (memo vs rpc) (#1541)
* Remove inner memo (no double-up on stringify) * Validators-specific query
This commit is contained in:
@@ -66,6 +66,6 @@ export const idAndIndex = memo((api: ApiInterfaceRx): (address?: Address | Accou
|
||||
indexToIdCall: indexToId(api)
|
||||
};
|
||||
|
||||
return memo((address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
||||
retrieve(address, calls).pipe(drr()));
|
||||
return (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
||||
retrieve(address, calls).pipe(drr());
|
||||
}, true);
|
||||
|
||||
@@ -28,12 +28,12 @@ import { drr, memo } from '../util';
|
||||
export const idToIndex = memo((api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> => {
|
||||
const indexesCall = indexes(api);
|
||||
|
||||
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
return (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
indexesCall().pipe(
|
||||
startWith({}),
|
||||
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
||||
(indexes || {})[accountId.toString()]
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -28,7 +28,7 @@ import { drr, memo } from '../util';
|
||||
export const indexToId = memo((api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> => {
|
||||
const querySection = api.query.indices || api.query.balances;
|
||||
|
||||
return memo((_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
|
||||
return (_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
|
||||
const accountIndex = _accountIndex instanceof ClassOf('AccountIndex')
|
||||
? _accountIndex
|
||||
: createType('AccountIndex', _accountIndex);
|
||||
@@ -40,5 +40,5 @@ export const indexToId = memo((api: ApiInterfaceRx): (accountIndex: AccountIndex
|
||||
),
|
||||
drr()
|
||||
);
|
||||
});
|
||||
};
|
||||
}, true);
|
||||
|
||||
@@ -32,7 +32,7 @@ const enumsetSize = ENUMSET_SIZE.toNumber();
|
||||
* ```
|
||||
*/
|
||||
export const indexes = memo((api: ApiInterfaceRx): () => Observable<AccountIndexes> => {
|
||||
return memo((): Observable<AccountIndexes> =>
|
||||
return (): Observable<AccountIndexes> =>
|
||||
api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
||||
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
||||
// a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the
|
||||
@@ -54,5 +54,5 @@ export const indexes = memo((api: ApiInterfaceRx): () => Observable<AccountIndex
|
||||
return result;
|
||||
}, {} as AccountIndexes)),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -30,7 +30,7 @@ export const info = memo((api: ApiInterfaceRx): (address?: AccountIndex | Accoun
|
||||
const idAndIndexCall = idAndIndex(api);
|
||||
const nickCall = retrieveNick(api);
|
||||
|
||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
return (address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
idAndIndexCall(address).pipe(
|
||||
switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, Option<[Bytes, Balance] & Codec>?]> =>
|
||||
combineLatest([
|
||||
@@ -46,5 +46,5 @@ export const info = memo((api: ApiInterfaceRx): (address?: AccountIndex | Accoun
|
||||
: undefined
|
||||
})),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -81,7 +81,7 @@ export const all = memo((api: ApiInterfaceRx): (address: AccountIndex | AccountI
|
||||
const bestNumberCall = bestNumber(api);
|
||||
const infoCall = info(api);
|
||||
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> =>
|
||||
return (address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> =>
|
||||
infoCall(address).pipe(
|
||||
switchMap(({ accountId }): Observable<Result> =>
|
||||
(accountId
|
||||
@@ -101,5 +101,5 @@ export const all = memo((api: ApiInterfaceRx): (address: AccountIndex | AccountI
|
||||
),
|
||||
map(calcBalances),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -56,7 +56,7 @@ export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedFees> =>
|
||||
? queryV2
|
||||
: queryV1;
|
||||
|
||||
return memo((): Observable<DerivedFees> =>
|
||||
return (): Observable<DerivedFees> =>
|
||||
query(api).pipe(
|
||||
map(([creationFee, existentialDeposit, transferFee, transactionBaseFee, transactionByteFee]): DerivedFees => ({
|
||||
creationFee,
|
||||
@@ -66,5 +66,5 @@ export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedFees> =>
|
||||
transferFee
|
||||
})),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -12,12 +12,12 @@ import { drr, memo } from '../util';
|
||||
import { all } from './all';
|
||||
|
||||
export const votingBalances = memo((api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DerivedBalances[]> => {
|
||||
return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> =>
|
||||
return (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> =>
|
||||
(
|
||||
!addresses || !addresses.length
|
||||
? of([] as DerivedBalances[])
|
||||
: combineLatest(addresses.map(all(api)))
|
||||
).pipe(
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -17,7 +17,7 @@ import { votingBalances } from './votingBalances';
|
||||
export const votingBalancesNominatorsFor = memo((api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return memo((address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> =>
|
||||
return (address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> =>
|
||||
infoCall(address).pipe(
|
||||
switchMap(({ accountId }): Observable<AccountId[]> =>
|
||||
accountId
|
||||
@@ -26,5 +26,5 @@ export const votingBalancesNominatorsFor = memo((api: ApiInterfaceRx): (address:
|
||||
),
|
||||
switchMap(votingBalances(api)),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -23,9 +23,9 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const bestNumber = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeNewHeads().pipe(
|
||||
map((header): BlockNumber => header.number.unwrap()),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -24,9 +24,9 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const bestNumberFinalized = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
||||
map((header): BlockNumber => header.number.unwrap()),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -30,7 +30,7 @@ export const bestNumberLag = memo((api: ApiInterfaceRx): () => Observable<BlockN
|
||||
const bestNumberCall = bestNumber(api);
|
||||
const bestNumberFinalizedCall = bestNumberFinalized(api);
|
||||
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
combineLatest([
|
||||
bestNumberCall(),
|
||||
bestNumberFinalizedCall()
|
||||
@@ -39,5 +39,5 @@ export const bestNumberLag = memo((api: ApiInterfaceRx): () => Observable<BlockN
|
||||
createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -28,7 +28,7 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const getHeader = memo((api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> => {
|
||||
return memo((hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
return (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(hash),
|
||||
api.query.session.validators.at(hash) as Observable<Vec<AccountId>>
|
||||
@@ -43,5 +43,5 @@ export const getHeader = memo((api: ApiInterfaceRx): (hash: Uint8Array | string)
|
||||
of()
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -26,7 +26,7 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const subscribeNewHeads = memo((api: ApiInterfaceRx): () => Observable<HeaderExtended> => {
|
||||
return memo((): Observable<HeaderExtended> =>
|
||||
return (): Observable<HeaderExtended> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.subscribeNewHeads(),
|
||||
api.query.session.validators<Vec<AccountId>>()
|
||||
@@ -35,5 +35,5 @@ export const subscribeNewHeads = memo((api: ApiInterfaceRx): () => Observable<He
|
||||
new HeaderExtended(header, validators)
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -104,7 +104,7 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||
* ```
|
||||
*/
|
||||
export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedContractFees> => {
|
||||
return memo((): Observable<DerivedContractFees> => {
|
||||
return (): Observable<DerivedContractFees> => {
|
||||
if (api.query.contract && !api.query.contract.rentByteFee) {
|
||||
return queryV1(api);
|
||||
}
|
||||
@@ -122,5 +122,5 @@ export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedContract
|
||||
),
|
||||
drr()
|
||||
);
|
||||
});
|
||||
};
|
||||
}, true);
|
||||
|
||||
@@ -28,12 +28,11 @@ export function constructInfo (index: BN | number, optionInfo?: Option<Referendu
|
||||
}
|
||||
|
||||
export const referendumInfo = memo((api: ApiInterfaceRx): (index: BN | number) => Observable<Option<ReferendumInfoExtended>> => {
|
||||
return memo((index: BN | number): Observable<Option<ReferendumInfoExtended>> =>
|
||||
(api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index))
|
||||
.pipe(
|
||||
map((optionInfo): Option<ReferendumInfoExtended> =>
|
||||
constructInfo(index, optionInfo)
|
||||
),
|
||||
drr()
|
||||
));
|
||||
return (index: BN | number): Observable<Option<ReferendumInfoExtended>> =>
|
||||
api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index).pipe(
|
||||
map((optionInfo): Option<ReferendumInfoExtended> =>
|
||||
constructInfo(index, optionInfo)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -15,7 +15,7 @@ import { drr, memo } from '../util';
|
||||
import { constructInfo } from './referendumInfo';
|
||||
|
||||
export const referendumInfos = memo((api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<Option<ReferendumInfoExtended>[]> => {
|
||||
return memo((ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
return (ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
(
|
||||
!ids || !ids.length
|
||||
? of([] as Option<ReferendumInfo>[])
|
||||
@@ -27,5 +27,5 @@ export const referendumInfos = memo((api: ApiInterfaceRx): (ids?: (BN | number)[
|
||||
)
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const referendumVotesFor = memo((api: ApiInterfaceRx): (referendumId: BN
|
||||
const votesCall = votes(api);
|
||||
const votingBalancesCall = votingBalances(api);
|
||||
|
||||
return memo((referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
return (referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
combineLatest([
|
||||
@@ -36,5 +36,5 @@ export const referendumVotesFor = memo((api: ApiInterfaceRx): (referendumId: BN
|
||||
} as unknown as DerivedReferendumVote))
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -17,7 +17,7 @@ import { referendumInfos } from './referendumInfos';
|
||||
export const referendums = memo((api: ApiInterfaceRx): () => Observable<Option<ReferendumInfoExtended>[]> => {
|
||||
const referendumInfosCall = referendumInfos(api);
|
||||
|
||||
return memo((): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
return (): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
||||
api.query.democracy.nextTally,
|
||||
api.query.democracy.referendumCount
|
||||
@@ -32,5 +32,5 @@ export const referendums = memo((api: ApiInterfaceRx): () => Observable<Option<R
|
||||
: of([])
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export const votes = memo((api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> => {
|
||||
return memo((referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> =>
|
||||
return (referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> =>
|
||||
(
|
||||
!accountIds || !accountIds.length
|
||||
? of([] as Vote[])
|
||||
@@ -20,5 +20,5 @@ export const votes = memo((api: ApiInterfaceRx): (referendumId: BN, accountIds?:
|
||||
[referendumId, accountId]
|
||||
)
|
||||
)
|
||||
).pipe(drr()));
|
||||
).pipe(drr());
|
||||
}, true);
|
||||
|
||||
@@ -24,7 +24,7 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> => {
|
||||
return memo((who: AccountId | string): Observable<boolean[][]> =>
|
||||
return (who: AccountId | string): Observable<boolean[][]> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi(
|
||||
@@ -39,5 +39,5 @@ export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Obser
|
||||
)
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -26,9 +26,9 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const approvalsOfAt = memo((api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> => {
|
||||
return memo((who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
return (who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe(
|
||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -93,6 +93,6 @@ export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedElection
|
||||
? queryPhragmen
|
||||
: queryElections;
|
||||
|
||||
return memo((): Observable<DerivedElectionsInfo> =>
|
||||
query(api).pipe(drr()));
|
||||
return (): Observable<DerivedElectionsInfo> =>
|
||||
query(api).pipe(drr());
|
||||
}, true);
|
||||
|
||||
@@ -27,7 +27,7 @@ import { drr, memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> => {
|
||||
return memo((): Observable<DerivedVoterPositions> =>
|
||||
return (): Observable<DerivedVoterPositions> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
@@ -54,5 +54,5 @@ export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<Deriv
|
||||
}, {});
|
||||
}),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -28,7 +28,7 @@ import { voterPositions } from './voterPositions';
|
||||
export const voters = memo((api: ApiInterfaceRx): () => Observable<Vec<AccountId>> => {
|
||||
const voterPositionsCall = voterPositions(api);
|
||||
|
||||
return memo((): Observable<Vec<AccountId>> =>
|
||||
return (): Observable<Vec<AccountId>> =>
|
||||
voterPositionsCall().pipe(
|
||||
map((voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
createType(
|
||||
@@ -39,5 +39,5 @@ export const voters = memo((api: ApiInterfaceRx): () => Observable<Vec<AccountId
|
||||
)
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -19,7 +19,7 @@ import { drr, memo } from '../util';
|
||||
export const receivedHeartbeats = memo((api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> => {
|
||||
const stakingOverviewvCall = stakingOverview(api);
|
||||
|
||||
return memo((): Observable<DerivedHeartbeats> =>
|
||||
return (): Observable<DerivedHeartbeats> =>
|
||||
api.query.imOnline && api.query.imOnline.receivedHeartbeats && api.query.imOnline.authoredBlocks
|
||||
? stakingOverviewvCall().pipe(
|
||||
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
||||
@@ -41,5 +41,5 @@ export const receivedHeartbeats = memo((api: ApiInterfaceRx): () => Observable<D
|
||||
),
|
||||
drr()
|
||||
)
|
||||
: of({}));
|
||||
: of({});
|
||||
}, true);
|
||||
|
||||
@@ -14,9 +14,9 @@ import { info } from './info';
|
||||
export const eraLength = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ eraLength }): BlockNumber => eraLength),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -14,9 +14,9 @@ import { info } from './info';
|
||||
export const eraProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ eraProgress }): BlockNumber => eraProgress),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { u32 } from '@polkadot/types';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> => {
|
||||
return memo((): Observable<DeriveSessionIndexes> =>
|
||||
return (): Observable<DeriveSessionIndexes> =>
|
||||
api.queryMulti<[SessionIndex, EraIndex, u32]>([
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.currentEra,
|
||||
@@ -23,5 +23,5 @@ export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessio
|
||||
currentIndex, currentEra, validatorCount
|
||||
})),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -138,6 +138,6 @@ export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedSessionI
|
||||
: infoLatestAura // 2.x with Aura (not all info there)
|
||||
: infoV1;
|
||||
|
||||
return memo((): Observable<DerivedSessionInfo> =>
|
||||
query(api, calls).pipe(drr()));
|
||||
return (): Observable<DerivedSessionInfo> =>
|
||||
query(api, calls).pipe(drr());
|
||||
}, true);
|
||||
|
||||
@@ -14,9 +14,9 @@ import { info } from './info';
|
||||
export const sessionProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
return (): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ sessionProgress }): BlockNumber => sessionProgress),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -16,7 +16,7 @@ import { drr, memo } from '../util';
|
||||
* @description From the list of stash accounts, retrieve the list of controllers
|
||||
*/
|
||||
export const controllers = memo((api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> => {
|
||||
return memo((): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
return (): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
api.query.staking.validators<[AccountId[]] & Codec>().pipe(
|
||||
switchMap(([stashIds]): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
combineLatest([
|
||||
@@ -28,5 +28,5 @@ export const controllers = memo((api: ApiInterfaceRx): () => Observable<[Account
|
||||
])
|
||||
),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -232,6 +232,6 @@ export const info = memo((api: ApiInterfaceRx): (_accountId: Uint8Array | string
|
||||
? retrieveV2
|
||||
: retrieveV1;
|
||||
|
||||
return memo((accountId: Uint8Array | string): Observable<DerivedStaking> =>
|
||||
query(api, calls, createType('AccountId', accountId)).pipe(drr()));
|
||||
return (accountId: Uint8Array | string): Observable<DerivedStaking> =>
|
||||
query(api, calls, createType('AccountId', accountId)).pipe(drr());
|
||||
}, true);
|
||||
|
||||
@@ -57,9 +57,9 @@ export const infoStash = memo((api: ApiInterfaceRx): (stashId: AccountId) => Obs
|
||||
? retrieveV2
|
||||
: retrieveV1;
|
||||
|
||||
return memo((stashId: AccountId): Observable<DerivedStakingStash> =>
|
||||
return (stashId: AccountId): Observable<DerivedStakingStash> =>
|
||||
query(api, stashId).pipe(
|
||||
map((result): DerivedStakingStash => parse(stashId, result)),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -2,32 +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 { AccountId, EraPoints } from '@polkadot/types/interfaces';
|
||||
import { EraPoints } 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, Vec } from '@polkadot/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { drr, memo } from '../util';
|
||||
import { indexes as sessionIndexes } from '../session';
|
||||
import { validators } from './validators';
|
||||
|
||||
/**
|
||||
* @description Retrieve the staking overview, including elected and points earned
|
||||
*/
|
||||
export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> => {
|
||||
const sessionIndexesCall = sessionIndexes(api);
|
||||
const validatorsCall = validators(api);
|
||||
|
||||
return memo((): Observable<DerivedStakingOverview> =>
|
||||
return (): Observable<DerivedStakingOverview> =>
|
||||
combineLatest([
|
||||
sessionIndexesCall(),
|
||||
api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([
|
||||
api.query.session.validators,
|
||||
api.query.staking.currentElected
|
||||
])
|
||||
validatorsCall()
|
||||
]).pipe(
|
||||
switchMap(([{ currentEra, currentIndex, validatorCount }, [validators, currentElected]]) =>
|
||||
switchMap(([{ currentEra, currentIndex, validatorCount }, { currentElected, validators }]) =>
|
||||
combineLatest([
|
||||
of({ currentElected, currentEra, currentIndex, validators, validatorCount }),
|
||||
// this will change on a per block basis, keep it innermost (and it needs eraIndex)
|
||||
@@ -40,5 +39,5 @@ export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStak
|
||||
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
|
||||
})),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -36,7 +36,7 @@ function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline
|
||||
* @description Retrieve a keyed record of accounts recently reported to be offline
|
||||
*/
|
||||
export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> => {
|
||||
return memo((): Observable<DerivedRecentlyOffline> =>
|
||||
return (): Observable<DerivedRecentlyOffline> =>
|
||||
(
|
||||
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
|
||||
// replacement as actually use and implement it
|
||||
@@ -46,5 +46,5 @@ export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<Deri
|
||||
).pipe(
|
||||
map(expandDerived),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -4,22 +4,26 @@
|
||||
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DeriveStakingValidators } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { drr, memo } from '../util';
|
||||
import { overview } from './overview';
|
||||
|
||||
/**
|
||||
* @description Retrieve latest list of validators
|
||||
*/
|
||||
export const validators = memo((api: ApiInterfaceRx): () => Observable<AccountId[]> => {
|
||||
const overviewCall = overview(api);
|
||||
|
||||
return memo((): Observable<AccountId[]> =>
|
||||
overviewCall().pipe(
|
||||
map(({ validators }): AccountId[] => validators),
|
||||
export const validators = memo((api: ApiInterfaceRx): () => Observable<DeriveStakingValidators> => {
|
||||
return (): Observable<DeriveStakingValidators> =>
|
||||
api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([
|
||||
api.query.session.validators,
|
||||
api.query.staking.currentElected
|
||||
]).pipe(
|
||||
map(([validators, currentElected]): DeriveStakingValidators => ({
|
||||
currentElected, validators
|
||||
})),
|
||||
drr()
|
||||
));
|
||||
);
|
||||
}, true);
|
||||
|
||||
@@ -115,6 +115,11 @@ export interface DerivedStakingOnlineStatus {
|
||||
}[];
|
||||
}
|
||||
|
||||
export interface DeriveStakingValidators {
|
||||
currentElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export interface DerivedStakingStash {
|
||||
controllerId?: AccountId;
|
||||
nominators?: AccountId[];
|
||||
|
||||
Reference in New Issue
Block a user