@pezkuwi/api-derive 16.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/build/accounts/accountId.d.ts +17 -0
- package/build/accounts/flags.d.ts +29 -0
- package/build/accounts/idAndIndex.d.ts +15 -0
- package/build/accounts/idToIndex.d.ts +16 -0
- package/build/accounts/identity.d.ts +48 -0
- package/build/accounts/index.d.ts +8 -0
- package/build/accounts/indexToId.d.ts +15 -0
- package/build/accounts/indexes.d.ts +16 -0
- package/build/accounts/info.d.ts +18 -0
- package/build/accounts/types.d.ts +39 -0
- package/build/alliance/index.d.ts +70 -0
- package/build/augment.d.ts +1 -0
- package/build/bagsList/get.d.ts +12 -0
- package/build/bagsList/getExpanded.d.ts +16 -0
- package/build/bagsList/index.d.ts +3 -0
- package/build/bagsList/listNodes.d.ts +9 -0
- package/build/bagsList/types.d.ts +13 -0
- package/build/bagsList/util.d.ts +2 -0
- package/build/balances/account.d.ts +17 -0
- package/build/balances/all.d.ts +20 -0
- package/build/balances/index.d.ts +20 -0
- package/build/balances/types.d.ts +69 -0
- package/build/balances/votingBalances.d.ts +15 -0
- package/build/bounties/bounties.d.ts +12 -0
- package/build/bounties/helpers/filterBountyProposals.d.ts +2 -0
- package/build/bounties/index.d.ts +1 -0
- package/build/bundle.d.ts +9 -0
- package/build/chain/bestNumber.d.ts +11 -0
- package/build/chain/bestNumberFinalized.d.ts +12 -0
- package/build/chain/bestNumberLag.d.ts +15 -0
- package/build/chain/getBlock.d.ts +15 -0
- package/build/chain/getBlockByNumber.d.ts +16 -0
- package/build/chain/getHeader.d.ts +16 -0
- package/build/chain/index.d.ts +10 -0
- package/build/chain/subscribeFinalizedBlocks.d.ts +14 -0
- package/build/chain/subscribeFinalizedHeads.d.ts +22 -0
- package/build/chain/subscribeNewBlocks.d.ts +14 -0
- package/build/chain/subscribeNewHeads.d.ts +15 -0
- package/build/chain/util.d.ts +9 -0
- package/build/collective/helpers.d.ts +6 -0
- package/build/collective/index.d.ts +3 -0
- package/build/collective/members.d.ts +2 -0
- package/build/collective/prime.d.ts +2 -0
- package/build/collective/proposals.d.ts +6 -0
- package/build/collective/types.d.ts +19 -0
- package/build/contracts/fees.d.ts +14 -0
- package/build/contracts/index.d.ts +1 -0
- package/build/council/index.d.ts +72 -0
- package/build/council/types.d.ts +6 -0
- package/build/council/votes.d.ts +11 -0
- package/build/council/votesOf.d.ts +16 -0
- package/build/crowdloan/childKey.d.ts +15 -0
- package/build/crowdloan/contributions.d.ts +14 -0
- package/build/crowdloan/index.d.ts +3 -0
- package/build/crowdloan/ownContributions.d.ts +15 -0
- package/build/crowdloan/types.d.ts +6 -0
- package/build/crowdloan/util.d.ts +10 -0
- package/build/democracy/dispatchQueue.d.ts +12 -0
- package/build/democracy/index.d.ts +11 -0
- package/build/democracy/locks.d.ts +14 -0
- package/build/democracy/nextExternal.d.ts +12 -0
- package/build/democracy/preimages.d.ts +24 -0
- package/build/democracy/proposals.d.ts +12 -0
- package/build/democracy/referendumIds.d.ts +12 -0
- package/build/democracy/referendums.d.ts +11 -0
- package/build/democracy/referendumsActive.d.ts +12 -0
- package/build/democracy/referendumsFinished.d.ts +15 -0
- package/build/democracy/referendumsInfo.d.ts +23 -0
- package/build/democracy/sqrtElectorate.d.ts +13 -0
- package/build/democracy/types.d.ts +70 -0
- package/build/democracy/util.d.ts +18 -0
- package/build/derive.d.ts +52 -0
- package/build/elections/index.d.ts +1 -0
- package/build/elections/info.d.ts +14 -0
- package/build/elections/types.d.ts +18 -0
- package/build/imOnline/index.d.ts +1 -0
- package/build/imOnline/receivedHeartbeats.d.ts +13 -0
- package/build/index.d.ts +2 -0
- package/build/membership/index.d.ts +70 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/parachains/index.d.ts +2 -0
- package/build/parachains/info.d.ts +19 -0
- package/build/parachains/overview.d.ts +15 -0
- package/build/parachains/types.d.ts +38 -0
- package/build/parachains/util.d.ts +3 -0
- package/build/session/index.d.ts +3 -0
- package/build/session/indexes.d.ts +15 -0
- package/build/session/info.d.ts +13 -0
- package/build/session/progress.d.ts +47 -0
- package/build/session/types.d.ts +19 -0
- package/build/society/candidates.d.ts +12 -0
- package/build/society/index.d.ts +4 -0
- package/build/society/info.d.ts +12 -0
- package/build/society/member.d.ts +14 -0
- package/build/society/members.d.ts +14 -0
- package/build/society/types.d.ts +27 -0
- package/build/staking/account.d.ts +31 -0
- package/build/staking/cache.d.ts +12 -0
- package/build/staking/currentPoints.d.ts +13 -0
- package/build/staking/electedInfo.d.ts +23 -0
- package/build/staking/erasExposure.d.ts +30 -0
- package/build/staking/erasHistoric.d.ts +8 -0
- package/build/staking/erasPoints.d.ts +18 -0
- package/build/staking/erasPrefs.d.ts +27 -0
- package/build/staking/erasRewards.d.ts +14 -0
- package/build/staking/erasSlashes.d.ts +26 -0
- package/build/staking/index.d.ts +22 -0
- package/build/staking/keys.d.ts +35 -0
- package/build/staking/overview.d.ts +19 -0
- package/build/staking/ownExposure.d.ts +37 -0
- package/build/staking/ownSlashes.d.ts +35 -0
- package/build/staking/query.d.ts +31 -0
- package/build/staking/stakerExposure.d.ts +33 -0
- package/build/staking/stakerPoints.d.ts +22 -0
- package/build/staking/stakerPrefs.d.ts +24 -0
- package/build/staking/stakerRewards.d.ts +49 -0
- package/build/staking/stakerSlashes.d.ts +22 -0
- package/build/staking/stashes.d.ts +16 -0
- package/build/staking/types.d.ts +139 -0
- package/build/staking/util.d.ts +14 -0
- package/build/staking/validators.d.ts +33 -0
- package/build/staking/waitingInfo.d.ts +16 -0
- package/build/technicalCommittee/index.d.ts +70 -0
- package/build/treasury/index.d.ts +1 -0
- package/build/treasury/proposals.d.ts +12 -0
- package/build/tx/constants.d.ts +5 -0
- package/build/tx/events.d.ts +22 -0
- package/build/tx/extrinsicInfo.d.ts +61 -0
- package/build/tx/index.d.ts +3 -0
- package/build/tx/signingInfo.d.ts +25 -0
- package/build/type/HeaderExtended.d.ts +4 -0
- package/build/type/SignedBlockExtended.d.ts +4 -0
- package/build/type/index.d.ts +2 -0
- package/build/type/types.d.ts +15 -0
- package/build/type/util.d.ts +2 -0
- package/build/types.d.ts +79 -0
- package/build/util/approvalFlagsToBools.d.ts +4 -0
- package/build/util/blockNumber.d.ts +7 -0
- package/build/util/cache.d.ts +4 -0
- package/build/util/cacheImpl.d.ts +3 -0
- package/build/util/first.d.ts +4 -0
- package/build/util/index.d.ts +7 -0
- package/build/util/lazy.d.ts +4 -0
- package/build/util/types.d.ts +6 -0
- package/package.json +42 -0
- package/src/accounts/accountId.ts +44 -0
- package/src/accounts/flags.ts +90 -0
- package/src/accounts/idAndIndex.ts +51 -0
- package/src/accounts/idToIndex.ts +31 -0
- package/src/accounts/identity.ts +235 -0
- package/src/accounts/index.ts +11 -0
- package/src/accounts/indexToId.ts +33 -0
- package/src/accounts/indexes.ts +56 -0
- package/src/accounts/info.ts +58 -0
- package/src/accounts/types.ts +48 -0
- package/src/alliance/index.ts +76 -0
- package/src/augment.ts +4 -0
- package/src/bagsList/get.ts +79 -0
- package/src/bagsList/getExpanded.ts +41 -0
- package/src/bagsList/index.ts +6 -0
- package/src/bagsList/listNodes.ts +50 -0
- package/src/bagsList/types.ts +18 -0
- package/src/bagsList/util.ts +14 -0
- package/src/balances/account.ts +210 -0
- package/src/balances/all.ts +246 -0
- package/src/balances/index.ts +26 -0
- package/src/balances/types.ts +79 -0
- package/src/balances/votingBalances.ts +33 -0
- package/src/bounties/bounties.spec.ts +162 -0
- package/src/bounties/bounties.ts +76 -0
- package/src/bounties/helpers/filterBountyProposals.ts +13 -0
- package/src/bounties/index.ts +4 -0
- package/src/bundle.ts +140 -0
- package/src/chain/bestNumber.ts +21 -0
- package/src/chain/bestNumberFinalized.ts +22 -0
- package/src/chain/bestNumberLag.ts +33 -0
- package/src/chain/getBlock.ts +43 -0
- package/src/chain/getBlockByNumber.ts +30 -0
- package/src/chain/getHeader.ts +37 -0
- package/src/chain/index.ts +13 -0
- package/src/chain/subscribeFinalizedBlocks.ts +30 -0
- package/src/chain/subscribeFinalizedHeads.ts +62 -0
- package/src/chain/subscribeNewBlocks.ts +30 -0
- package/src/chain/subscribeNewHeads.ts +38 -0
- package/src/chain/util.ts +112 -0
- package/src/checkTypes.manual.ts +8 -0
- package/src/collective/helpers.ts +36 -0
- package/src/collective/index.ts +6 -0
- package/src/collective/members.ts +8 -0
- package/src/collective/prime.ts +25 -0
- package/src/collective/proposals.ts +73 -0
- package/src/collective/types.ts +30 -0
- package/src/contracts/fees.ts +61 -0
- package/src/contracts/index.ts +4 -0
- package/src/council/index.ts +79 -0
- package/src/council/types.ts +11 -0
- package/src/council/votes.ts +97 -0
- package/src/council/votesOf.ts +35 -0
- package/src/crowdloan/childKey.ts +57 -0
- package/src/crowdloan/contributions.ts +142 -0
- package/src/crowdloan/index.ts +6 -0
- package/src/crowdloan/ownContributions.ts +81 -0
- package/src/crowdloan/types.ts +11 -0
- package/src/crowdloan/util.ts +33 -0
- package/src/democracy/dispatchQueue.ts +158 -0
- package/src/democracy/index.ts +14 -0
- package/src/democracy/locks.ts +114 -0
- package/src/democracy/nextExternal.ts +49 -0
- package/src/democracy/preimages.ts +171 -0
- package/src/democracy/proposals.ts +81 -0
- package/src/democracy/referendumIds.ts +37 -0
- package/src/democracy/referendums.ts +39 -0
- package/src/democracy/referendumsActive.ts +30 -0
- package/src/democracy/referendumsFinished.ts +37 -0
- package/src/democracy/referendumsInfo.ts +181 -0
- package/src/democracy/sqrtElectorate.ts +29 -0
- package/src/democracy/types.ts +84 -0
- package/src/democracy/util.ts +166 -0
- package/src/derive.ts +41 -0
- package/src/elections/index.ts +4 -0
- package/src/elections/info.ts +126 -0
- package/src/elections/types.ts +22 -0
- package/src/imOnline/index.ts +4 -0
- package/src/imOnline/receivedHeartbeats.ts +65 -0
- package/src/index.spec.ts +103 -0
- package/src/index.ts +6 -0
- package/src/membership/index.ts +76 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +11 -0
- package/src/packageInfo.ts +6 -0
- package/src/parachains/index.ts +5 -0
- package/src/parachains/info.ts +111 -0
- package/src/parachains/overview.ts +63 -0
- package/src/parachains/types.ts +46 -0
- package/src/parachains/util.ts +11 -0
- package/src/session/index.ts +6 -0
- package/src/session/indexes.ts +90 -0
- package/src/session/info.ts +39 -0
- package/src/session/progress.ts +130 -0
- package/src/session/types.ts +25 -0
- package/src/society/candidates.ts +71 -0
- package/src/society/index.ts +7 -0
- package/src/society/info.ts +50 -0
- package/src/society/member.ts +28 -0
- package/src/society/members.ts +107 -0
- package/src/society/types.ts +33 -0
- package/src/staking/account.ts +112 -0
- package/src/staking/cache.ts +48 -0
- package/src/staking/currentPoints.ts +28 -0
- package/src/staking/electedInfo.ts +54 -0
- package/src/staking/erasExposure.ts +105 -0
- package/src/staking/erasHistoric.ts +47 -0
- package/src/staking/erasPoints.ts +67 -0
- package/src/staking/erasPrefs.ts +63 -0
- package/src/staking/erasRewards.ts +52 -0
- package/src/staking/erasSlashes.ts +69 -0
- package/src/staking/index.ts +25 -0
- package/src/staking/keys.ts +86 -0
- package/src/staking/overview.ts +42 -0
- package/src/staking/ownExposure.ts +83 -0
- package/src/staking/ownSlashes.ts +68 -0
- package/src/staking/query.ts +230 -0
- package/src/staking/stakerExposure.ts +78 -0
- package/src/staking/stakerPoints.ts +46 -0
- package/src/staking/stakerPrefs.ts +45 -0
- package/src/staking/stakerRewards.ts +298 -0
- package/src/staking/stakerSlashes.ts +45 -0
- package/src/staking/stashes.ts +55 -0
- package/src/staking/types.ts +174 -0
- package/src/staking/util.ts +94 -0
- package/src/staking/validators.ts +82 -0
- package/src/staking/waitingInfo.ts +45 -0
- package/src/technicalCommittee/index.ts +76 -0
- package/src/test/bountyFactory.ts +39 -0
- package/src/test/bytesFactory.ts +15 -0
- package/src/test/helpers.ts +23 -0
- package/src/test/proposalFactory.ts +25 -0
- package/src/treasury/index.ts +4 -0
- package/src/treasury/proposals.ts +109 -0
- package/src/tx/constants.ts +13 -0
- package/src/tx/events.ts +43 -0
- package/src/tx/extrinsicInfo.ts +123 -0
- package/src/tx/index.ts +6 -0
- package/src/tx/signingInfo.ts +129 -0
- package/src/type/HeaderExtended.ts +33 -0
- package/src/type/SignedBlockExtended.ts +75 -0
- package/src/type/index.ts +5 -0
- package/src/type/types.ts +21 -0
- package/src/type/util.ts +45 -0
- package/src/types.ts +97 -0
- package/src/util/approvalFlagToBools.spec.ts +37 -0
- package/src/util/approvalFlagsToBools.ts +26 -0
- package/src/util/blockNumber.ts +15 -0
- package/src/util/cache.ts +65 -0
- package/src/util/cacheImpl.ts +30 -0
- package/src/util/first.ts +20 -0
- package/src/util/index.ts +13 -0
- package/src/util/lazy.ts +16 -0
- package/src/util/types.ts +9 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +27 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { QueryableModuleStorage } from '@pezkuwi/api-base/types';
|
|
6
|
+
import type { Vec } from '@pezkuwi/types';
|
|
7
|
+
import type { AccountId, Balance } from '@pezkuwi/types/interfaces';
|
|
8
|
+
import type { PalletElectionsPhragmenVoter } from '@pezkuwi/types/lookup';
|
|
9
|
+
import type { ITuple } from '@pezkuwi/types/types';
|
|
10
|
+
import type { DeriveApi, DeriveCouncilVote, DeriveCouncilVotes } from '../types.js';
|
|
11
|
+
|
|
12
|
+
import { combineLatest, map, of } from 'rxjs';
|
|
13
|
+
|
|
14
|
+
import { memo } from '../util/index.js';
|
|
15
|
+
|
|
16
|
+
// Voter is current tuple is 2.x-era
|
|
17
|
+
type VoteEntry = PalletElectionsPhragmenVoter | ITuple<[Balance, Vec<AccountId>]>;
|
|
18
|
+
|
|
19
|
+
function isVoter (value: VoteEntry): value is PalletElectionsPhragmenVoter {
|
|
20
|
+
return !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function retrieveStakeOf (elections: QueryableModuleStorage<'rxjs'>): Observable<[AccountId, Balance][]> {
|
|
24
|
+
return elections['stakeOf'].entries<Balance, [AccountId]>().pipe(
|
|
25
|
+
map((entries) =>
|
|
26
|
+
entries.map(([{ args: [accountId] }, stake]) => [accountId, stake])
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function retrieveVoteOf (elections: DeriveApi['query']['elections']): Observable<[AccountId, AccountId[]][]> {
|
|
32
|
+
return elections['votesOf'].entries<Vec<AccountId>, [AccountId]>().pipe(
|
|
33
|
+
map((entries) =>
|
|
34
|
+
entries.map(([{ args: [accountId] }, votes]) => [accountId, votes])
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function retrievePrev (api: DeriveApi, elections: DeriveApi['query']['elections']): Observable<DeriveCouncilVotes> {
|
|
40
|
+
return combineLatest([
|
|
41
|
+
retrieveStakeOf(elections),
|
|
42
|
+
retrieveVoteOf(elections)
|
|
43
|
+
]).pipe(
|
|
44
|
+
map(([stakes, votes]): DeriveCouncilVotes => {
|
|
45
|
+
const result: DeriveCouncilVotes = [];
|
|
46
|
+
|
|
47
|
+
votes.forEach(([voter, votes]): void => {
|
|
48
|
+
result.push([voter, { stake: api.registry.createType('Balance'), votes }]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
stakes.forEach(([staker, stake]): void => {
|
|
52
|
+
const entry = result.find(([voter]) => voter.eq(staker));
|
|
53
|
+
|
|
54
|
+
if (entry) {
|
|
55
|
+
entry[1].stake = stake;
|
|
56
|
+
} else {
|
|
57
|
+
result.push([staker, { stake, votes: [] }]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return result;
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function retrieveCurrent (elections: DeriveApi['query']['elections']): Observable<DeriveCouncilVotes> {
|
|
67
|
+
return elections.voting.entries<VoteEntry, [AccountId]>().pipe(
|
|
68
|
+
map((entries): DeriveCouncilVotes =>
|
|
69
|
+
entries.map(([{ args: [accountId] }, value]): [AccountId, DeriveCouncilVote] => [
|
|
70
|
+
accountId,
|
|
71
|
+
isVoter(value)
|
|
72
|
+
? { stake: value.stake, votes: value.votes }
|
|
73
|
+
: { stake: value[0], votes: value[1] }
|
|
74
|
+
])
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @name votes
|
|
81
|
+
* @description Retrieves the council election votes for all participants.
|
|
82
|
+
* @example
|
|
83
|
+
* ```javascript
|
|
84
|
+
* const votes = await api.derive.council.votes();
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export function votes (instanceId: string, api: DeriveApi): () => Observable<DeriveCouncilVotes> {
|
|
88
|
+
const elections = api.query.elections || api.query['phragmenElection'] || api.query['electionsPhragmen'];
|
|
89
|
+
|
|
90
|
+
return memo(instanceId, (): Observable<DeriveCouncilVotes> =>
|
|
91
|
+
elections
|
|
92
|
+
? elections['stakeOf']
|
|
93
|
+
? retrievePrev(api, elections)
|
|
94
|
+
: retrieveCurrent(elections)
|
|
95
|
+
: of([])
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { AccountId } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type { DeriveApi, DeriveCouncilVote } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { map } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
import { memo } from '../util/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @name votesOf
|
|
14
|
+
* @description Retrieves the council votes associated with a given account.
|
|
15
|
+
* @returns The stake and the list of candidates the account has voted for.
|
|
16
|
+
* @param {string | Uint8Array | AccountId} accountId The accountId to retrieve votes for.
|
|
17
|
+
* @example
|
|
18
|
+
* ```javascript
|
|
19
|
+
* const accountId = "5Gw3s7qQ9Z..."; // Replace with a valid account ID
|
|
20
|
+
* const votes = await api.derive.council.votesOf(accountId);
|
|
21
|
+
* console.log("Account votes:", votes);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function votesOf (instanceId: string, api: DeriveApi): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
|
25
|
+
return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
|
26
|
+
api.derive.council.votes().pipe(
|
|
27
|
+
map((votes): DeriveCouncilVote =>
|
|
28
|
+
(
|
|
29
|
+
votes.find(([from]) => from.eq(accountId)) ||
|
|
30
|
+
[null, { stake: api.registry.createType('Balance'), votes: [] as AccountId[] }]
|
|
31
|
+
)[1]
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { Option, u32 } from '@pezkuwi/types';
|
|
6
|
+
import type { PolkadotRuntimeCommonCrowdloanFundInfo } from '@pezkuwi/types/lookup';
|
|
7
|
+
import type { BN } from '@pezkuwi/util';
|
|
8
|
+
import type { DeriveApi } from '../types.js';
|
|
9
|
+
|
|
10
|
+
import { map } from 'rxjs';
|
|
11
|
+
|
|
12
|
+
import { u8aConcat, u8aToHex } from '@pezkuwi/util';
|
|
13
|
+
import { blake2AsU8a } from '@pezkuwi/util-crypto';
|
|
14
|
+
|
|
15
|
+
import { memo } from '../util/index.js';
|
|
16
|
+
|
|
17
|
+
interface AllInfo extends PolkadotRuntimeCommonCrowdloanFundInfo {
|
|
18
|
+
// previously it was named trieIndex
|
|
19
|
+
trieIndex?: u32;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function createChildKey (info: AllInfo): string {
|
|
23
|
+
return u8aToHex(
|
|
24
|
+
u8aConcat(
|
|
25
|
+
':child_storage:default:',
|
|
26
|
+
blake2AsU8a(
|
|
27
|
+
u8aConcat(
|
|
28
|
+
'crowdloan',
|
|
29
|
+
(info.fundIndex || info.trieIndex).toU8a()
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @name childKey
|
|
38
|
+
* @description Retrieves the child storage key for a given parachain’s crowdloan contributions.
|
|
39
|
+
* This key is used to access contribution data stored in a separate child trie of the blockchain’s state.
|
|
40
|
+
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
|
41
|
+
* @example
|
|
42
|
+
* ```javascript
|
|
43
|
+
* const childKey = await api.derive.crowdloan.childKey(3369);
|
|
44
|
+
* console.log("Child Key:", childKey);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function childKey (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<string | null> {
|
|
48
|
+
return memo(instanceId, (paraId: string | number | BN): Observable<string | null> =>
|
|
49
|
+
api.query['crowdloan']['funds']<Option<PolkadotRuntimeCommonCrowdloanFundInfo>>(paraId).pipe(
|
|
50
|
+
map((optInfo) =>
|
|
51
|
+
optInfo.isSome
|
|
52
|
+
? createChildKey(optInfo.unwrap())
|
|
53
|
+
: null
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { StorageKey } from '@pezkuwi/types';
|
|
6
|
+
import type { BN } from '@pezkuwi/util';
|
|
7
|
+
import type { DeriveApi, DeriveContributions } from '../types.js';
|
|
8
|
+
|
|
9
|
+
import { BehaviorSubject, combineLatest, EMPTY, map, of, startWith, switchMap, tap, toArray } from 'rxjs';
|
|
10
|
+
|
|
11
|
+
import { arrayFlatten, isFunction, nextTick } from '@pezkuwi/util';
|
|
12
|
+
|
|
13
|
+
import { memo } from '../util/index.js';
|
|
14
|
+
import { extractContributed } from './util.js';
|
|
15
|
+
|
|
16
|
+
interface Changes {
|
|
17
|
+
added: string[];
|
|
18
|
+
blockHash: string;
|
|
19
|
+
removed: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PAGE_SIZE_K = 1000; // limit aligned with the 1k on the node (trie lookups are heavy)
|
|
23
|
+
|
|
24
|
+
function _getUpdates (api: DeriveApi, paraId: string | number | BN): Observable<Changes> {
|
|
25
|
+
let added: string[] = [];
|
|
26
|
+
let removed: string[] = [];
|
|
27
|
+
|
|
28
|
+
return api.query.system.events().pipe(
|
|
29
|
+
switchMap((events): Observable<Changes> => {
|
|
30
|
+
const changes = extractContributed(paraId, events);
|
|
31
|
+
|
|
32
|
+
if (changes.added.length || changes.removed.length) {
|
|
33
|
+
added = added.concat(...changes.added);
|
|
34
|
+
removed = removed.concat(...changes.removed);
|
|
35
|
+
|
|
36
|
+
return of({ added, addedDelta: changes.added, blockHash: events.createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return EMPTY;
|
|
40
|
+
}),
|
|
41
|
+
startWith({ added, addedDelta: [], blockHash: '-', removed, removedDelta: [] })
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _eventTriggerAll (api: DeriveApi, paraId: string | number | BN): Observable<string> {
|
|
46
|
+
return api.query.system.events().pipe(
|
|
47
|
+
switchMap((events): Observable<string> => {
|
|
48
|
+
const items = events.filter(({ event: { data: [eventParaId], method, section } }) =>
|
|
49
|
+
section === 'crowdloan' &&
|
|
50
|
+
['AllRefunded', 'Dissolved', 'PartiallyRefunded'].includes(method) &&
|
|
51
|
+
eventParaId.eq(paraId)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return items.length
|
|
55
|
+
? of(events.createdAtHash?.toHex() || '-')
|
|
56
|
+
: EMPTY;
|
|
57
|
+
}),
|
|
58
|
+
startWith('-')
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _getKeysPaged (api: DeriveApi, childKey: string): Observable<StorageKey[]> {
|
|
63
|
+
const subject = new BehaviorSubject<string | undefined>(undefined);
|
|
64
|
+
|
|
65
|
+
return subject.pipe(
|
|
66
|
+
switchMap((startKey) =>
|
|
67
|
+
api.rpc.childstate.getKeysPaged(childKey, '0x', PAGE_SIZE_K, startKey)
|
|
68
|
+
),
|
|
69
|
+
tap((keys): void => {
|
|
70
|
+
nextTick((): void => {
|
|
71
|
+
keys.length === PAGE_SIZE_K
|
|
72
|
+
? subject.next(keys[PAGE_SIZE_K - 1].toHex())
|
|
73
|
+
: subject.complete();
|
|
74
|
+
});
|
|
75
|
+
}),
|
|
76
|
+
toArray(), // toArray since we want to startSubject to be completed
|
|
77
|
+
map((keyArr: StorageKey[][]) => arrayFlatten(keyArr))
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function _getAll (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable<string[]> {
|
|
82
|
+
return _eventTriggerAll(api, paraId).pipe(
|
|
83
|
+
switchMap(() =>
|
|
84
|
+
isFunction(api.rpc.childstate.getKeysPaged)
|
|
85
|
+
? _getKeysPaged(api, childKey)
|
|
86
|
+
: api.rpc.childstate.getKeys(childKey, '0x')
|
|
87
|
+
),
|
|
88
|
+
map((keys) =>
|
|
89
|
+
keys.map((k) => k.toHex())
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable<DeriveContributions> {
|
|
95
|
+
return combineLatest([
|
|
96
|
+
_getAll(api, paraId, childKey),
|
|
97
|
+
_getUpdates(api, paraId)
|
|
98
|
+
]).pipe(
|
|
99
|
+
map(([keys, { added, blockHash, removed }]): DeriveContributions => {
|
|
100
|
+
const contributorsMap: Record<string, boolean> = {};
|
|
101
|
+
|
|
102
|
+
keys.forEach((k): void => {
|
|
103
|
+
contributorsMap[k] = true;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
added.forEach((k): void => {
|
|
107
|
+
contributorsMap[k] = true;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
removed.forEach((k): void => {
|
|
111
|
+
delete contributorsMap[k];
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
blockHash,
|
|
116
|
+
contributorsHex: Object.keys(contributorsMap)
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @name contributions
|
|
124
|
+
* @description Retrieves all contributions for a given parachain crowdloan.
|
|
125
|
+
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
|
126
|
+
* @example
|
|
127
|
+
* ```javascript
|
|
128
|
+
* const contributions = await api.derive.crowdloan.contributions(3369);
|
|
129
|
+
* console.log("Contributions:", contributions);
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function contributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<DeriveContributions> {
|
|
133
|
+
return memo(instanceId, (paraId: string | number | BN): Observable<DeriveContributions> =>
|
|
134
|
+
api.derive.crowdloan.childKey(paraId).pipe(
|
|
135
|
+
switchMap((childKey) =>
|
|
136
|
+
childKey
|
|
137
|
+
? _contributions(api, paraId, childKey)
|
|
138
|
+
: of({ blockHash: '-', contributorsHex: [] })
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { BN } from '@pezkuwi/util';
|
|
6
|
+
import type { DeriveApi, DeriveOwnContributions } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { combineLatest, EMPTY, map, of, startWith, switchMap } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
import { objectSpread } from '@pezkuwi/util';
|
|
11
|
+
|
|
12
|
+
import { memo } from '../util/index.js';
|
|
13
|
+
import { extractContributed } from './util.js';
|
|
14
|
+
|
|
15
|
+
function _getValues (api: DeriveApi, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
|
16
|
+
// We actually would love to use multi-keys https://github.com/paritytech/substrate/issues/9203
|
|
17
|
+
return combineLatest(keys.map((k) => api.rpc.childstate.getStorage(childKey, k))).pipe(
|
|
18
|
+
map((values) =>
|
|
19
|
+
values
|
|
20
|
+
.map((v) => api.registry.createType('Option<StorageData>', v))
|
|
21
|
+
.map((o) =>
|
|
22
|
+
o.isSome
|
|
23
|
+
? api.registry.createType('Balance', o.unwrap())
|
|
24
|
+
: api.registry.createType('Balance')
|
|
25
|
+
)
|
|
26
|
+
.reduce((all: DeriveOwnContributions, b, index): DeriveOwnContributions =>
|
|
27
|
+
objectSpread(all, { [keys[index]]: b }), {})
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _watchOwnChanges (api: DeriveApi, paraId: string | number | BN, childkey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
|
33
|
+
return api.query.system.events().pipe(
|
|
34
|
+
switchMap((events): Observable<DeriveOwnContributions> => {
|
|
35
|
+
const changes = extractContributed(paraId, events);
|
|
36
|
+
const filtered = keys.filter((k) =>
|
|
37
|
+
changes.added.includes(k) ||
|
|
38
|
+
changes.removed.includes(k)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return filtered.length
|
|
42
|
+
? _getValues(api, childkey, filtered)
|
|
43
|
+
: EMPTY;
|
|
44
|
+
}),
|
|
45
|
+
startWith({})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
|
50
|
+
return combineLatest([
|
|
51
|
+
_getValues(api, childKey, keys),
|
|
52
|
+
_watchOwnChanges(api, paraId, childKey, keys)
|
|
53
|
+
]).pipe(
|
|
54
|
+
map(([all, latest]) =>
|
|
55
|
+
objectSpread({}, all, latest)
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @name ownContributions
|
|
62
|
+
* @description Retrieves the contribution amounts made by specific accounts (`keys`) to a given parachain crowdloan (`paraId`).
|
|
63
|
+
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
|
64
|
+
* @param {string[]} keys An array of account addresses whose contributions are to be fetched.
|
|
65
|
+
* @example
|
|
66
|
+
* ```javascript
|
|
67
|
+
* const contributions = await api.derive.crowdloan.ownContributions(2000, ['5Ff...PqV', '5Gg...XyZ']);
|
|
68
|
+
* console.log("Own Contributions:", contributions);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function ownContributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN, keys: string[]) => Observable<DeriveOwnContributions> {
|
|
72
|
+
return memo(instanceId, (paraId: string | number | BN, keys: string[]): Observable<DeriveOwnContributions> =>
|
|
73
|
+
api.derive.crowdloan.childKey(paraId).pipe(
|
|
74
|
+
switchMap((childKey) =>
|
|
75
|
+
childKey && keys.length
|
|
76
|
+
? _contributions(api, paraId, childKey, keys)
|
|
77
|
+
: of({})
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Balance } from '@pezkuwi/types/interfaces';
|
|
5
|
+
|
|
6
|
+
export interface DeriveContributions {
|
|
7
|
+
blockHash: string;
|
|
8
|
+
contributorsHex: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type DeriveOwnContributions = Record<string, Balance>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { FrameSystemEventRecord } from '@pezkuwi/types/lookup';
|
|
5
|
+
import type { Vec } from '@pezkuwi/types-codec';
|
|
6
|
+
import type { BN } from '@pezkuwi/util';
|
|
7
|
+
|
|
8
|
+
interface Changes {
|
|
9
|
+
added: string[];
|
|
10
|
+
blockHash: string;
|
|
11
|
+
removed: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function extractContributed (paraId: string | number | BN, events: Vec<FrameSystemEventRecord>): Changes {
|
|
15
|
+
const added: string[] = [];
|
|
16
|
+
const removed: string[] = [];
|
|
17
|
+
|
|
18
|
+
return events
|
|
19
|
+
.filter(({ event: { data: [, eventParaId], method, section } }) =>
|
|
20
|
+
section === 'crowdloan' &&
|
|
21
|
+
['Contributed', 'Withdrew'].includes(method) &&
|
|
22
|
+
eventParaId.eq(paraId)
|
|
23
|
+
)
|
|
24
|
+
.reduce((result: Changes, { event: { data: [accountId], method } }): Changes => {
|
|
25
|
+
if (method === 'Contributed') {
|
|
26
|
+
result.added.push(accountId.toHex());
|
|
27
|
+
} else {
|
|
28
|
+
result.removed.push(accountId.toHex());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}, { added, blockHash: events.createdAtHash?.toHex() || '-', removed });
|
|
33
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
import type { Bytes, Option, u8, u32, Vec } from '@pezkuwi/types';
|
|
6
|
+
import type { BlockNumber, Call, Hash, ReferendumIndex, Scheduled } from '@pezkuwi/types/interfaces';
|
|
7
|
+
import type { FrameSupportPreimagesBounded, PalletSchedulerScheduled } from '@pezkuwi/types/lookup';
|
|
8
|
+
import type { Codec, ITuple } from '@pezkuwi/types/types';
|
|
9
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
10
|
+
import type { DeriveApi, DeriveDispatch, DeriveProposalImage } from '../types.js';
|
|
11
|
+
|
|
12
|
+
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
|
13
|
+
|
|
14
|
+
import { Enum } from '@pezkuwi/types';
|
|
15
|
+
import { isFunction, objectSpread, stringToHex } from '@pezkuwi/util';
|
|
16
|
+
|
|
17
|
+
import { memo } from '../util/index.js';
|
|
18
|
+
import { getImageHashBounded } from './util.js';
|
|
19
|
+
|
|
20
|
+
const DEMOCRACY_ID = stringToHex('democrac');
|
|
21
|
+
|
|
22
|
+
// included here for backwards compat
|
|
23
|
+
interface PalletSchedulerScheduledV3 extends Codec {
|
|
24
|
+
maybeId: Option<Bytes>;
|
|
25
|
+
priority: u8;
|
|
26
|
+
call: FrameSupportScheduleMaybeHashed;
|
|
27
|
+
maybePeriodic: Option<ITuple<[u32, u32]>>;
|
|
28
|
+
origin: Codec;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// included here for backwards compat
|
|
32
|
+
interface FrameSupportScheduleMaybeHashed extends Codec {
|
|
33
|
+
isHash: boolean;
|
|
34
|
+
isValue: boolean;
|
|
35
|
+
asValue: Call;
|
|
36
|
+
asHash: Hash;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface SchedulerInfo {
|
|
40
|
+
at: BlockNumber;
|
|
41
|
+
imageHash: HexString;
|
|
42
|
+
index: ReferendumIndex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isMaybeHashedOrBounded (call: FrameSupportPreimagesBounded | FrameSupportScheduleMaybeHashed | Call): call is FrameSupportScheduleMaybeHashed | FrameSupportPreimagesBounded {
|
|
46
|
+
// check for enum
|
|
47
|
+
return call instanceof Enum;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isBounded (call: FrameSupportPreimagesBounded | FrameSupportScheduleMaybeHashed): call is FrameSupportPreimagesBounded {
|
|
51
|
+
// check for type
|
|
52
|
+
return (call as FrameSupportPreimagesBounded).isInline || (call as FrameSupportPreimagesBounded).isLegacy || (call as FrameSupportPreimagesBounded).isLookup;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function queryQueue (api: DeriveApi): Observable<DeriveDispatch[]> {
|
|
56
|
+
return api.query.democracy['dispatchQueue']<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>().pipe(
|
|
57
|
+
switchMap((dispatches) =>
|
|
58
|
+
combineLatest([
|
|
59
|
+
of(dispatches),
|
|
60
|
+
api.derive.democracy.preimages(
|
|
61
|
+
dispatches.map(([, hash]) => hash))
|
|
62
|
+
])
|
|
63
|
+
),
|
|
64
|
+
map(([dispatches, images]) =>
|
|
65
|
+
dispatches.map(([at, imageHash, index], dispatchIndex): DeriveDispatch => ({
|
|
66
|
+
at,
|
|
67
|
+
image: images[dispatchIndex],
|
|
68
|
+
imageHash: getImageHashBounded(imageHash),
|
|
69
|
+
index
|
|
70
|
+
}))
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function schedulerEntries (api: DeriveApi): Observable<[BlockNumber[], Option<PalletSchedulerScheduled | PalletSchedulerScheduledV3 | Scheduled>[][]]> {
|
|
76
|
+
// We don't get entries, but rather we get the keys (triggered via finished referendums) and
|
|
77
|
+
// the subscribe to those keys - this means we pickup when the schedulers actually executes
|
|
78
|
+
// at a block, the entry for that block will become empty
|
|
79
|
+
return api.derive.democracy.referendumsFinished().pipe(
|
|
80
|
+
switchMap(() =>
|
|
81
|
+
api.query.scheduler.agenda.keys()
|
|
82
|
+
),
|
|
83
|
+
switchMap((keys) => {
|
|
84
|
+
const blockNumbers = keys.map(({ args: [blockNumber] }) => blockNumber);
|
|
85
|
+
|
|
86
|
+
return blockNumbers.length
|
|
87
|
+
? combineLatest([
|
|
88
|
+
of(blockNumbers),
|
|
89
|
+
// this should simply be api.query.scheduler.agenda.multi,
|
|
90
|
+
// however we have had cases on Darwinia where the indices have moved around after an
|
|
91
|
+
// upgrade, which results in invalid on-chain data
|
|
92
|
+
api.query.scheduler.agenda.multi(blockNumbers).pipe(
|
|
93
|
+
catchError(() => of(blockNumbers.map(() => [])))
|
|
94
|
+
)
|
|
95
|
+
])
|
|
96
|
+
: of<[BlockNumber[], Option<PalletSchedulerScheduledV3 | Scheduled>[][]]>([[], []]);
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function queryScheduler (api: DeriveApi): Observable<DeriveDispatch[]> {
|
|
102
|
+
return schedulerEntries(api).pipe(
|
|
103
|
+
switchMap(([blockNumbers, agendas]): Observable<[SchedulerInfo[], (DeriveProposalImage | undefined)[]]> => {
|
|
104
|
+
const result: SchedulerInfo[] = [];
|
|
105
|
+
|
|
106
|
+
blockNumbers.forEach((at, index): void => {
|
|
107
|
+
(agendas[index] || []).filter((o) => o.isSome).forEach((o): void => {
|
|
108
|
+
const scheduled = o.unwrap();
|
|
109
|
+
|
|
110
|
+
if (scheduled.maybeId.isSome) {
|
|
111
|
+
const id = scheduled.maybeId.unwrap().toHex();
|
|
112
|
+
|
|
113
|
+
if (id.startsWith(DEMOCRACY_ID)) {
|
|
114
|
+
const imageHash = isMaybeHashedOrBounded(scheduled.call)
|
|
115
|
+
? isBounded(scheduled.call)
|
|
116
|
+
? getImageHashBounded(scheduled.call)
|
|
117
|
+
: scheduled.call.isHash
|
|
118
|
+
? scheduled.call.asHash.toHex()
|
|
119
|
+
: scheduled.call.asValue.args[0].toHex()
|
|
120
|
+
: scheduled.call.args[0].toHex();
|
|
121
|
+
|
|
122
|
+
result.push({ at, imageHash, index: api.registry.createType('(u64, ReferendumIndex)', id)[1] });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return combineLatest([
|
|
129
|
+
of(result),
|
|
130
|
+
result.length
|
|
131
|
+
? api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
|
|
132
|
+
: of([])
|
|
133
|
+
]);
|
|
134
|
+
}),
|
|
135
|
+
map(([infos, images]): DeriveDispatch[] =>
|
|
136
|
+
infos.map((info, index) => objectSpread({ image: images[index] }, info))
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @name dispatchQueue
|
|
143
|
+
* @description Retrieves the list of scheduled or pending dispatches in the governance system.
|
|
144
|
+
* @example
|
|
145
|
+
* ```javascript
|
|
146
|
+
* const queue = await api.derive.democracy.dispatchQueue();
|
|
147
|
+
* console.log("Dispatch Queue:", queue);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export function dispatchQueue (instanceId: string, api: DeriveApi): () => Observable<DeriveDispatch[]> {
|
|
151
|
+
return memo(instanceId, (): Observable<DeriveDispatch[]> =>
|
|
152
|
+
isFunction(api.query.scheduler?.agenda)
|
|
153
|
+
? queryScheduler(api)
|
|
154
|
+
: api.query.democracy['dispatchQueue']
|
|
155
|
+
? queryQueue(api)
|
|
156
|
+
: of([])
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export * from './dispatchQueue.js';
|
|
5
|
+
export * from './locks.js';
|
|
6
|
+
export * from './nextExternal.js';
|
|
7
|
+
export * from './preimages.js';
|
|
8
|
+
export * from './proposals.js';
|
|
9
|
+
export * from './referendumIds.js';
|
|
10
|
+
export * from './referendums.js';
|
|
11
|
+
export * from './referendumsActive.js';
|
|
12
|
+
export * from './referendumsFinished.js';
|
|
13
|
+
export * from './referendumsInfo.js';
|
|
14
|
+
export * from './sqrtElectorate.js';
|