Multi query adjustments (#1732)
This commit is contained in:
@@ -14,10 +14,10 @@ import { bnMax } from '@polkadot/util';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
type ResultBalance = [Balance, Balance, BalanceLock[], Option<VestingSchedule>];
|
type ResultBalance = [Balance, Balance, BalanceLock[], Option<VestingSchedule>, Index];
|
||||||
type Result = [AccountId, BlockNumber, ResultBalance, Index];
|
type Result = [AccountId, BlockNumber, ResultBalance];
|
||||||
|
|
||||||
function calcBalances (api: ApiInterfaceRx, [accountId, bestNumber, [freeBalance, reservedBalance, locks, vesting], accountNonce]: Result): DerivedBalances {
|
function calcBalances (api: ApiInterfaceRx, [accountId, bestNumber, [freeBalance, reservedBalance, locks, vesting, accountNonce]]: Result): DerivedBalances {
|
||||||
let lockedBalance = createType(api.registry, 'Balance');
|
let lockedBalance = createType(api.registry, 'Balance');
|
||||||
let lockedBreakdown: BalanceLock[] = [];
|
let lockedBreakdown: BalanceLock[] = [];
|
||||||
|
|
||||||
@@ -64,15 +64,6 @@ function calcBalances (api: ApiInterfaceRx, [accountId, bestNumber, [freeBalance
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryBalances (api: ApiInterfaceRx, accountId: AccountId): Observable<ResultBalance> {
|
|
||||||
return api.queryMulti<[Balance, Balance, Vec<BalanceLock>, Option<VestingSchedule>]>([
|
|
||||||
[api.query.balances.freeBalance, accountId],
|
|
||||||
[api.query.balances.reservedBalance, accountId],
|
|
||||||
[api.query.balances.locks, accountId],
|
|
||||||
[api.query.balances.vesting, accountId]
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name all
|
* @name all
|
||||||
* @param {( AccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
|
* @param {( AccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
|
||||||
@@ -96,15 +87,15 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId |
|
|||||||
? combineLatest([
|
? combineLatest([
|
||||||
of(accountId),
|
of(accountId),
|
||||||
api.derive.chain.bestNumber(),
|
api.derive.chain.bestNumber(),
|
||||||
queryBalances(api, accountId),
|
api.queryMulti<[Balance, Balance, Vec<BalanceLock>, Option<VestingSchedule>, Index]>([
|
||||||
// FIXME This is having issues with Kusama, only use accountNonce atm
|
[api.query.balances.freeBalance, accountId],
|
||||||
// api.rpc.account && api.rpc.account.nextIndex
|
[api.query.balances.reservedBalance, accountId],
|
||||||
// ? api.rpc.account.nextIndex(accountId)
|
[api.query.balances.locks, accountId],
|
||||||
// // otherwise we end up with this: type 'Codec | Index' is not assignable to type 'Index'.
|
[api.query.balances.vesting, accountId],
|
||||||
// : api.query.system.accountNonce<Index>(accountId)
|
[api.query.system.accountNonce, accountId]
|
||||||
api.query.system.accountNonce<Index>(accountId)
|
])
|
||||||
])
|
])
|
||||||
: of([createType(api.registry, 'AccountId'), createType(api.registry, 'BlockNumber'), [createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), createType(api.registry, 'Vec<BalanceLock>'), createType(api.registry, 'Option<VestingSchedule>', null)], createType(api.registry, 'Index')])
|
: of([createType(api.registry, 'AccountId'), createType(api.registry, 'BlockNumber'), [createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), createType(api.registry, 'Vec<BalanceLock>'), createType(api.registry, 'Option<VestingSchedule>', null), createType(api.registry, 'Index')]])
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
map((result): DerivedBalances => calcBalances(api, result))
|
map((result): DerivedBalances => calcBalances(api, result))
|
||||||
|
|||||||
@@ -4,41 +4,40 @@
|
|||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
import { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||||
import { DerivedCollectiveProposals } from '../types';
|
import { DerivedCollectiveProposal } from '../types';
|
||||||
|
|
||||||
import { combineLatest, Observable, of } from 'rxjs';
|
import { combineLatest, Observable, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { Option } from '@polkadot/types';
|
import { Option } from '@polkadot/types';
|
||||||
|
|
||||||
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposals> {
|
type Result = [Hash[], Option<Proposal>[], Option<Votes>[]];
|
||||||
return (): Observable<DerivedCollectiveProposals> =>
|
|
||||||
api.query[section]
|
|
||||||
? api.query[section].proposals()
|
|
||||||
.pipe(
|
|
||||||
switchMap((hashes: Hash[]): Observable<[Hash[], Option<Proposal>[], Option<Votes>[]]> => {
|
|
||||||
return combineLatest([
|
|
||||||
of(hashes),
|
|
||||||
combineLatest(
|
|
||||||
hashes.map((hash): Observable<Option<Proposal>> => api.query[section].proposalOf(hash))
|
|
||||||
),
|
|
||||||
api.query[section].voting.multi<Option<Votes>>(hashes)
|
|
||||||
]);
|
|
||||||
}),
|
|
||||||
map(([hashes, proposals, votes]): DerivedCollectiveProposals => {
|
|
||||||
const result: DerivedCollectiveProposals = [];
|
|
||||||
|
|
||||||
proposals.forEach((proposalOpt, index): void => {
|
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposal[]> {
|
||||||
if (proposalOpt.isSome) {
|
return (): Observable<DerivedCollectiveProposal[]> =>
|
||||||
result.push({
|
api.query[section]
|
||||||
|
? api.query[section].proposals().pipe(
|
||||||
|
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||||
|
hashes.length
|
||||||
|
? combineLatest([
|
||||||
|
of(hashes),
|
||||||
|
api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
|
||||||
|
api.query[section].voting.multi<Option<Votes>>(hashes)
|
||||||
|
])
|
||||||
|
: of([[], [], []])
|
||||||
|
),
|
||||||
|
map(([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] =>
|
||||||
|
proposals
|
||||||
|
.map((proposalOpt, index): DerivedCollectiveProposal | null =>
|
||||||
|
proposalOpt.isSome
|
||||||
|
? {
|
||||||
hash: hashes[index],
|
hash: hashes[index],
|
||||||
proposal: proposalOpt.unwrap(),
|
proposal: proposalOpt.unwrap(),
|
||||||
votes: votes[index].unwrapOr(null)
|
votes: votes[index].unwrapOr(null)
|
||||||
});
|
}
|
||||||
}
|
: null
|
||||||
});
|
)
|
||||||
|
.filter((proposal): boolean => !!proposal) as DerivedCollectiveProposal[]
|
||||||
return result;
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
: of([] as DerivedCollectiveProposals);
|
)
|
||||||
|
: of([] as DerivedCollectiveProposal[]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,20 +64,20 @@ function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Resul
|
|||||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||||
return memo((): Observable<DeriveProposal[]> =>
|
return memo((): Observable<DeriveProposal[]> =>
|
||||||
api.query.democracy?.publicProps
|
api.query.democracy?.publicProps
|
||||||
? api.query.democracy
|
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||||
.publicProps<Proposals>()
|
switchMap((proposals) =>
|
||||||
.pipe(
|
combineLatest([
|
||||||
switchMap((proposals) =>
|
of(proposals),
|
||||||
combineLatest([
|
api.query.democracy.preimages.multi<PreImage>(
|
||||||
of(proposals),
|
proposals.map(([, hash]): Hash => hash)),
|
||||||
api.query.democracy.preimages.multi<PreImage>(proposals.map(([, hash]): Hash => hash)),
|
api.query.democracy.depositOf.multi<Depositors>(
|
||||||
api.query.democracy.depositOf.multi<Depositors>(proposals.map(([index]): PropIndex => index))
|
proposals.map(([index]): PropIndex => index))
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([proposals, preimages, depositors]): DeriveProposal[] =>
|
map(([proposals, preimages, depositors]): DeriveProposal[] =>
|
||||||
parse(api, { depositors, proposals, preimages })
|
parse(api, { depositors, proposals, preimages })
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
: of([] as DeriveProposal[])
|
: of([] as DeriveProposal[])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import BN from 'bn.js';
|
|||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Option, Vec } from '@polkadot/types';
|
import { Option } from '@polkadot/types';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
import { retrieveInfo } from './referendumInfo';
|
import { retrieveInfo } from './referendumInfo';
|
||||||
@@ -17,9 +17,9 @@ import { retrieveInfo } from './referendumInfo';
|
|||||||
export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<DerivedReferendum[]> {
|
export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<DerivedReferendum[]> {
|
||||||
return memo((ids: (BN | number)[] = []): Observable<DerivedReferendum[]> =>
|
return memo((ids: (BN | number)[] = []): Observable<DerivedReferendum[]> =>
|
||||||
(
|
(
|
||||||
!ids || !ids.length
|
!ids?.length
|
||||||
? of([] as Option<ReferendumInfo>[])
|
? of([] as Option<ReferendumInfo>[])
|
||||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vec<Option<ReferendumInfo>>>
|
: api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)
|
||||||
).pipe(
|
).pipe(
|
||||||
switchMap((infos): Observable<(DerivedReferendum | null)[]> =>
|
switchMap((infos): Observable<(DerivedReferendum | null)[]> =>
|
||||||
combineLatest(
|
combineLatest(
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
|
|||||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of(votersFor),
|
of(votersFor),
|
||||||
api.derive.democracy.votes(referendumId as BN, votersFor),
|
api.derive.democracy.votes(referendumId, votersFor),
|
||||||
api.derive.balances.votingBalances(votersFor)
|
api.derive.balances.votingBalances(votersFor)
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> {
|
export function votes (api: ApiInterfaceRx): (referendumId: BN | number, accountIds?: AccountId[]) => Observable<Vote[]> {
|
||||||
return memo((referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> =>
|
return memo((referendumId: BN | number, accountIds: AccountId[] = []): Observable<Vote[]> =>
|
||||||
!accountIds || !accountIds.length
|
!accountIds || !accountIds.length
|
||||||
? of([] as Vote[])
|
? of([] as Vote[])
|
||||||
: api.query.democracy.voteOf.multi<Vote>(
|
: api.query.democracy.voteOf.multi<Vote>(
|
||||||
accountIds.map((accountId): [BN, AccountId] =>
|
accountIds.map((accountId): [BN | number, AccountId] =>
|
||||||
[referendumId, accountId]
|
[referendumId, accountId]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import { AccountId, Balance, BlockNumber } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, BlockNumber } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
|
|
||||||
import { Observable, combineLatest } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { createType, Vec, u32 } from '@polkadot/types';
|
import { createType, Vec, u32 } from '@polkadot/types';
|
||||||
@@ -13,39 +13,26 @@ import { createType, Vec, u32 } from '@polkadot/types';
|
|||||||
import { DerivedElectionsInfo } from '../types';
|
import { DerivedElectionsInfo } from '../types';
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
function deriveElections (api: ApiInterfaceRx, candidates: AccountId[], members: [AccountId, Balance][], runnersUp: [AccountId, Balance][], candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
|
|
||||||
return {
|
|
||||||
candidates,
|
|
||||||
candidateCount: createType(api.registry, 'u32', candidates.length),
|
|
||||||
candidacyBond,
|
|
||||||
desiredSeats,
|
|
||||||
members: members.sort((a, b): number => b[1].cmp(a[1])),
|
|
||||||
runnersUp: runnersUp.sort((a, b): number => b[1].cmp(a[1])),
|
|
||||||
termDuration,
|
|
||||||
votingBond
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||||
const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
||||||
|
|
||||||
// NOTE We have an issue where candidates can return `null` for an empty array, hence
|
// NOTE We have an issue where candidates can return `null` for an empty array, hence
|
||||||
// we are not using multi queries here, so empty array is empty (instead of space-filled)
|
// we are not using multi queries here, so empty array is empty (instead of space-filled)
|
||||||
return combineLatest([
|
return api.queryMulti<[Vec<AccountId>, Vec<ITuple<[AccountId, Balance]>>, Vec<ITuple<[AccountId, Balance]>>]>([
|
||||||
api.query[section].candidates<Vec<AccountId>>(),
|
api.query[section].candidates,
|
||||||
api.query[section].members<Vec<ITuple<[AccountId, Balance]>>>(),
|
api.query[section].members,
|
||||||
api.query[section].runnersUp<Vec<ITuple<[AccountId, Balance]>>>()
|
api.query[section].runnersUp
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([candidates, members, runnersUp]): DerivedElectionsInfo => deriveElections(
|
map(([candidates, members, runnersUp]): DerivedElectionsInfo => ({
|
||||||
api,
|
|
||||||
candidates,
|
candidates,
|
||||||
members,
|
candidateCount: createType(api.registry, 'u32', candidates.length),
|
||||||
runnersUp,
|
candidacyBond: api.consts[section].candidacyBond as Balance,
|
||||||
api.consts[section].candidacyBond as Balance,
|
desiredSeats: api.consts[section].desiredMembers as u32,
|
||||||
api.consts[section].desiredMembers as u32,
|
members: members.sort((a, b): number => b[1].cmp(a[1])),
|
||||||
api.consts[section].termDuration as BlockNumber,
|
runnersUp: runnersUp.sort((a, b): number => b[1].cmp(a[1])),
|
||||||
api.consts[section].votingBond as Balance
|
termDuration: api.consts[section].termDuration as BlockNumber,
|
||||||
))
|
votingBond: api.consts[section].votingBond as Balance
|
||||||
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,15 @@ import { memo } from '../util';
|
|||||||
*/
|
*/
|
||||||
export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> {
|
export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> {
|
||||||
return memo((): Observable<DerivedHeartbeats> =>
|
return memo((): Observable<DerivedHeartbeats> =>
|
||||||
api.query.imOnline?.receivedHeartbeats && api.query.imOnline.authoredBlocks
|
api.query.imOnline?.receivedHeartbeats
|
||||||
? api.derive.staking.overview().pipe(
|
? api.derive.staking.overview().pipe(
|
||||||
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of(validators),
|
of(validators),
|
||||||
api.query.imOnline.receivedHeartbeats.multi<Option<Bytes>>(validators.map((_address, index): [SessionIndex, number] => [currentIndex, index])),
|
api.query.imOnline.receivedHeartbeats.multi<Option<Bytes>>(
|
||||||
api.query.imOnline.authoredBlocks.multi<u32>(validators.map((address): [SessionIndex, AccountId] => [currentIndex, address]))
|
validators.map((_address, index): [SessionIndex, number] => [currentIndex, index])),
|
||||||
|
api.query.imOnline.authoredBlocks.multi<u32>(
|
||||||
|
validators.map((address): [SessionIndex, AccountId] => [currentIndex, address]))
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
|
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces';
|
import { AccountId, BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
import { DeriveSocietyCandidate } from '../types';
|
import { DeriveSocietyCandidate } from '../types';
|
||||||
|
|
||||||
@@ -25,11 +25,8 @@ export function candidates (api: ApiInterfaceRx): () => Observable<DeriveSociety
|
|||||||
switchMap((candidates: Vec<Bid>): Observable<Result> =>
|
switchMap((candidates: Vec<Bid>): Observable<Result> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of(candidates),
|
of(candidates),
|
||||||
combineLatest(
|
api.query.society.suspendedCandidates.multi<ResultSuspend>(
|
||||||
candidates.map(({ who }: Bid): Observable<ResultSuspend> =>
|
candidates.map(({ who }): AccountId => who))
|
||||||
api.query.society.suspendedCandidates<ResultSuspend>(who)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
||||||
|
|||||||
@@ -7,33 +7,27 @@ import { AccountId, Balance, BlockNumber, StrikeCount, VouchingStatus, Vote } fr
|
|||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
import { DeriveSocietyMember } from '../types';
|
import { DeriveSocietyMember } from '../types';
|
||||||
|
|
||||||
import { Observable, combineLatest } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { bool, Option, Vec } from '@polkadot/types';
|
import { bool, Option, Vec } from '@polkadot/types';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
type ResultMulti = [Vec<ITuple<[BlockNumber, Balance]>>, StrikeCount];
|
type Result = [Vec<ITuple<[BlockNumber, Balance]>>, StrikeCount, Option<Vote>, bool, Option<VouchingStatus>];
|
||||||
type ResultSingle = [Option<Vote>, bool, Option<VouchingStatus>];
|
|
||||||
type Result = [ResultMulti, ResultSingle];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Get the member info for a society
|
* @description Get the member info for a society
|
||||||
*/
|
*/
|
||||||
export function member (api: ApiInterfaceRx): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
export function member (api: ApiInterfaceRx): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
||||||
return memo((accountId: AccountId): Observable<DeriveSocietyMember> =>
|
return memo((accountId: AccountId): Observable<DeriveSocietyMember> =>
|
||||||
combineLatest([
|
api.queryMulti<Result>([
|
||||||
api.queryMulti<ResultMulti>([
|
[api.query.society.payouts, accountId],
|
||||||
[api.query.society.payouts, accountId],
|
[api.query.society.strikes, accountId],
|
||||||
[api.query.society.strikes, accountId]
|
[api.query.society.defenderVotes, accountId],
|
||||||
]),
|
[api.query.society.suspendedMembers, accountId],
|
||||||
combineLatest([
|
[api.query.society.vouching, accountId]
|
||||||
api.query.society.defenderVotes<Option<Vote>>(accountId),
|
|
||||||
api.query.society.suspendedMembers<bool>(accountId),
|
|
||||||
api.query.society.vouching<Option<VouchingStatus>>(accountId)
|
|
||||||
])
|
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([[payouts, strikes], [defenderVote, suspended, vouching]]: Result): DeriveSocietyMember => ({
|
map(([payouts, strikes, defenderVote, suspended, vouching]: Result): DeriveSocietyMember => ({
|
||||||
accountId,
|
accountId,
|
||||||
payouts,
|
payouts,
|
||||||
isSuspended: suspended.isTrue,
|
isSuspended: suspended.isTrue,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { DerivedStakingOverview } from '../types';
|
|||||||
|
|
||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { createType } from '@polkadot/types';
|
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
@@ -24,10 +23,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
|||||||
switchMap(([{ currentEra, currentIndex, validatorCount }, { currentElected, validators }]) =>
|
switchMap(([{ currentEra, currentIndex, validatorCount }, { currentElected, validators }]) =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of({ currentElected, currentEra, currentIndex, validators, validatorCount }),
|
of({ currentElected, currentEra, currentIndex, validators, validatorCount }),
|
||||||
// this will change on a per block basis, keep it innermost (and it needs eraIndex)
|
api.query.staking.currentEraPointsEarned<EraPoints>(currentEra)
|
||||||
api.query.staking?.currentEraPointsEarned
|
|
||||||
? api.query.staking.currentEraPointsEarned<EraPoints>(currentEra)
|
|
||||||
: of(createType(api.registry, 'EraPoints'))
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([{ currentElected, currentEra, currentIndex, validators, validatorCount }, eraPoints]): DerivedStakingOverview => ({
|
map(([{ currentElected, currentEra, currentIndex, validators, validatorCount }, eraPoints]): DerivedStakingOverview => ({
|
||||||
|
|||||||
@@ -62,10 +62,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a
|
|||||||
const allIds = [...proposalIds, ...approvalIds];
|
const allIds = [...proposalIds, ...approvalIds];
|
||||||
|
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
// We are doing single subscriptions on all these, multi may yield old results
|
api.query.treasury.proposals.multi<Option<TreasuryProposal>>(allIds),
|
||||||
combineLatest(
|
|
||||||
allIds.map((id): Observable<Option<TreasuryProposal>> => api.query.treasury.proposals(id))
|
|
||||||
),
|
|
||||||
api.derive.council.proposals()
|
api.derive.council.proposals()
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DerivedCollectiveProposals]): DerivedTreasuryProposals =>
|
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DerivedCollectiveProposals]): DerivedTreasuryProposals =>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import jsonrpcMethod from '@polkadot/jsonrpc/create/method';
|
|||||||
import jsonrpcParam from '@polkadot/jsonrpc/create/param';
|
import jsonrpcParam from '@polkadot/jsonrpc/create/param';
|
||||||
import { Option, StorageKey, Vec, createClass } from '@polkadot/types';
|
import { Option, StorageKey, Vec, createClass } from '@polkadot/types';
|
||||||
import { createTypeUnsafe } from '@polkadot/types/codec';
|
import { createTypeUnsafe } from '@polkadot/types/codec';
|
||||||
import { assert, isFunction, isNull, isNumber, logger, u8aToU8a } from '@polkadot/util';
|
import { assert, isFunction, isNull, isNumber, isUndefined, logger, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { drr } from './rxjs';
|
import { drr } from './rxjs';
|
||||||
|
|
||||||
@@ -390,24 +390,19 @@ export default class Rpc implements RpcInterface {
|
|||||||
const type = key.outputType || 'Raw';
|
const type = key.outputType || 'Raw';
|
||||||
const hexKey = key.toHex();
|
const hexKey = key.toHex();
|
||||||
const meta = key.meta || EMPTY_META;
|
const meta = key.meta || EMPTY_META;
|
||||||
|
const found = changes.find(([key]): boolean => key === hexKey);
|
||||||
|
|
||||||
// if we don't find the value, this is our fallback
|
// if we don't find the value, this is our fallback
|
||||||
// - in the case of an array of values, fill the hole from the cache
|
// - in the case of an array of values, fill the hole from the cache
|
||||||
// - if a single result value, don't fill - it is not an update hole
|
// - if a single result value, don't fill - it is not an update hole
|
||||||
// - fallback to an empty option in all cases
|
// - fallback to an empty option in all cases
|
||||||
const emptyVal = (witCache && this._storageCache.get(hexKey)) || null;
|
const value = isUndefined(found)
|
||||||
|
? (witCache && this._storageCache.get(hexKey)) || null
|
||||||
// see if we have a result value for this specific key, fallback to the cache value
|
: found[1];
|
||||||
// when the value in the set is not available, or is null/empty.
|
|
||||||
const [, value] = changes.find(([key, value]): boolean =>
|
|
||||||
!isNull(value) && key === hexKey
|
|
||||||
) || [null, emptyVal];
|
|
||||||
const isEmpty = isNull(value);
|
const isEmpty = isNull(value);
|
||||||
const input = isEmpty
|
const input = isEmpty || this.treatAsHex(key)
|
||||||
? null
|
? value
|
||||||
: this.treatAsHex(key)
|
: u8aToU8a(value);
|
||||||
? value
|
|
||||||
: u8aToU8a(value);
|
|
||||||
|
|
||||||
// store the retrieved result - the only issue with this cache is that there is no
|
// store the retrieved result - the only issue with this cache is that there is no
|
||||||
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
// clearing of it, so very long running processes (not just a couple of hours, longer)
|
||||||
|
|||||||
Reference in New Issue
Block a user