Skip to content

Commit 987a2ec

Browse files
authored
Adjust multi to infer return types (#4002)
* Adjust multi to infer return types * some linting * Additional * Dedupe
1 parent 389c4c5 commit 987a2ec

File tree

30 files changed

+130
-142
lines changed

30 files changed

+130
-142
lines changed

packages/api-derive/src/accounts/identity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (acc
113113
return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
114114
api.query.identity?.identityOf
115115
? combineLatest([
116-
api.query.identity.identityOf.multi<Option<Registration>>(accountIds),
117-
api.query.identity.superOf.multi<Option<ITuple<[AccountId, Data]>>>(accountIds)
116+
api.query.identity.identityOf.multi(accountIds),
117+
api.query.identity.superOf.multi(accountIds)
118118
]).pipe(
119119
map(([identities, supers]) =>
120120
identities.map((identityOfOpt, index): DeriveHasIdentity => {

packages/api-derive/src/bounties/bounties.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
66
import type { Bytes, Option } from '@polkadot/types';
7-
import type { Bounty, BountyIndex, ProposalIndex } from '@polkadot/types/interfaces';
7+
import type { BountyIndex, ProposalIndex } from '@polkadot/types/interfaces';
8+
import type { PalletBountiesBounty } from '@polkadot/types/lookup';
89
import type { DeriveBounties, DeriveCollectiveProposal } from '../types';
910

1011
import { combineLatest, map, of, switchMap } from 'rxjs';
1112

1213
import { memo } from '../util';
1314
import { filterBountiesProposals } from './helpers/filterBountyProposals';
1415

15-
type Result = [Option<Bounty>[], Option<Bytes>[], BountyIndex[], DeriveCollectiveProposal[]];
16+
type Result = [Option<PalletBountiesBounty>[], Option<Bytes>[], BountyIndex[], DeriveCollectiveProposal[]];
1617

1718
function parseResult ([maybeBounties, maybeDescriptions, ids, bountyProposals]: Result): DeriveBounties {
1819
const bounties: DeriveBounties = [];
@@ -53,8 +54,8 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
5354
const ids = keys.map(({ args: [id] }) => id);
5455

5556
return combineLatest([
56-
bountyBase.bounties.multi<Option<Bounty>>(ids),
57-
bountyBase.bountyDescriptions.multi<Option<Bytes>>(ids),
57+
bountyBase.bounties.multi(ids),
58+
bountyBase.bountyDescriptions.multi(ids),
5859
of(ids),
5960
of(filterBountiesProposals(api, proposals))
6061
]);

packages/api-derive/src/collective/proposals.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: strin
4040
// however we have had cases on Edgeware where the indices have moved around after an
4141
// upgrade, which results in invalid on-chain data
4242
combineLatest(hashes.map((hash) =>
43-
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
44-
// however we have had cases on Edgeware where the indices have moved around after an
45-
// upgrade, which results in invalid on-chain data
4643
api.query[section].proposalOf<Option<Proposal>>(hash).pipe(
4744
catchError(() => of(null))
4845
)

packages/api-derive/src/democracy/dispatchQueue.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Option, u64, Vec } from '@polkadot/types';
7-
import type { BlockNumber, Hash, ReferendumIndex, Scheduled } from '@polkadot/types/interfaces';
6+
import type { Option, Vec } from '@polkadot/types';
7+
import type { BlockNumber, Hash, ReferendumIndex } from '@polkadot/types/interfaces';
8+
import type { PalletSchedulerScheduledV2 } from '@polkadot/types/lookup';
89
import type { ITuple } from '@polkadot/types/types';
910
import type { DeriveDispatch, DeriveProposalImage } from '../types';
1011

@@ -42,7 +43,7 @@ function queryQueue (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
4243
);
4344
}
4445

45-
function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option<Scheduled>[] | null)[]]> {
46+
function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option<PalletSchedulerScheduledV2>[] | null)[]]> {
4647
// We don't get entries, but rather we get the keys (triggered via finished referendums) and
4748
// the subscribe to those keys - this means we pickup when the schedulers actually executes
4849
// at a block, the entry for that block will become empty
@@ -56,11 +57,11 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt
5657
return blockNumbers.length
5758
? combineLatest([
5859
of(blockNumbers),
59-
// this should simply be api.query.scheduler.agenda.multi<Vec<Option<Scheduled>>>,
60+
// this should simply be api.query.scheduler.agenda.multi,
6061
// however we have had cases on Darwinia where the indices have moved around after an
6162
// upgrade, which results in invalid on-chain data
6263
combineLatest(blockNumbers.map((blockNumber) =>
63-
api.query.scheduler.agenda<Vec<Option<Scheduled>>>(blockNumber).pipe(
64+
api.query.scheduler.agenda(blockNumber).pipe(
6465
// this does create an issue since it discards all at that block
6566
catchError(() => of(null))
6667
)
@@ -86,7 +87,7 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
8687
const id = scheduled.maybeId.unwrap().toHex();
8788

8889
if (id.startsWith(DEMOCRACY_ID)) {
89-
const [, index] = api.registry.createType<ITuple<[u64, ReferendumIndex]>>('(u64, ReferendumIndex)', id);
90+
const [, index] = api.registry.createType('(u64, ReferendumIndex)', id);
9091
const imageHash = scheduled.call.args[0] as Hash;
9192

9293
result.push({ at, imageHash, index });

packages/api-derive/src/democracy/locks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Option } from '@polkadot/types';
7-
import type { AccountId, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
6+
import type { AccountId, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
7+
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
88
import type { BN } from '@polkadot/util';
99
import type { DeriveDemocracyLock } from '../types';
1010

@@ -25,7 +25,7 @@ function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: Referendu
2525
];
2626
}
2727

28-
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock {
28+
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: PalletDemocracyReferendumInfo): DeriveDemocracyLock {
2929
const { balance, vote } = accountVote.asStandard;
3030
const [referendumEnd, unlockAt] = referendum.isFinished
3131
? parseEnd(api, vote, referendum.asFinished)
@@ -57,13 +57,13 @@ function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<
5757
return of([]);
5858
}
5959

60-
return api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo | ReferendumInfoTo239>>(votes.map(([referendumId]) => referendumId)).pipe(
60+
return api.query.democracy.referendumInfoOf.multi(votes.map(([referendumId]) => referendumId)).pipe(
6161
map((referendums) =>
6262
votes
63-
.map((vote, index): [VotingDirectVote, ReferendumInfo | ReferendumInfoTo239 | null] =>
63+
.map((vote, index): [VotingDirectVote, PalletDemocracyReferendumInfo | ReferendumInfoTo239 | null] =>
6464
[vote, referendums[index].unwrapOr(null)]
6565
)
66-
.filter((item): item is [VotingDirectVote, ReferendumInfo] =>
66+
.filter((item): item is [VotingDirectVote, PalletDemocracyReferendumInfo] =>
6767
!!item[1] && isUndefined((item[1] as ReferendumInfoTo239).end) && item[0][1].isStandard
6868
)
6969
.map(([directVote, referendum]) =>

packages/api-derive/src/democracy/preimages.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Bytes, Option } from '@polkadot/types';
7-
import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
8-
import type { ITuple } from '@polkadot/types/types';
6+
import type { Hash } from '@polkadot/types/interfaces';
97
import type { DeriveProposalImage } from '../types';
108

119
import { map, of } from 'rxjs';
1210

1311
import { memo } from '../util';
1412
import { parseImage } from './util';
1513

16-
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
17-
1814
export function preimages (instanceId: string, api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
1915
return memo(instanceId, (hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
2016
hashes.length
21-
? api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
17+
? api.query.democracy.preimages.multi(hashes).pipe(
2218
map((images): (DeriveProposalImage | undefined)[] =>
2319
images.map((imageOpt) => parseImage(api, imageOpt))
2420
)

packages/api-derive/src/democracy/proposals.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export function proposals (instanceId: string, api: ApiInterfaceRx): () => Obser
5858
? combineLatest([
5959
of(proposals),
6060
api.derive.democracy.preimages(
61-
proposals.map(([, hash]): Hash => hash)),
62-
api.query.democracy.depositOf.multi<Depositors>(
63-
proposals.map(([index]): PropIndex => index))
61+
proposals.map(([, hash]) => hash)),
62+
api.query.democracy.depositOf.multi(
63+
proposals.map(([index]) => index))
6464
])
6565
: of<Result>([[], [], []])
6666
),

packages/api-derive/src/democracy/referendumsFinished.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Option } from '@polkadot/types';
7-
import type { ReferendumInfo, ReferendumInfoFinished } from '@polkadot/types/interfaces';
6+
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
87

98
import { map, switchMap } from 'rxjs';
109

1110
import { memo } from '../util';
1211

12+
type ReferendumInfoFinished = PalletDemocracyReferendumInfo['asFinished'];
13+
1314
export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): () => Observable<ReferendumInfoFinished[]> {
1415
return memo(instanceId, (): Observable<ReferendumInfoFinished[]> =>
1516
api.derive.democracy.referendumIds().pipe(
1617
switchMap((ids) =>
17-
api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)
18+
api.query.democracy.referendumInfoOf.multi(ids)
1819
),
1920
map((infos): ReferendumInfoFinished[] =>
2021
infos
2122
.map((optInfo) => optInfo.unwrapOr(null))
22-
.filter((info): info is ReferendumInfo => !!info && info.isFinished)
23+
.filter((info): info is PalletDemocracyReferendumInfo => !!info && info.isFinished)
2324
.map((info) => info.asFinished)
2425
)
2526
)

packages/api-derive/src/democracy/referendumsInfo.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
66
import type { Option, Vec } from '@polkadot/types';
7-
import type { AccountId, ReferendumInfo, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces';
7+
import type { AccountId, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces';
8+
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
89
import type { BN } from '@polkadot/util';
910
import type { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
1011

@@ -123,8 +124,8 @@ export function _referendumsVotes (instanceId: string, api: ApiInterfaceRx): (re
123124
);
124125
}
125126

126-
export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (index: BN, info: Option<ReferendumInfo | ReferendumInfoTo239>) => Observable<DeriveReferendum | null> {
127-
return memo(instanceId, (index: BN, info: Option<ReferendumInfo | ReferendumInfoTo239>): Observable<DeriveReferendum | null> => {
127+
export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (index: BN, info: Option<PalletDemocracyReferendumInfo | ReferendumInfoTo239>) => Observable<DeriveReferendum | null> {
128+
return memo(instanceId, (index: BN, info: Option<PalletDemocracyReferendumInfo | ReferendumInfoTo239>): Observable<DeriveReferendum | null> => {
128129
const status = getStatus(info);
129130

130131
return status
@@ -143,7 +144,7 @@ export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (inde
143144
export function referendumsInfo (instanceId: string, api: ApiInterfaceRx): (ids: BN[]) => Observable<DeriveReferendum[]> {
144145
return memo(instanceId, (ids: BN[]): Observable<DeriveReferendum[]> =>
145146
ids.length
146-
? api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids).pipe(
147+
? api.query.democracy.referendumInfoOf.multi(ids).pipe(
147148
switchMap((infos): Observable<(DeriveReferendum | null)[]> =>
148149
combineLatest(
149150
ids.map((id, index): Observable<DeriveReferendum | null> =>

packages/api-derive/src/democracy/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type { Vec } from '@polkadot/types';
5-
import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, ReferendumStatus, Vote, VoteThreshold } from '@polkadot/types/interfaces';
5+
import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, Vote, VoteThreshold } from '@polkadot/types/interfaces';
6+
import type { PalletDemocracyReferendumStatus } from '@polkadot/types/lookup';
67
import type { BN } from '@polkadot/util';
78

89
export interface DeriveDemocracyLock {
@@ -48,7 +49,7 @@ export interface DeriveReferendum {
4849
index: ReferendumIndex;
4950
image?: DeriveProposalImage;
5051
imageHash: Hash;
51-
status: ReferendumStatus | ReferendumInfoTo239;
52+
status: PalletDemocracyReferendumStatus | ReferendumInfoTo239;
5253
}
5354

5455
export interface DeriveReferendumVote {

0 commit comments

Comments
 (0)