diff --git a/packages/api-derive/src/accounts/identity.ts b/packages/api-derive/src/accounts/identity.ts index 18aac02b3e..fb24bd5e13 100644 --- a/packages/api-derive/src/accounts/identity.ts +++ b/packages/api-derive/src/accounts/identity.ts @@ -113,8 +113,8 @@ export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (acc return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable => api.query.identity?.identityOf ? combineLatest([ - api.query.identity.identityOf.multi>(accountIds), - api.query.identity.superOf.multi>>(accountIds) + api.query.identity.identityOf.multi(accountIds), + api.query.identity.superOf.multi(accountIds) ]).pipe( map(([identities, supers]) => identities.map((identityOfOpt, index): DeriveHasIdentity => { diff --git a/packages/api-derive/src/bounties/bounties.ts b/packages/api-derive/src/bounties/bounties.ts index 96635b4b8f..038e26168a 100644 --- a/packages/api-derive/src/bounties/bounties.ts +++ b/packages/api-derive/src/bounties/bounties.ts @@ -4,7 +4,8 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Bytes, Option } from '@polkadot/types'; -import type { Bounty, BountyIndex, ProposalIndex } from '@polkadot/types/interfaces'; +import type { BountyIndex, ProposalIndex } from '@polkadot/types/interfaces'; +import type { PalletBountiesBounty } from '@polkadot/types/lookup'; import type { DeriveBounties, DeriveCollectiveProposal } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -12,7 +13,7 @@ import { combineLatest, map, of, switchMap } from 'rxjs'; import { memo } from '../util'; import { filterBountiesProposals } from './helpers/filterBountyProposals'; -type Result = [Option[], Option[], BountyIndex[], DeriveCollectiveProposal[]]; +type Result = [Option[], Option[], BountyIndex[], DeriveCollectiveProposal[]]; function parseResult ([maybeBounties, maybeDescriptions, ids, bountyProposals]: Result): DeriveBounties { const bounties: DeriveBounties = []; @@ -53,8 +54,8 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ const ids = keys.map(({ args: [id] }) => id); return combineLatest([ - bountyBase.bounties.multi>(ids), - bountyBase.bountyDescriptions.multi>(ids), + bountyBase.bounties.multi(ids), + bountyBase.bountyDescriptions.multi(ids), of(ids), of(filterBountiesProposals(api, proposals)) ]); diff --git a/packages/api-derive/src/collective/proposals.ts b/packages/api-derive/src/collective/proposals.ts index 1fbe334f7c..60c7dc6b4b 100644 --- a/packages/api-derive/src/collective/proposals.ts +++ b/packages/api-derive/src/collective/proposals.ts @@ -40,9 +40,6 @@ function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: strin // however we have had cases on Edgeware where the indices have moved around after an // upgrade, which results in invalid on-chain data combineLatest(hashes.map((hash) => - // this should simply be api.query[section].proposalOf.multi>(hashes), - // however we have had cases on Edgeware where the indices have moved around after an - // upgrade, which results in invalid on-chain data api.query[section].proposalOf>(hash).pipe( catchError(() => of(null)) ) diff --git a/packages/api-derive/src/democracy/dispatchQueue.ts b/packages/api-derive/src/democracy/dispatchQueue.ts index 30fa29a978..ff6dbfe838 100644 --- a/packages/api-derive/src/democracy/dispatchQueue.ts +++ b/packages/api-derive/src/democracy/dispatchQueue.ts @@ -3,8 +3,9 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Option, u64, Vec } from '@polkadot/types'; -import type { BlockNumber, Hash, ReferendumIndex, Scheduled } from '@polkadot/types/interfaces'; +import type { Option, Vec } from '@polkadot/types'; +import type { BlockNumber, Hash, ReferendumIndex } from '@polkadot/types/interfaces'; +import type { PalletSchedulerScheduledV2 } from '@polkadot/types/lookup'; import type { ITuple } from '@polkadot/types/types'; import type { DeriveDispatch, DeriveProposalImage } from '../types'; @@ -42,7 +43,7 @@ function queryQueue (api: ApiInterfaceRx): Observable { ); } -function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option[] | null)[]]> { +function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option[] | null)[]]> { // We don't get entries, but rather we get the keys (triggered via finished referendums) and // the subscribe to those keys - this means we pickup when the schedulers actually executes // at a block, the entry for that block will become empty @@ -56,11 +57,11 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt return blockNumbers.length ? combineLatest([ of(blockNumbers), - // this should simply be api.query.scheduler.agenda.multi>>, + // this should simply be api.query.scheduler.agenda.multi, // however we have had cases on Darwinia where the indices have moved around after an // upgrade, which results in invalid on-chain data combineLatest(blockNumbers.map((blockNumber) => - api.query.scheduler.agenda>>(blockNumber).pipe( + api.query.scheduler.agenda(blockNumber).pipe( // this does create an issue since it discards all at that block catchError(() => of(null)) ) @@ -86,7 +87,7 @@ function queryScheduler (api: ApiInterfaceRx): Observable { const id = scheduled.maybeId.unwrap().toHex(); if (id.startsWith(DEMOCRACY_ID)) { - const [, index] = api.registry.createType>('(u64, ReferendumIndex)', id); + const [, index] = api.registry.createType('(u64, ReferendumIndex)', id); const imageHash = scheduled.call.args[0] as Hash; result.push({ at, imageHash, index }); diff --git a/packages/api-derive/src/democracy/locks.ts b/packages/api-derive/src/democracy/locks.ts index accf4d7501..cb1b53b069 100644 --- a/packages/api-derive/src/democracy/locks.ts +++ b/packages/api-derive/src/democracy/locks.ts @@ -3,8 +3,8 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Option } from '@polkadot/types'; -import type { AccountId, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces'; +import type { AccountId, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces'; +import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; import type { DeriveDemocracyLock } from '../types'; @@ -25,7 +25,7 @@ function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: Referendu ]; } -function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock { +function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: PalletDemocracyReferendumInfo): DeriveDemocracyLock { const { balance, vote } = accountVote.asStandard; const [referendumEnd, unlockAt] = referendum.isFinished ? parseEnd(api, vote, referendum.asFinished) @@ -57,13 +57,13 @@ function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable< return of([]); } - return api.query.democracy.referendumInfoOf.multi>(votes.map(([referendumId]) => referendumId)).pipe( + return api.query.democracy.referendumInfoOf.multi(votes.map(([referendumId]) => referendumId)).pipe( map((referendums) => votes - .map((vote, index): [VotingDirectVote, ReferendumInfo | ReferendumInfoTo239 | null] => + .map((vote, index): [VotingDirectVote, PalletDemocracyReferendumInfo | ReferendumInfoTo239 | null] => [vote, referendums[index].unwrapOr(null)] ) - .filter((item): item is [VotingDirectVote, ReferendumInfo] => + .filter((item): item is [VotingDirectVote, PalletDemocracyReferendumInfo] => !!item[1] && isUndefined((item[1] as ReferendumInfoTo239).end) && item[0][1].isStandard ) .map(([directVote, referendum]) => diff --git a/packages/api-derive/src/democracy/preimages.ts b/packages/api-derive/src/democracy/preimages.ts index e86007412a..506bbb96cd 100644 --- a/packages/api-derive/src/democracy/preimages.ts +++ b/packages/api-derive/src/democracy/preimages.ts @@ -3,9 +3,7 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Bytes, Option } from '@polkadot/types'; -import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces'; -import type { ITuple } from '@polkadot/types/types'; +import type { Hash } from '@polkadot/types/interfaces'; import type { DeriveProposalImage } from '../types'; import { map, of } from 'rxjs'; @@ -13,12 +11,10 @@ import { map, of } from 'rxjs'; import { memo } from '../util'; import { parseImage } from './util'; -type PreImage = Option>; - export function preimages (instanceId: string, api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> { return memo(instanceId, (hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> => hashes.length - ? api.query.democracy.preimages.multi(hashes).pipe( + ? api.query.democracy.preimages.multi(hashes).pipe( map((images): (DeriveProposalImage | undefined)[] => images.map((imageOpt) => parseImage(api, imageOpt)) ) diff --git a/packages/api-derive/src/democracy/proposals.ts b/packages/api-derive/src/democracy/proposals.ts index 3e15c4f1c1..76d3f793dd 100644 --- a/packages/api-derive/src/democracy/proposals.ts +++ b/packages/api-derive/src/democracy/proposals.ts @@ -58,9 +58,9 @@ export function proposals (instanceId: string, api: ApiInterfaceRx): () => Obser ? combineLatest([ of(proposals), api.derive.democracy.preimages( - proposals.map(([, hash]): Hash => hash)), - api.query.democracy.depositOf.multi( - proposals.map(([index]): PropIndex => index)) + proposals.map(([, hash]) => hash)), + api.query.democracy.depositOf.multi( + proposals.map(([index]) => index)) ]) : of([[], [], []]) ), diff --git a/packages/api-derive/src/democracy/referendumsFinished.ts b/packages/api-derive/src/democracy/referendumsFinished.ts index 2fb3bcde07..813e1d7656 100644 --- a/packages/api-derive/src/democracy/referendumsFinished.ts +++ b/packages/api-derive/src/democracy/referendumsFinished.ts @@ -3,23 +3,24 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Option } from '@polkadot/types'; -import type { ReferendumInfo, ReferendumInfoFinished } from '@polkadot/types/interfaces'; +import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup'; import { map, switchMap } from 'rxjs'; import { memo } from '../util'; +type ReferendumInfoFinished = PalletDemocracyReferendumInfo['asFinished']; + export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): () => Observable { return memo(instanceId, (): Observable => api.derive.democracy.referendumIds().pipe( switchMap((ids) => - api.query.democracy.referendumInfoOf.multi>(ids) + api.query.democracy.referendumInfoOf.multi(ids) ), map((infos): ReferendumInfoFinished[] => infos .map((optInfo) => optInfo.unwrapOr(null)) - .filter((info): info is ReferendumInfo => !!info && info.isFinished) + .filter((info): info is PalletDemocracyReferendumInfo => !!info && info.isFinished) .map((info) => info.asFinished) ) ) diff --git a/packages/api-derive/src/democracy/referendumsInfo.ts b/packages/api-derive/src/democracy/referendumsInfo.ts index 9a7363bc2a..0e864f0df9 100644 --- a/packages/api-derive/src/democracy/referendumsInfo.ts +++ b/packages/api-derive/src/democracy/referendumsInfo.ts @@ -4,7 +4,8 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Option, Vec } from '@polkadot/types'; -import type { AccountId, ReferendumInfo, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces'; +import type { AccountId, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces'; +import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; import type { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types'; @@ -123,8 +124,8 @@ export function _referendumsVotes (instanceId: string, api: ApiInterfaceRx): (re ); } -export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (index: BN, info: Option) => Observable { - return memo(instanceId, (index: BN, info: Option): Observable => { +export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (index: BN, info: Option) => Observable { + return memo(instanceId, (index: BN, info: Option): Observable => { const status = getStatus(info); return status @@ -143,7 +144,7 @@ export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (inde export function referendumsInfo (instanceId: string, api: ApiInterfaceRx): (ids: BN[]) => Observable { return memo(instanceId, (ids: BN[]): Observable => ids.length - ? api.query.democracy.referendumInfoOf.multi>(ids).pipe( + ? api.query.democracy.referendumInfoOf.multi(ids).pipe( switchMap((infos): Observable<(DeriveReferendum | null)[]> => combineLatest( ids.map((id, index): Observable => diff --git a/packages/api-derive/src/democracy/types.ts b/packages/api-derive/src/democracy/types.ts index 39a2fd599f..c4d48dcf3b 100644 --- a/packages/api-derive/src/democracy/types.ts +++ b/packages/api-derive/src/democracy/types.ts @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import type { Vec } from '@polkadot/types'; -import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, ReferendumStatus, Vote, VoteThreshold } from '@polkadot/types/interfaces'; +import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, Vote, VoteThreshold } from '@polkadot/types/interfaces'; +import type { PalletDemocracyReferendumStatus } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; export interface DeriveDemocracyLock { @@ -48,7 +49,7 @@ export interface DeriveReferendum { index: ReferendumIndex; image?: DeriveProposalImage; imageHash: Hash; - status: ReferendumStatus | ReferendumInfoTo239; + status: PalletDemocracyReferendumStatus | ReferendumInfoTo239; } export interface DeriveReferendumVote { diff --git a/packages/api-derive/src/democracy/util.ts b/packages/api-derive/src/democracy/util.ts index 5c524fbdfe..ff64ef09d7 100644 --- a/packages/api-derive/src/democracy/util.ts +++ b/packages/api-derive/src/democracy/util.ts @@ -3,7 +3,8 @@ import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Bytes, Option } from '@polkadot/types'; -import type { AccountId, Balance, BlockNumber, PreimageStatus, Proposal, ReferendumInfo, ReferendumInfoTo239, ReferendumStatus, Tally, VoteThreshold } from '@polkadot/types/interfaces'; +import type { AccountId, Balance, BlockNumber, PreimageStatus, Proposal, ReferendumInfoTo239, Tally } from '@polkadot/types/interfaces'; +import type { PalletDemocracyReferendumInfo, PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup'; import type { ITuple } from '@polkadot/types/types'; import type { DeriveProposalImage, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes, DeriveReferendumVoteState } from '../types'; @@ -18,12 +19,12 @@ interface ApproxState { votedTotal: BN; } -function isOldInfo (info: ReferendumInfo | ReferendumInfoTo239): info is ReferendumInfoTo239 { +function isOldInfo (info: PalletDemocracyReferendumInfo | ReferendumInfoTo239): info is ReferendumInfoTo239 { return !!(info as ReferendumInfoTo239).proposalHash; } -function isCurrentStatus (status: ReferendumStatus | ReferendumInfoTo239): status is ReferendumStatus { - return !!(status as ReferendumStatus).tally; +function isCurrentStatus (status: PalletDemocracyReferendumStatus | ReferendumInfoTo239): status is PalletDemocracyReferendumStatus { + return !!(status as PalletDemocracyReferendumStatus).tally; } function isCurrentPreimage (api: ApiInterfaceRx, imageOpt: Option | Option): imageOpt is Option { @@ -57,18 +58,18 @@ export function compareRationals (n1: BN, d1: BN, n2: BN, d2: BN): boolean { } } -function calcPassingOther (threshold: VoteThreshold, sqrtElectorate: BN, { votedAye, votedNay, votedTotal }: ApproxState): boolean { +function calcPassingOther (threshold: PalletDemocracyVoteThreshold, sqrtElectorate: BN, { votedAye, votedNay, votedTotal }: ApproxState): boolean { const sqrtVoters = bnSqrt(votedTotal); return sqrtVoters.isZero() ? false - : threshold.isSupermajorityapproval + : threshold.isSuperMajorityApprove ? compareRationals(votedNay, sqrtVoters, votedAye, sqrtElectorate) : compareRationals(votedNay, sqrtElectorate, votedAye, sqrtVoters); } -export function calcPassing (threshold: VoteThreshold, sqrtElectorate: BN, state: ApproxState): boolean { - return threshold.isSimplemajority +export function calcPassing (threshold: PalletDemocracyVoteThreshold, sqrtElectorate: BN, state: ApproxState): boolean { + return threshold.isSimpleMajority ? state.votedAye.gt(state.votedNay) : calcPassingOther(threshold, sqrtElectorate, state); } @@ -134,7 +135,7 @@ export function calcVotes (sqrtElectorate: BN, referendum: DeriveReferendum, vot }; } -export function getStatus (info: Option): ReferendumStatus | ReferendumInfoTo239 | null { +export function getStatus (info: Option): PalletDemocracyReferendumStatus | ReferendumInfoTo239 | null { if (info.isNone) { return null; } diff --git a/packages/api-derive/src/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts index 62bd5c2cfc..03ee53826f 100644 --- a/packages/api-derive/src/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -3,8 +3,9 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Bytes, Option, u32 } from '@polkadot/types'; +import type { Option, u32, WrapperOpaque } from '@polkadot/types'; import type { AccountId } from '@polkadot/types/interfaces'; +import type { PalletImOnlineBoundedOpaqueNetworkState } from '@polkadot/types/lookup'; import type { DeriveHeartbeats } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -13,7 +14,9 @@ import { BN_ZERO } from '@polkadot/util'; import { memo } from '../util'; -function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbeats, AccountId[], Option[], u32[]]): DeriveHeartbeats { +type HeartbeatsOpt = Option>; + +function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbeats, AccountId[], HeartbeatsOpt[], u32[]]): DeriveHeartbeats { validators.forEach((validator, index): void => { const validatorId = validator.toString(); const blockCount = numBlocks[index]; @@ -39,13 +42,13 @@ export function receivedHeartbeats (instanceId: string, api: ApiInterfaceRx): () return memo(instanceId, (): Observable => api.query.imOnline?.receivedHeartbeats ? api.derive.staking.overview().pipe( - switchMap(({ currentIndex, validators }): Observable<[DeriveHeartbeats, AccountId[], Option[], u32[]]> => + switchMap(({ currentIndex, validators }): Observable<[DeriveHeartbeats, AccountId[], HeartbeatsOpt[], u32[]]> => combineLatest([ of({}), of(validators), - api.query.imOnline.receivedHeartbeats.multi>( + api.query.imOnline.receivedHeartbeats.multi( validators.map((_address, index) => [currentIndex, index])), - api.query.imOnline.authoredBlocks.multi( + api.query.imOnline.authoredBlocks.multi( validators.map((address) => [currentIndex, address])) ]) ), diff --git a/packages/api-derive/src/society/candidates.ts b/packages/api-derive/src/society/candidates.ts index f392b71e40..7388e64438 100644 --- a/packages/api-derive/src/society/candidates.ts +++ b/packages/api-derive/src/society/candidates.ts @@ -24,7 +24,7 @@ export function candidates (instanceId: string, api: ApiInterfaceRx): () => Obse switchMap((candidates: Vec): Observable => combineLatest([ of(candidates), - api.query.society.suspendedCandidates.multi( + api.query.society.suspendedCandidates.multi( candidates.map(({ who }): AccountId => who)) ]) ), diff --git a/packages/api-derive/src/society/members.ts b/packages/api-derive/src/society/members.ts index 633d5a252d..d0fdb481d4 100644 --- a/packages/api-derive/src/society/members.ts +++ b/packages/api-derive/src/society/members.ts @@ -3,9 +3,7 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { bool, Option, Vec } from '@polkadot/types'; -import type { AccountId, Balance, BlockNumber, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces'; -import type { ITuple } from '@polkadot/types/types'; +import type { AccountId } from '@polkadot/types/interfaces'; import type { DeriveSocietyMember } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -16,11 +14,11 @@ export function _members (instanceId: string, api: ApiInterfaceRx): (accountIds: return memo(instanceId, (accountIds: AccountId[]): Observable => combineLatest([ of(accountIds), - api.query.society.payouts.multi>>(accountIds), - api.query.society.strikes.multi(accountIds), - api.query.society.defenderVotes.multi>(accountIds), - api.query.society.suspendedMembers.multi(accountIds), - api.query.society.vouching.multi>(accountIds) + api.query.society.payouts.multi(accountIds), + api.query.society.strikes.multi(accountIds), + api.query.society.defenderVotes.multi(accountIds), + api.query.society.suspendedMembers.multi(accountIds), + api.query.society.vouching.multi(accountIds) ]).pipe( map(([accountIds, payouts, strikes, defenderVotes, suspended, vouching]) => accountIds.map((accountId, index) => ({ diff --git a/packages/api-derive/src/staking/erasPoints.ts b/packages/api-derive/src/staking/erasPoints.ts index 428d3845c6..7d38b7d66c 100644 --- a/packages/api-derive/src/staking/erasPoints.ts +++ b/packages/api-derive/src/staking/erasPoints.ts @@ -48,7 +48,7 @@ export function _erasPoints (instanceId: string, api: ApiInterfaceRx): (eras: Er return !remaining.length ? of(cached) - : api.query.staking.erasRewardPoints.multi(remaining).pipe( + : api.query.staking.erasRewardPoints.multi(remaining).pipe( map((points): DeriveEraPoints[] => { const query = mapPoints(remaining, points); diff --git a/packages/api-derive/src/staking/erasRewards.ts b/packages/api-derive/src/staking/erasRewards.ts index 804494def6..22572fe471 100644 --- a/packages/api-derive/src/staking/erasRewards.ts +++ b/packages/api-derive/src/staking/erasRewards.ts @@ -38,7 +38,7 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E return of(cached); } - return api.query.staking.erasValidatorReward.multi>(remaining).pipe( + return api.query.staking.erasValidatorReward.multi(remaining).pipe( map((optRewards) => { const query = mapRewards(remaining, optRewards); diff --git a/packages/api-derive/src/staking/keys.ts b/packages/api-derive/src/staking/keys.ts index 41aec5c545..a6f2b27cc3 100644 --- a/packages/api-derive/src/staking/keys.ts +++ b/packages/api-derive/src/staking/keys.ts @@ -4,7 +4,8 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Option, Vec } from '@polkadot/types'; -import type { AccountId, Keys } from '@polkadot/types/interfaces'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { NodeRuntimeSessionKeys } from '@polkadot/types/lookup'; import type { ITuple } from '@polkadot/types/types'; import type { DeriveStakingKeys } from './types'; @@ -12,13 +13,17 @@ import { combineLatest, map, of, switchMap } from 'rxjs'; import { memo } from '../util'; -function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Keys][], nextKeys: Option): DeriveStakingKeys { +function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, NodeRuntimeSessionKeys | AccountId[]][], nextKeys: Option): DeriveStakingKeys { const sessionIds = (queuedKeys.find(([currentId]) => currentId.eq(stashId)) || [undefined, [] as AccountId[]])[1]; const nextSessionIds = nextKeys.unwrapOr([] as AccountId[]); return { - nextSessionIds, - sessionIds + nextSessionIds: Array.isArray(nextSessionIds) + ? nextSessionIds + : [...nextSessionIds.values()] as AccountId[], + sessionIds: Array.isArray(sessionIds) + ? sessionIds + : [...sessionIds.values()] as AccountId[] }; } @@ -33,13 +38,13 @@ export function keys (instanceId: string, api: ApiInterfaceRx): (stashId: Uint8A export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable { return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable => stashIds.length - ? api.query.session.queuedKeys>>().pipe( - switchMap((queuedKeys): Observable<[Vec>, Option[]]> => + ? api.query.session.queuedKeys().pipe( + switchMap((queuedKeys): Observable<[Vec>, Option[]]> => combineLatest([ of(queuedKeys), api.consts.session?.dedupKeyPrefix - ? api.query.session.nextKeys.multi>(stashIds.map((stashId) => [api.consts.session.dedupKeyPrefix, stashId])) - : api.query.session.nextKeys.multi>(stashIds) + ? api.query.session.nextKeys.multi(stashIds.map((stashId) => [api.consts.session.dedupKeyPrefix, stashId])) + : api.query.session.nextKeys.multi(stashIds) ]) ), map(([queuedKeys, nextKeys]) => diff --git a/packages/api-derive/src/staking/query.ts b/packages/api-derive/src/staking/query.ts index 75dfc91224..91624239f6 100644 --- a/packages/api-derive/src/staking/query.ts +++ b/packages/api-derive/src/staking/query.ts @@ -34,7 +34,7 @@ function getLedgers (api: ApiInterfaceRx, optIds: (Option | null)[], return ( ids.length - ? api.query.staking.ledger.multi>(ids) + ? api.query.staking.ledger.multi(ids) : of([]) ).pipe( map((optLedgers): Option[] => { @@ -57,19 +57,19 @@ function getStashInfo (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: Er return combineLatest([ withController || withLedger - ? api.query.staking.bonded.multi>(stashIds) + ? api.query.staking.bonded.multi(stashIds) : of(stashIds.map(() => null)), withNominations - ? api.query.staking.nominators.multi>(stashIds) + ? api.query.staking.nominators.multi(stashIds) : of(stashIds.map(() => emptyNoms)), withDestination - ? api.query.staking.payee.multi(stashIds) + ? api.query.staking.payee.multi(stashIds) : of(stashIds.map(() => emptyRewa)), withPrefs - ? api.query.staking.validators.multi(stashIds) + ? api.query.staking.validators.multi(stashIds) : of(stashIds.map(() => emptyPrefs)), withExposure - ? api.query.staking.erasStakers.multi(stashIds.map((stashId) => [activeEra, stashId])) + ? api.query.staking.erasStakers.multi(stashIds.map((stashId) => [activeEra, stashId])) : of(stashIds.map(() => emptyExpo)) ]); } diff --git a/packages/api-derive/src/staking/stakerPrefs.ts b/packages/api-derive/src/staking/stakerPrefs.ts index 9ffeea6c69..842172db28 100644 --- a/packages/api-derive/src/staking/stakerPrefs.ts +++ b/packages/api-derive/src/staking/stakerPrefs.ts @@ -3,7 +3,7 @@ import type { Observable } from 'rxjs'; import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { EraIndex, ValidatorPrefs } from '@polkadot/types/interfaces'; +import type { EraIndex } from '@polkadot/types/interfaces'; import type { DeriveStakerPrefs } from '../types'; import { map, switchMap } from 'rxjs'; @@ -13,7 +13,7 @@ import { memo } from '../util'; export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { // eslint-disable-next-line @typescript-eslint/no-unused-vars return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable => - api.query.staking.erasValidatorPrefs.multi(eras.map((era) => [era, accountId])).pipe( + api.query.staking.erasValidatorPrefs.multi(eras.map((era) => [era, accountId])).pipe( map((all): DeriveStakerPrefs[] => all.map((validatorPrefs, index): DeriveStakerPrefs => ({ era: eras[index], diff --git a/packages/api-derive/src/treasury/proposals.ts b/packages/api-derive/src/treasury/proposals.ts index a34721b69a..8be06d1f07 100644 --- a/packages/api-derive/src/treasury/proposals.ts +++ b/packages/api-derive/src/treasury/proposals.ts @@ -59,7 +59,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a const allIds = [...proposalIds, ...approvalIds]; return combineLatest([ - api.query.treasury.proposals.multi>(allIds), + api.query.treasury.proposals.multi(allIds), api.derive.council ? api.derive.council.proposals() : of([] as DeriveCollectiveProposal[]) diff --git a/packages/api/src/checkTypes.manual.ts b/packages/api/src/checkTypes.manual.ts index 5c36457fb8..e8ae4da50a 100644 --- a/packages/api/src/checkTypes.manual.ts +++ b/packages/api/src/checkTypes.manual.ts @@ -82,7 +82,7 @@ async function query (api: ApiPromise, pairs: TestKeyringMap): Promise { const oldBal = await api.query.balances.totalIssuance.at('abcd'); // It's hard to correctly type .multi. Expected: `Balance[]`, actual: Codec[]. // In the meantime, we can case with `` (this is not available on recent chains) - const multi = await api.query.balances.freeBalance.multi([pairs.alice.address, pairs.bob.address]); + const multi = await api.query.balances.freeBalance.multi([pairs.alice.address, pairs.bob.address]); console.log('query types:', bar, bal, bal2, override, oldBal, multi); diff --git a/packages/api/src/types/storage.ts b/packages/api/src/types/storage.ts index de6c9f3415..c0ee653688 100644 --- a/packages/api/src/types/storage.ts +++ b/packages/api/src/types/storage.ts @@ -8,13 +8,19 @@ import type { StorageEntry } from '@polkadot/types/primitive/types'; import type { AnyFunction, AnyTuple, Callback, Codec, IStorageKey } from '@polkadot/types/types'; import type { ApiTypes, DropLast, MethodResult, ObsInnerType, PaginationOptions, PromiseOrObs, UnsubscribePromise } from './base'; -interface StorageEntryObservableMulti { - (args: (unknown[] | unknown)[]): Observable; +type AsCodec = R extends Codec + ? R + : Codec; + +type ReturnCodec = AsCodec>>; + +interface StorageEntryObservableMulti { + (args: (unknown[] | unknown)[]): Observable; } -interface StorageEntryPromiseMulti { - (args: (unknown[] | unknown)[]): Promise; - (args: (unknown[] | unknown)[], callback: Callback): UnsubscribePromise; +interface StorageEntryPromiseMulti { + (args: (unknown[] | unknown)[]): Promise; + (args: (unknown[] | unknown)[], callback: Callback): UnsubscribePromise; } export interface StorageEntryPromiseOverloads { @@ -52,28 +58,23 @@ export interface QueryableStorageAt extends AugmentedQ [key: string]: QueryableModuleStorageAt; } -export interface StorageEntryBase { - at: >>(hash: Hash | Uint8Array | string, ...args: Parameters) => PromiseOrObs; +export interface StorageEntryBase extends StorageEntryBaseAt { + at: >(hash: Hash | Uint8Array | string, ...args: Parameters) => PromiseOrObs; creator: StorageEntry; - entries: >, K extends AnyTuple = A>(...args: DropLast>) => PromiseOrObs, T][]>; - entriesAt: >, K extends AnyTuple = A>(hash: Hash | Uint8Array | string, ...args: DropLast>) => PromiseOrObs, T][]>; - entriesPaged: >, K extends AnyTuple = A>(opts: PaginationOptions[0]>) => PromiseOrObs, T][]>; - hash: (...args: Parameters) => PromiseOrObs; - is: (key: IStorageKey) => key is IStorageKey; - key: (...args: Parameters) => string; - keyPrefix: (...args: DropLast>) => string; - keys: (...args: DropLast>) => PromiseOrObs[]>; + entriesAt: , K extends AnyTuple = A>(hash: Hash | Uint8Array | string, ...args: DropLast>) => PromiseOrObs, T][]>; + entriesPaged: , K extends AnyTuple = A>(opts: PaginationOptions[0]>) => PromiseOrObs, T][]>; keysAt: (hash: Hash | Uint8Array | string, ...args: DropLast>) => PromiseOrObs[]>; keysPaged: (opts: PaginationOptions[0]>) => PromiseOrObs[]>; // @deprecated The underlying RPC this been marked unsafe and is generally not exposed - range: >>([from, to]: [Hash | Uint8Array | string, Hash | Uint8Array | string | undefined] | [Hash | Uint8Array | string], ...args: Parameters) => PromiseOrObs; - size: (...args: Parameters) => PromiseOrObs; + range: >([from, to]: [Hash | Uint8Array | string, Hash | Uint8Array | string | undefined] | [Hash | Uint8Array | string], ...args: Parameters) => PromiseOrObs; sizeAt: (hash: Hash | Uint8Array | string, ...args: Parameters) => PromiseOrObs; - multi: ApiType extends 'rxjs' ? StorageEntryObservableMulti : StorageEntryPromiseMulti; + multi: ApiType extends 'rxjs' + ? StorageEntryObservableMulti> + : StorageEntryPromiseMulti>; } export interface StorageEntryBaseAt { - entries: >, K extends AnyTuple = A>(...args: DropLast>) => PromiseOrObs, T][]>; + entries: , K extends AnyTuple = A>(...args: DropLast>) => PromiseOrObs, T][]>; hash: (...args: Parameters) => PromiseOrObs; is: (key: IStorageKey) => key is IStorageKey; key: (...args: Parameters) => string; diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index 8cc8d52fce..fdacda8964 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -41,10 +41,6 @@ function entrySignature (lookup: PortableRegistry, allDefs: Record t.join(' | ')); const defValue = lookup.getTypeDef(value); - if (value.toNumber() === 416) { - console.log(JSON.stringify(defValue)); - } - setImports(allDefs, imports, [ ...similarTypes.reduce((all, t) => all.concat(t), []), storageEntry.modifier.isOptional diff --git a/packages/types/src/augment/lookup/kusama.ts b/packages/types/src/augment/lookup/kusama.ts index c39168ee4d..1d90c2e351 100644 --- a/packages/types/src/augment/lookup/kusama.ts +++ b/packages/types/src/augment/lookup/kusama.ts @@ -138,12 +138,9 @@ export default { xcm: 'XcmV2Xcm', }, Transact: { - _alias: { - call_: 'call', - }, originType: 'XcmV0OriginKind', requireWeightAtMost: 'Compact', - call_: 'XcmDoubleEncoded', + call: 'XcmDoubleEncoded', }, HrmpNewChannelOpenRequest: { sender: 'Compact', @@ -501,12 +498,9 @@ export default { effects: 'Vec', }, Transact: { - _alias: { - call_: 'call', - }, originType: 'XcmV0OriginKind', requireWeightAtMost: 'u64', - call_: 'XcmDoubleEncoded', + call: 'XcmDoubleEncoded', }, HrmpNewChannelOpenRequest: { sender: 'Compact', @@ -609,12 +603,9 @@ export default { effects: 'Vec', }, Transact: { - _alias: { - call_: 'call', - }, originType: 'XcmV0OriginKind', requireWeightAtMost: 'u64', - call_: 'XcmDoubleEncoded', + call: 'XcmDoubleEncoded', }, HrmpNewChannelOpenRequest: { sender: 'Compact', diff --git a/packages/types/src/augment/lookup/substrate.ts b/packages/types/src/augment/lookup/substrate.ts index bb2e6d364a..288d8566bd 100644 --- a/packages/types/src/augment/lookup/substrate.ts +++ b/packages/types/src/augment/lookup/substrate.ts @@ -965,8 +965,7 @@ export default { **/ PalletContractsScheduleInstructionWeights: { _alias: { - r_if: 'r#if', - call_: 'call' + r_if: 'r#if' }, version: 'u32', i64Const: 'u32', @@ -978,7 +977,7 @@ export default { brIf: 'u32', brTable: 'u32', brTablePerEntry: 'u32', - call_: 'u32', + call: 'u32', callIndirect: 'u32', callIndirectPerParam: 'u32', localGet: 'u32', @@ -1026,8 +1025,7 @@ export default { **/ PalletContractsScheduleHostFnWeights: { _alias: { - r_return: 'r#return', - call_: 'call' + r_return: 'r#return' }, caller: 'u64', address: 'u64', @@ -1056,7 +1054,7 @@ export default { getStorage: 'u64', getStoragePerByte: 'u64', transfer: 'u64', - call_: 'u64', + call: 'u64', callTransferSurcharge: 'u64', callPerInputByte: 'u64', callPerOutputByte: 'u64', @@ -1160,12 +1158,9 @@ export default { * Lookup454: pallet_scheduler::ScheduledV2 **/ PalletSchedulerScheduledV2: { - _alias: { - call_: 'call' - }, maybeId: 'Option', priority: 'u8', - call_: 'Call', + call: 'Call', maybePeriodic: 'Option<(u32,u32)>', origin: 'NodeRuntimeOriginCaller' }, diff --git a/packages/types/src/augment/lookup/types-kusama.ts b/packages/types/src/augment/lookup/types-kusama.ts index 3a153dcfda..b3074dae66 100644 --- a/packages/types/src/augment/lookup/types-kusama.ts +++ b/packages/types/src/augment/lookup/types-kusama.ts @@ -156,7 +156,7 @@ declare module '@polkadot/types/lookup' { readonly asTransact: { readonly originType: XcmV0OriginKind; readonly requireWeightAtMost: Compact; - readonly call_: XcmDoubleEncoded; + readonly call: XcmDoubleEncoded; } & Struct; readonly isHrmpNewChannelOpenRequest: boolean; readonly asHrmpNewChannelOpenRequest: { @@ -539,7 +539,7 @@ declare module '@polkadot/types/lookup' { readonly asTransact: { readonly originType: XcmV0OriginKind; readonly requireWeightAtMost: u64; - readonly call_: XcmDoubleEncoded; + readonly call: XcmDoubleEncoded; } & Struct; readonly isHrmpNewChannelOpenRequest: boolean; readonly asHrmpNewChannelOpenRequest: { @@ -654,7 +654,7 @@ declare module '@polkadot/types/lookup' { readonly asTransact: { readonly originType: XcmV0OriginKind; readonly requireWeightAtMost: u64; - readonly call_: XcmDoubleEncoded; + readonly call: XcmDoubleEncoded; } & Struct; readonly isHrmpNewChannelOpenRequest: boolean; readonly asHrmpNewChannelOpenRequest: { diff --git a/packages/types/src/augment/lookup/types-substrate.ts b/packages/types/src/augment/lookup/types-substrate.ts index 5127ecf34e..154f790a50 100644 --- a/packages/types/src/augment/lookup/types-substrate.ts +++ b/packages/types/src/augment/lookup/types-substrate.ts @@ -1029,7 +1029,7 @@ declare module '@polkadot/types/lookup' { readonly brIf: u32; readonly brTable: u32; readonly brTablePerEntry: u32; - readonly call_: u32; + readonly call: u32; readonly callIndirect: u32; readonly callIndirectPerParam: u32; readonly localGet: u32; @@ -1102,7 +1102,7 @@ declare module '@polkadot/types/lookup' { readonly getStorage: u64; readonly getStoragePerByte: u64; readonly transfer: u64; - readonly call_: u64; + readonly call: u64; readonly callTransferSurcharge: u64; readonly callPerInputByte: u64; readonly callPerOutputByte: u64; @@ -1200,7 +1200,7 @@ declare module '@polkadot/types/lookup' { export interface PalletSchedulerScheduledV2 extends Struct { readonly maybeId: Option; readonly priority: u8; - readonly call_: Call; + readonly call: Call; readonly maybePeriodic: Option>; readonly origin: NodeRuntimeOriginCaller; } diff --git a/packages/types/src/generic/PortableRegistry/PortableRegistry.ts b/packages/types/src/generic/PortableRegistry/PortableRegistry.ts index d7c1fc05ef..88baf23251 100644 --- a/packages/types/src/generic/PortableRegistry/PortableRegistry.ts +++ b/packages/types/src/generic/PortableRegistry/PortableRegistry.ts @@ -50,8 +50,8 @@ const SETS = [ // These we never use these as top-level names, they are wrappers const WRAPPERS = ['BoundedBTreeMap', 'BoundedVec', 'Box', 'BTreeMap', 'Cow', 'Result', 'Option', 'WeakBoundedVec', 'WrapperOpaque']; -// These are reserved and/or conflicts with built-in Codec definitions -const RESERVED = ['call', 'entries', 'hash', 'keys', 'new', 'size']; +// These are reserved and/or conflicts with built-in Codec or JS definitions +const RESERVED = ['entries', 'hash', 'keys', 'new', 'size']; function matchParts (first: string[], second: (string | Text)[]): boolean { return first.length === second.length && first.every((a, index) => { diff --git a/packages/types/src/interfaces/elections/definitions.ts b/packages/types/src/interfaces/elections/definitions.ts index c1a511e620..024ba69a63 100644 --- a/packages/types/src/interfaces/elections/definitions.ts +++ b/packages/types/src/interfaces/elections/definitions.ts @@ -33,9 +33,9 @@ export default { }, VoteThreshold: { _enum: [ - 'Super majority approval', - 'Super majority rejection', - 'Simple majority' + 'Super Majority Approve', + 'Super Majority Against', + 'Simple Majority' ] } } diff --git a/packages/types/src/interfaces/elections/types.ts b/packages/types/src/interfaces/elections/types.ts index 157aac5692..4761400801 100644 --- a/packages/types/src/interfaces/elections/types.ts +++ b/packages/types/src/interfaces/elections/types.ts @@ -41,9 +41,9 @@ export interface VoterInfo extends Struct { /** @name VoteThreshold */ export interface VoteThreshold extends Enum { - readonly isSupermajorityapproval: boolean; - readonly isSupermajorityrejection: boolean; - readonly isSimplemajority: boolean; + readonly isSuperMajorityApprove: boolean; + readonly isSuperMajorityAgainst: boolean; + readonly isSimpleMajority: boolean; } export type PHANTOM_ELECTIONS = 'elections';