From cce0c891681cdcf8a9da6e77c04bc2e6fb78f7ac Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 1 Jul 2021 11:17:48 +0300 Subject: [PATCH] Adjust collective with instances (#3712) * Adjust collective with instances * Update CHANGELOG * Add prime & proposalaHashes to all * Export members collective * prime * Optional constants * Move constant expansion * proposalCount derive * candidateCount is non-optional --- CHANGELOG.md | 11 ++++ .../api-derive/src/collective/getInstance.ts | 12 ++++ packages/api-derive/src/collective/index.ts | 2 + packages/api-derive/src/collective/members.ts | 23 ++++++++ packages/api-derive/src/collective/prime.ts | 28 ++++++++++ .../api-derive/src/collective/proposals.ts | 55 ++++++++++++++----- packages/api-derive/src/collective/types.ts | 4 ++ packages/api-derive/src/council/index.ts | 2 + packages/api-derive/src/council/members.ts | 13 +++++ packages/api-derive/src/council/prime.ts | 13 +++++ packages/api-derive/src/council/proposals.ts | 15 ++++- packages/api-derive/src/council/votes.ts | 33 ++++++----- packages/api-derive/src/elections/info.ts | 43 ++++++++++----- packages/api-derive/src/elections/types.ts | 6 +- packages/api-derive/src/index.ts | 43 ++++++++++----- packages/api-derive/src/membership/index.ts | 2 + packages/api-derive/src/membership/members.ts | 13 +++++ packages/api-derive/src/membership/prime.ts | 13 +++++ .../api-derive/src/membership/proposals.ts | 20 ++++++- .../src/technicalCommittee/index.ts | 2 + .../src/technicalCommittee/members.ts | 13 +++++ .../src/technicalCommittee/prime.ts | 13 +++++ .../src/technicalCommittee/proposals.ts | 20 ++++++- 23 files changed, 338 insertions(+), 61 deletions(-) create mode 100644 packages/api-derive/src/collective/getInstance.ts create mode 100644 packages/api-derive/src/collective/members.ts create mode 100644 packages/api-derive/src/collective/prime.ts create mode 100644 packages/api-derive/src/collective/types.ts create mode 100644 packages/api-derive/src/council/members.ts create mode 100644 packages/api-derive/src/council/prime.ts create mode 100644 packages/api-derive/src/membership/members.ts create mode 100644 packages/api-derive/src/membership/prime.ts create mode 100644 packages/api-derive/src/technicalCommittee/members.ts create mode 100644 packages/api-derive/src/technicalCommittee/prime.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 709ccf05e1..d770695703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG +## master + +Contributed: + +- Added `Emergency` to `ElectionPhase` (Thanks to https://github.com/arjanz) + +Changes: + +- Allow `instances` API config to drive collective locations + + ## 4.16.2 Jun 27, 2021 Upgrade priority: Low. Recommended for Polkadot with runtime >= 9050. diff --git a/packages/api-derive/src/collective/getInstance.ts b/packages/api-derive/src/collective/getInstance.ts new file mode 100644 index 0000000000..99049b0822 --- /dev/null +++ b/packages/api-derive/src/collective/getInstance.ts @@ -0,0 +1,12 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; + +export function getInstance (api: ApiInterfaceRx, section: string): string { + const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section); + + return instances && instances.length + ? instances[0] + : section; +} diff --git a/packages/api-derive/src/collective/index.ts b/packages/api-derive/src/collective/index.ts index c927b748a9..2b261cc2ae 100644 --- a/packages/api-derive/src/collective/index.ts +++ b/packages/api-derive/src/collective/index.ts @@ -1,4 +1,6 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 +export * from './members'; +export * from './prime'; export * from './proposals'; diff --git a/packages/api-derive/src/collective/members.ts b/packages/api-derive/src/collective/members.ts new file mode 100644 index 0000000000..616065abaf --- /dev/null +++ b/packages/api-derive/src/collective/members.ts @@ -0,0 +1,23 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; +import type { Collective } from './types'; + +import { isFunction } from '@polkadot/util'; +import { of } from '@polkadot/x-rxjs'; + +import { memo } from '../util'; +import { getInstance } from './getInstance'; + +export function members (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable { + const section = getInstance(api, _section); + + return memo(instanceId, (): Observable => + isFunction(api.query[section]?.members) + ? api.query[section as 'council'].members() + : of([]) + ); +} diff --git a/packages/api-derive/src/collective/prime.ts b/packages/api-derive/src/collective/prime.ts new file mode 100644 index 0000000000..1ff38089b9 --- /dev/null +++ b/packages/api-derive/src/collective/prime.ts @@ -0,0 +1,28 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { Option } from '@polkadot/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { isFunction } from '@polkadot/util'; +import { of } from '@polkadot/x-rxjs'; +import { map } from '@polkadot/x-rxjs/operators'; + +import { memo } from '../util'; +import { getInstance } from './getInstance'; + +export function prime (instanceId: string, api: ApiInterfaceRx, _section: string): () => Observable { + const section = getInstance(api, _section); + + return memo(instanceId, (): Observable => + isFunction(api.query[section as 'council']?.prime) + ? api.query[section as 'council'].prime>().pipe( + map((optPrime): AccountId | null => + optPrime.unwrapOr(null) + ) + ) + : of(null) + ); +} diff --git a/packages/api-derive/src/collective/proposals.ts b/packages/api-derive/src/collective/proposals.ts index b0e826e1ac..e3724dd3ad 100644 --- a/packages/api-derive/src/collective/proposals.ts +++ b/packages/api-derive/src/collective/proposals.ts @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; -import type { Option } from '@polkadot/types'; +import type { Option, u32 } from '@polkadot/types'; import type { Hash, Proposal, Votes } from '@polkadot/types/interfaces'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveCollectiveProposal } from '../types'; +import type { Collective } from './types'; import { isFunction } from '@polkadot/util'; import { combineLatest, of } from '@polkadot/x-rxjs'; import { catchError, map, switchMap } from '@polkadot/x-rxjs/operators'; import { memo } from '../util'; - -type Collective = 'council' | 'membership' | 'technicalCommittee'; +import { getInstance } from './getInstance'; type Result = [(Hash | Uint8Array | string)[], (Option | null)[], Option[]]; @@ -31,7 +31,7 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive .filter((proposal): proposal is DeriveCollectiveProposal => !!proposal); } -function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: Collective): (hashes: (Hash | Uint8Array | string)[]) => Observable { +function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: string): (hashes: (Hash | Uint8Array | string)[]) => Observable { return memo(instanceId, (hashes: (Hash | Uint8Array | string)[]): Observable => (isFunction(api.query[section]?.proposals) && hashes.length ? combineLatest([ @@ -51,19 +51,48 @@ function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: Colle ); } -export function proposals (instanceId: string, api: ApiInterfaceRx, section: Collective): () => Observable { - const proposalsFrom = _proposalsFrom(instanceId, api, section); +export function hasProposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable { + const section = getInstance(api, _section); - return memo(instanceId, (): Observable => - isFunction(api.query[section]?.proposals) - ? api.query[section as 'council'].proposals().pipe( - switchMap(proposalsFrom) - ) - : of([] as DeriveCollectiveProposal[]) + return memo(instanceId, (): Observable => + of(isFunction(api.query[section]?.proposals)) ); } -export function proposal (instanceId: string, api: ApiInterfaceRx, section: Collective): (hash: Hash | Uint8Array | string) => Observable { +export function proposalCount (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable { + const section = getInstance(api, _section); + + return memo(instanceId, (): Observable => + isFunction(api.query[section].proposalCount) + ? api.query[section as 'council'].proposalCount() + : of(null) + ); +} + +export function proposalHashes (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable { + const section = getInstance(api, _section); + + return memo(instanceId, (): Observable => + isFunction(api.query[section]?.proposals) + ? api.query[section as 'council'].proposals() + : of([]) + ); +} + +export function proposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable { + const section = getInstance(api, _section); + const proposalsFrom = _proposalsFrom(instanceId, api, section); + const getHashes = proposalHashes(instanceId, api, _section); + + return memo(instanceId, (): Observable => + getHashes().pipe( + switchMap(proposalsFrom) + ) + ); +} + +export function proposal (instanceId: string, api: ApiInterfaceRx, _section: Collective): (hash: Hash | Uint8Array | string) => Observable { + const section = getInstance(api, _section); const proposalsFrom = _proposalsFrom(instanceId, api, section); return memo(instanceId, (hash: Hash | Uint8Array | string): Observable => diff --git a/packages/api-derive/src/collective/types.ts b/packages/api-derive/src/collective/types.ts new file mode 100644 index 0000000000..7c9facb447 --- /dev/null +++ b/packages/api-derive/src/collective/types.ts @@ -0,0 +1,4 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export type Collective = 'council' | 'membership' | 'technicalCommittee'; diff --git a/packages/api-derive/src/council/index.ts b/packages/api-derive/src/council/index.ts index ec862c60fc..faca9bace8 100644 --- a/packages/api-derive/src/council/index.ts +++ b/packages/api-derive/src/council/index.ts @@ -1,6 +1,8 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 +export * from './members'; +export * from './prime'; export * from './proposals'; export * from './votes'; export * from './votesOf'; diff --git a/packages/api-derive/src/council/members.ts b/packages/api-derive/src/council/members.ts new file mode 100644 index 0000000000..2a8e7d7856 --- /dev/null +++ b/packages/api-derive/src/council/members.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { members as collectiveMembers } from '../collective'; +import { memo } from '../util'; + +export function members (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveMembers(instanceId, api, 'council')); +} diff --git a/packages/api-derive/src/council/prime.ts b/packages/api-derive/src/council/prime.ts new file mode 100644 index 0000000000..b13348bfe1 --- /dev/null +++ b/packages/api-derive/src/council/prime.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { prime as collectivePrime } from '../collective'; +import { memo } from '../util'; + +export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectivePrime(instanceId, api, 'council')); +} diff --git a/packages/api-derive/src/council/proposals.ts b/packages/api-derive/src/council/proposals.ts index d6c5faf5c2..9c46ae42fa 100644 --- a/packages/api-derive/src/council/proposals.ts +++ b/packages/api-derive/src/council/proposals.ts @@ -2,17 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { u32 } from '@polkadot/types'; import type { Hash } from '@polkadot/types/interfaces'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveCollectiveProposal } from '../types'; -import { proposal as collectiveProposal, proposals as collectiveProposals } from '../collective'; +import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective'; import { memo } from '../util'; +export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveHasProposals(instanceId, api, 'council')); +} + export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable { return memo(instanceId, collectiveProposal(instanceId, api, 'council')); } +export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalCount(instanceId, api, 'council')); +} + +export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalHashes(instanceId, api, 'council')); +} + export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable { return memo(instanceId, collectiveProposals(instanceId, api, 'council')); } diff --git a/packages/api-derive/src/council/votes.ts b/packages/api-derive/src/council/votes.ts index 0c9bb9d273..930e89d610 100644 --- a/packages/api-derive/src/council/votes.ts +++ b/packages/api-derive/src/council/votes.ts @@ -1,14 +1,14 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { ApiInterfaceRx, QueryableModuleStorage } from '@polkadot/api/types'; import type { Vec } from '@polkadot/types'; import type { AccountId, Balance, Voter } from '@polkadot/types/interfaces'; import type { ITuple } from '@polkadot/types/types'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveCouncilVote, DeriveCouncilVotes } from '../types'; -import { combineLatest } from '@polkadot/x-rxjs'; +import { combineLatest, of } from '@polkadot/x-rxjs'; import { map } from '@polkadot/x-rxjs/operators'; import { memo } from '../util'; @@ -20,24 +20,27 @@ function isVoter (value: VoteEntry): value is Voter { return !Array.isArray(value); } -function retrieveStakeOf (api: ApiInterfaceRx): Observable<[AccountId, Balance][]> { - return (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).stakeOf.entries().pipe( +function retrieveStakeOf (elections: QueryableModuleStorage<'rxjs'>): Observable<[AccountId, Balance][]> { + return elections.stakeOf.entries().pipe( map((entries) => entries.map(([{ args: [accountId] }, stake]) => [accountId, stake]) ) ); } -function retrieveVoteOf (api: ApiInterfaceRx): Observable<[AccountId, AccountId[]][]> { - return (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).votesOf.entries, [AccountId]>().pipe( +function retrieveVoteOf (elections: QueryableModuleStorage<'rxjs'>): Observable<[AccountId, AccountId[]][]> { + return elections.votesOf.entries, [AccountId]>().pipe( map((entries) => entries.map(([{ args: [accountId] }, votes]) => [accountId, votes]) ) ); } -function retrievePrev (api: ApiInterfaceRx): Observable { - return combineLatest([retrieveStakeOf(api), retrieveVoteOf(api)]).pipe( +function retrievePrev (api: ApiInterfaceRx, elections: QueryableModuleStorage<'rxjs'>): Observable { + return combineLatest([ + retrieveStakeOf(elections), + retrieveVoteOf(elections) + ]).pipe( map(([stakes, votes]): DeriveCouncilVotes => { const result: DeriveCouncilVotes = []; @@ -60,9 +63,7 @@ function retrievePrev (api: ApiInterfaceRx): Observable { ); } -function retrieveCurrent (api: ApiInterfaceRx): Observable { - const elections = (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections); - +function retrieveCurrent (elections: QueryableModuleStorage<'rxjs'>): Observable { return elections.voting.entries().pipe( map((entries): DeriveCouncilVotes => entries.map(([{ args: [accountId] }, value]): [AccountId, DeriveCouncilVote] => [ @@ -76,9 +77,13 @@ function retrieveCurrent (api: ApiInterfaceRx): Observable { } export function votes (instanceId: string, api: ApiInterfaceRx): () => Observable { + const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections; + return memo(instanceId, (): Observable => - (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).stakeOf - ? retrievePrev(api) - : retrieveCurrent(api) + elections + ? elections.stakeOf + ? retrievePrev(api, elections) + : retrieveCurrent(elections) + : of([]) ); } diff --git a/packages/api-derive/src/elections/info.ts b/packages/api-derive/src/elections/info.ts index b79c1b4bca..1b22cf4710 100644 --- a/packages/api-derive/src/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -8,6 +8,7 @@ import type { ITuple } from '@polkadot/types/types'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveElectionsInfo } from './types'; +import { combineLatest, of } from '@polkadot/x-rxjs'; import { map } from '@polkadot/x-rxjs/operators'; import { memo } from '../util'; @@ -42,30 +43,46 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun } function queryElections (api: ApiInterfaceRx): Observable { - const section = api.query.phragmenElection + const elections = api.query.phragmenElection ? 'phragmenElection' : api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections'; + const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council']; - return api.queryMulti<[Vec, Vec, Vec, Vec]>([ - api.query.council.members, - api.query[section].candidates, - api.query[section].members, - api.query[section].runnersUp - ]).pipe( + return ( + api.query[elections] + ? api.queryMulti<[Vec, Vec, Vec, Vec]>([ + api.query[council].members, + api.query[elections].candidates, + api.query[elections].members, + api.query[elections].runnersUp + ]) + : combineLatest<[Vec, Candidate[], Member[], Member[]]>([ + api.query[council].members, + of([]), + of([]), + of([]) + ]) + ).pipe( map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({ - candidacyBond: api.consts[section].candidacyBond as Balance, + ...( + api.consts[elections] + ? { + candidacyBond: api.consts[elections].candidacyBond as Balance, + desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32, + desiredSeats: api.consts[elections].desiredMembers as u32, + termDuration: api.consts[elections].termDuration as BlockNumber, + votingBond: api.consts[elections].votingBond as Balance + } + : {} + ), candidateCount: api.registry.createType('u32', candidates.length), candidates: candidates.map(getCandidate), - desiredRunnersUp: api.consts[section].desiredRunnersUp as u32, - desiredSeats: api.consts[section].desiredMembers as u32, members: members.length ? members.map(getAccountTuple).sort(sortAccounts) : councilMembers.map((accountId): [AccountId, Balance] => [accountId, api.registry.createType('Balance')]), - runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts), - termDuration: api.consts[section].termDuration as BlockNumber, - votingBond: api.consts[section].votingBond as Balance + runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts) })) ); } diff --git a/packages/api-derive/src/elections/types.ts b/packages/api-derive/src/elections/types.ts index 7617c3f8c2..2260ecf6cf 100644 --- a/packages/api-derive/src/elections/types.ts +++ b/packages/api-derive/src/elections/types.ts @@ -8,12 +8,12 @@ export interface DeriveElectionsInfo { candidates: AccountId[]; candidateCount: u32; candidacyBond?: Balance; - desiredRunnersUp: u32; - desiredSeats: u32; + desiredRunnersUp?: u32; + desiredSeats?: u32; members: [AccountId, Balance][]; nextVoterSet?: SetIndex; runnersUp: [AccountId, Balance][]; - termDuration: BlockNumber; + termDuration?: BlockNumber; voteCount?: VoteIndex; voterCount?: SetIndex; votingBond?: Balance; diff --git a/packages/api-derive/src/index.ts b/packages/api-derive/src/index.ts index a3622904d3..cd491ffbbd 100644 --- a/packages/api-derive/src/index.ts +++ b/packages/api-derive/src/index.ts @@ -28,6 +28,11 @@ import * as tx from './tx'; export { packageInfo } from './packageInfo'; export * from './type'; +interface Avail { + instances: string[]; + withDetect?: boolean; +} + export const derive = { accounts, balances, bounties, chain, contracts, council, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx }; type DeriveSection
= { @@ -44,19 +49,19 @@ export type DeriveCustom = Record; // Enable derive only if some of these modules are available -const deriveAvail: Record = { - contracts: ['contracts'], - council: ['council'], - democracy: ['democracy'], - elections: ['phragmenElection', 'electionsPhragmen', 'elections'], - imOnline: ['imOnline'], - membership: ['membership'], - parachains: ['parachains', 'registrar'], - session: ['session'], - society: ['society'], - staking: ['staking'], - technicalCommittee: ['technicalCommittee'], - treasury: ['treasury'] +const deriveAvail: Record = { + contracts: { instances: ['contracts'] }, + council: { instances: ['council'], withDetect: true }, + democracy: { instances: ['democracy'] }, + elections: { instances: ['phragmenElection', 'electionsPhragmen', 'elections'] }, + imOnline: { instances: ['imOnline'] }, + membership: { instances: ['membership'] }, + parachains: { instances: ['parachains', 'registrar'] }, + session: { instances: ['session'] }, + society: { instances: ['society'] }, + staking: { instances: ['staking'] }, + technicalCommittee: { instances: ['technicalCommittee'], withDetect: true }, + treasury: { instances: ['treasury'] } }; /** @@ -66,11 +71,19 @@ const deriveAvail: Record = { /** @internal */ function injectFunctions (instanceId: string, api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections { const queryKeys = Object.keys(api.query); + const specName = api.runtimeVersion.specName.toString(); return Object .keys(allSections) - .filter((sectionName): boolean => - !deriveAvail[sectionName] || deriveAvail[sectionName].some((query): boolean => queryKeys.includes(query)) + .filter((sectionName) => + !deriveAvail[sectionName] || + deriveAvail[sectionName].instances.some((q) => queryKeys.includes(q)) || + ( + deriveAvail[sectionName].withDetect && + deriveAvail[sectionName].instances.some((q) => + (api.registry.getModuleInstances(specName, q) || []).some((q) => queryKeys.includes(q)) + ) + ) ) .reduce((deriveAcc, sectionName): DeriveAllSections => { const section = allSections[sectionName as keyof AllSections]; diff --git a/packages/api-derive/src/membership/index.ts b/packages/api-derive/src/membership/index.ts index c927b748a9..2b261cc2ae 100644 --- a/packages/api-derive/src/membership/index.ts +++ b/packages/api-derive/src/membership/index.ts @@ -1,4 +1,6 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 +export * from './members'; +export * from './prime'; export * from './proposals'; diff --git a/packages/api-derive/src/membership/members.ts b/packages/api-derive/src/membership/members.ts new file mode 100644 index 0000000000..381f2371b0 --- /dev/null +++ b/packages/api-derive/src/membership/members.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { members as collectiveMembers } from '../collective'; +import { memo } from '../util'; + +export function members (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveMembers(instanceId, api, 'membership')); +} diff --git a/packages/api-derive/src/membership/prime.ts b/packages/api-derive/src/membership/prime.ts new file mode 100644 index 0000000000..35ddf58050 --- /dev/null +++ b/packages/api-derive/src/membership/prime.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { prime as collectivePrime } from '../collective'; +import { memo } from '../util'; + +export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectivePrime(instanceId, api, 'membership')); +} diff --git a/packages/api-derive/src/membership/proposals.ts b/packages/api-derive/src/membership/proposals.ts index e362b0f9aa..29c967e0b0 100644 --- a/packages/api-derive/src/membership/proposals.ts +++ b/packages/api-derive/src/membership/proposals.ts @@ -2,12 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { u32 } from '@polkadot/types'; +import type { Hash } from '@polkadot/types/interfaces'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveCollectiveProposal } from '../types'; -import { proposals as collectiveProposals } from '../collective'; +import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective'; import { memo } from '../util'; +export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveHasProposals(instanceId, api, 'membership')); +} + +export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable { + return memo(instanceId, collectiveProposal(instanceId, api, 'membership')); +} + +export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalCount(instanceId, api, 'membership')); +} + +export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalHashes(instanceId, api, 'membership')); +} + export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable { return memo(instanceId, collectiveProposals(instanceId, api, 'membership')); } diff --git a/packages/api-derive/src/technicalCommittee/index.ts b/packages/api-derive/src/technicalCommittee/index.ts index c927b748a9..2b261cc2ae 100644 --- a/packages/api-derive/src/technicalCommittee/index.ts +++ b/packages/api-derive/src/technicalCommittee/index.ts @@ -1,4 +1,6 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 +export * from './members'; +export * from './prime'; export * from './proposals'; diff --git a/packages/api-derive/src/technicalCommittee/members.ts b/packages/api-derive/src/technicalCommittee/members.ts new file mode 100644 index 0000000000..0309a02feb --- /dev/null +++ b/packages/api-derive/src/technicalCommittee/members.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { members as collectiveMembers } from '../collective'; +import { memo } from '../util'; + +export function members (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveMembers(instanceId, api, 'technicalCommittee')); +} diff --git a/packages/api-derive/src/technicalCommittee/prime.ts b/packages/api-derive/src/technicalCommittee/prime.ts new file mode 100644 index 0000000000..2e3cdaa4c6 --- /dev/null +++ b/packages/api-derive/src/technicalCommittee/prime.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2021 @polkadot/api-derive authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { AccountId } from '@polkadot/types/interfaces'; +import type { Observable } from '@polkadot/x-rxjs'; + +import { prime as collectivePrime } from '../collective'; +import { memo } from '../util'; + +export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectivePrime(instanceId, api, 'technicalCommittee')); +} diff --git a/packages/api-derive/src/technicalCommittee/proposals.ts b/packages/api-derive/src/technicalCommittee/proposals.ts index dd991f7e3d..cf7f389541 100644 --- a/packages/api-derive/src/technicalCommittee/proposals.ts +++ b/packages/api-derive/src/technicalCommittee/proposals.ts @@ -2,12 +2,30 @@ // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; +import type { u32 } from '@polkadot/types'; +import type { Hash } from '@polkadot/types/interfaces'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveCollectiveProposal } from '../types'; -import { proposals as collectiveProposals } from '../collective'; +import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective'; import { memo } from '../util'; +export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveHasProposals(instanceId, api, 'technicalCommittee')); +} + +export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable { + return memo(instanceId, collectiveProposal(instanceId, api, 'technicalCommittee')); +} + +export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalCount(instanceId, api, 'technicalCommittee')); +} + +export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable { + return memo(instanceId, collectiveProposalHashes(instanceId, api, 'technicalCommittee')); +} + export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable { return memo(instanceId, collectiveProposals(instanceId, api, 'technicalCommittee')); }