@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,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name members
|
|
3
|
+
* @description Retrieves the list of members in the "technicalCommittee" collective.
|
|
4
|
+
* @example
|
|
5
|
+
* ```javascript
|
|
6
|
+
* const members = await api.derive.technicalCommittee.members();
|
|
7
|
+
* console.log(`Members: ${JSON.stringify(members)});
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare const members: import("../collective/types.js").MembersFnRet;
|
|
11
|
+
/**
|
|
12
|
+
* @name hasProposals
|
|
13
|
+
* @description Checks if there are any active proposals in the "technicalCommittee" collective.
|
|
14
|
+
* @example
|
|
15
|
+
* ```javascript
|
|
16
|
+
* const exists = await api.derive.technicalCommittee.hasProposals();
|
|
17
|
+
* console.log(exists);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const hasProposals: import("../collective/types.js").HasProposalsFnRet;
|
|
21
|
+
/**
|
|
22
|
+
* @name proposal
|
|
23
|
+
* @description Retrieves details of a specific proposal in the "technicalCommitteeMotion" collective by its hash.
|
|
24
|
+
* @example
|
|
25
|
+
* ```javascript
|
|
26
|
+
* const proposalDetails = await api.derive.technicalCommittee.proposal(PROPOSAL_HASH);
|
|
27
|
+
* console.log(proposalDetails);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const proposal: import("../collective/types.js").ProposalFnRet;
|
|
31
|
+
/**
|
|
32
|
+
* @name proposalCount
|
|
33
|
+
* @description Retrieves the total number of proposals in the "technicalCommittee" collective.
|
|
34
|
+
* @example
|
|
35
|
+
* ```javascript
|
|
36
|
+
* const count = await api.derive.technicalCommittee.proposalCount();
|
|
37
|
+
* console.log(`Amount of proposals: ${count}`);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const proposalCount: import("../collective/types.js").ProposalCountFnRet;
|
|
41
|
+
/**
|
|
42
|
+
* @name proposalHashes
|
|
43
|
+
* @description Retrieves an array of hashes for all active proposals in the "technicalCommittee" collective.
|
|
44
|
+
* @example
|
|
45
|
+
* ```javascript
|
|
46
|
+
* const hashes = await api.derive.technicalCommittee.proposalHashes();
|
|
47
|
+
* console.log(`Proposals ${JSON.stringify(hashes)}`);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const proposalHashes: import("../collective/types.js").ProposalHashesFnRet;
|
|
51
|
+
/**
|
|
52
|
+
* @name proposals
|
|
53
|
+
* @description Retrieves a list of all active proposals in the "technicalCommittee" collective.
|
|
54
|
+
* @example
|
|
55
|
+
* ```javascript
|
|
56
|
+
* const proposals = await api.derive.technicalCommittee.proposals();
|
|
57
|
+
* console.log(proposals);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const proposals: import("../collective/types.js").ProposalsFnRet;
|
|
61
|
+
/**
|
|
62
|
+
* @name prime
|
|
63
|
+
* @description Retrieves the prime member of the "technicalCommittee" collective, if one exists.
|
|
64
|
+
* @example
|
|
65
|
+
* ```javascript
|
|
66
|
+
* const primeMember = await api.derive.technicalCommittee.prime();
|
|
67
|
+
* console.log(primeMember);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const prime: import("../collective/types.js").PrimeFnRet;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './proposals.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { DeriveApi, DeriveTreasuryProposals } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name proposals
|
|
5
|
+
* @description Retrieve all active and approved treasury proposals, along with their info.
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* const treasuryProposals = await api.derive.treasury.proposals();
|
|
9
|
+
* console.log(treasuryProposals);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function proposals(instanceId: string, api: DeriveApi): () => Observable<DeriveTreasuryProposals>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { EventRecord, Hash, SignedBlock } from '@pezkuwi/types/interfaces';
|
|
3
|
+
import type { DeriveApi } from '../types.js';
|
|
4
|
+
interface Result {
|
|
5
|
+
block: SignedBlock;
|
|
6
|
+
events: EventRecord[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @name events
|
|
10
|
+
* @param {Hash} at Block hash to query at.
|
|
11
|
+
* @description Retrieves the block information alongside its events at a given block hash
|
|
12
|
+
* @example
|
|
13
|
+
* ```javascript
|
|
14
|
+
* const blockHash = api.registry.createType(
|
|
15
|
+
* "Hash",
|
|
16
|
+
* "0xf1dc2efe8265be67deea5e91b05a98a7f9f81f66854e92825cf36f541beb7af6"
|
|
17
|
+
* );
|
|
18
|
+
* const { events, block } = await api.derive.tx.events(blockHash);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function events(instanceId: string, api: DeriveApi): (at: Hash) => Observable<Result>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { GenericExtrinsic } from '@pezkuwi/types';
|
|
3
|
+
import type { EventRecord, Hash } from '@pezkuwi/types/interfaces';
|
|
4
|
+
import type { DeriveApi } from '../types.js';
|
|
5
|
+
interface ExtrinsicInfo {
|
|
6
|
+
blockHash: Hash | string;
|
|
7
|
+
blockNumber: number;
|
|
8
|
+
extrinsic: GenericExtrinsic;
|
|
9
|
+
events: EventRecord[];
|
|
10
|
+
success: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface ExtrinsicsInfo {
|
|
13
|
+
blockHash: Hash | string;
|
|
14
|
+
blockNumber: number;
|
|
15
|
+
extrinsics: {
|
|
16
|
+
events: EventRecord[];
|
|
17
|
+
extrinsic: GenericExtrinsic;
|
|
18
|
+
success: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @name extrinsicInfo
|
|
23
|
+
* @param { Hash } at The block hash to query at.
|
|
24
|
+
* @param { Uint8Array | string } transactionHash A transaction hash as U8 array or string.
|
|
25
|
+
* @description Retrieves the extrinsic information and its events.
|
|
26
|
+
* @example
|
|
27
|
+
* ```javascript
|
|
28
|
+
* const blockHash = api.registry.createType(
|
|
29
|
+
* 'Hash',
|
|
30
|
+
* '0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
|
|
31
|
+
* );
|
|
32
|
+
* const extrinsicInfo = await api.derive.tx.extrinsicInfo(
|
|
33
|
+
* blockHash,
|
|
34
|
+
* '0xcd96520b05e0c4648ea365f3f063f27c5cdd8be10d41a1c44566428c91f37dcb'
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* console.log(extrinsicInfo.extrinsic.toHuman());
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function extrinsicInfo(instanceId: string, api: DeriveApi): (at: Hash, transactionHash: Uint8Array | string) => Observable<ExtrinsicInfo | null>;
|
|
41
|
+
/**
|
|
42
|
+
* @name accountExtrinsics
|
|
43
|
+
* @description Retrieves information about every extrinsic submitted by an account at a given block.
|
|
44
|
+
* @param { Hash } at The block hash to query at.
|
|
45
|
+
* @param { Uint8Array | strings } accountId The account identifier to query.
|
|
46
|
+
* @example
|
|
47
|
+
* ```javascript
|
|
48
|
+
const blockHash = api.registry.createType(
|
|
49
|
+
'Hash',
|
|
50
|
+
'0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
|
|
51
|
+
);
|
|
52
|
+
const extrinsicsInfo = await api.derive.tx.accountExtrinsics(
|
|
53
|
+
blockHash,
|
|
54
|
+
'0x21895DdfD4640b4e0aDCa2865b907f2CE6e6B777'
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
console.log(extrinsicsInfo.extrinsics[0]).extrinsic.toHuman();
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function accountExtrinsics(instanceId: string, api: DeriveApi): (at: Hash, accountId: Uint8Array | string) => Observable<ExtrinsicsInfo>;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { Header, Index } from '@pezkuwi/types/interfaces';
|
|
3
|
+
import type { AnyNumber, Codec, IExtrinsicEra } from '@pezkuwi/types/types';
|
|
4
|
+
import type { DeriveApi } from '../types.js';
|
|
5
|
+
interface Result {
|
|
6
|
+
header: Header | null;
|
|
7
|
+
mortalLength: number;
|
|
8
|
+
nonce: Index;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @name signingInfo
|
|
12
|
+
* @description Retrieves signing-related information for an account, including the nonce, block header, and mortal length.
|
|
13
|
+
* @param {string} address The account address for which signing information is needed.
|
|
14
|
+
* @param { BN | bigint | Uint8Array | number | string } nonce? (Optional) The nonce to use. If `undefined`, the latest nonce is retrieved.
|
|
15
|
+
* @param { IExtrinsicEra | number } era? (Optional) The transaction era.
|
|
16
|
+
* @example
|
|
17
|
+
* ```javascript
|
|
18
|
+
* const info = await api.derive.tx.signingInfo(
|
|
19
|
+
* "14mM9FRDDtwSYicjNxSvMfQkap8o4m9zHq7hNW4JpbSL4PPU"
|
|
20
|
+
* );
|
|
21
|
+
* console.log(info);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function signingInfo(_instanceId: string, api: DeriveApi): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable<Result>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AccountId, Header } from '@pezkuwi/types/interfaces';
|
|
2
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
3
|
+
import type { HeaderExtended } from './types.js';
|
|
4
|
+
export declare function createHeaderExtended(registry: Registry, header?: Header, validators?: AccountId[] | null, author?: AccountId | null): HeaderExtended;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AccountId, EventRecord, SignedBlock } from '@pezkuwi/types/interfaces';
|
|
2
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
3
|
+
import type { SignedBlockExtended } from './types.js';
|
|
4
|
+
export declare function createSignedBlockExtended(registry: Registry, block?: SignedBlock, events?: EventRecord[], validators?: AccountId[] | null, author?: AccountId | null): SignedBlockExtended;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AccountId, DispatchError, DispatchInfo, Event, EventRecord, Extrinsic, Header, SignedBlock } from '@pezkuwi/types/interfaces';
|
|
2
|
+
export interface HeaderExtended extends Header {
|
|
3
|
+
readonly author: AccountId | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface SignedBlockExtended extends SignedBlock {
|
|
6
|
+
readonly author: AccountId | undefined;
|
|
7
|
+
readonly events: EventRecord[];
|
|
8
|
+
readonly extrinsics: TxWithEvent[];
|
|
9
|
+
}
|
|
10
|
+
export interface TxWithEvent {
|
|
11
|
+
dispatchError?: DispatchError | undefined;
|
|
12
|
+
dispatchInfo?: DispatchInfo | undefined;
|
|
13
|
+
events: Event[];
|
|
14
|
+
extrinsic: Extrinsic;
|
|
15
|
+
}
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ApiInterfaceRx } from '@pezkuwi/api-base/types';
|
|
2
|
+
import type { u32 } from '@pezkuwi/types';
|
|
3
|
+
import type { Balance, BlockNumber, BountyIndex, Hash, Proposal, ProposalIndex, SetIndex, Votes } from '@pezkuwi/types/interfaces';
|
|
4
|
+
import type { PalletBountiesBounty, PalletTreasuryProposal } from '@pezkuwi/types/lookup';
|
|
5
|
+
import type { BN } from '@pezkuwi/util';
|
|
6
|
+
import type { ExactDerive } from './derive.js';
|
|
7
|
+
export * from './accounts/types.js';
|
|
8
|
+
export * from './bagsList/types.js';
|
|
9
|
+
export * from './balances/types.js';
|
|
10
|
+
export * from './council/types.js';
|
|
11
|
+
export * from './crowdloan/types.js';
|
|
12
|
+
export * from './democracy/types.js';
|
|
13
|
+
export * from './elections/types.js';
|
|
14
|
+
export * from './parachains/types.js';
|
|
15
|
+
export * from './session/types.js';
|
|
16
|
+
export * from './society/types.js';
|
|
17
|
+
export * from './staking/types.js';
|
|
18
|
+
export * from './type/types.js';
|
|
19
|
+
export interface DeriveApi extends ApiInterfaceRx {
|
|
20
|
+
derive: ExactDerive;
|
|
21
|
+
}
|
|
22
|
+
export interface DeriveContractFees {
|
|
23
|
+
callBaseFee: BN;
|
|
24
|
+
contractFee: BN;
|
|
25
|
+
creationFee: BN;
|
|
26
|
+
rentByteFee: BN;
|
|
27
|
+
rentDepositOffset: BN;
|
|
28
|
+
surchargeReward: BN;
|
|
29
|
+
tombstoneDeposit: BN;
|
|
30
|
+
transactionBaseFee: BN;
|
|
31
|
+
transactionByteFee: BN;
|
|
32
|
+
transferFee: BN;
|
|
33
|
+
}
|
|
34
|
+
export interface DeriveCollectiveProposal {
|
|
35
|
+
hash: Hash;
|
|
36
|
+
proposal: Proposal | null;
|
|
37
|
+
votes: Votes | null;
|
|
38
|
+
}
|
|
39
|
+
export interface DeriveFees {
|
|
40
|
+
creationFee: Balance;
|
|
41
|
+
existentialDeposit: Balance;
|
|
42
|
+
transactionBaseFee: Balance;
|
|
43
|
+
transactionByteFee: Balance;
|
|
44
|
+
transferFee: Balance;
|
|
45
|
+
}
|
|
46
|
+
export interface DeriveHeartbeatAuthor {
|
|
47
|
+
blockCount: u32;
|
|
48
|
+
hasMessage: boolean;
|
|
49
|
+
isOnline: boolean;
|
|
50
|
+
}
|
|
51
|
+
export type DeriveHeartbeats = Record<string, DeriveHeartbeatAuthor>;
|
|
52
|
+
export interface RecentlyOffline {
|
|
53
|
+
blockNumber: BlockNumber;
|
|
54
|
+
count: BN;
|
|
55
|
+
}
|
|
56
|
+
export type DeriveRecentlyOffline = Record<string, RecentlyOffline[]>;
|
|
57
|
+
export interface DeriveTreasuryProposal {
|
|
58
|
+
council: DeriveCollectiveProposal[];
|
|
59
|
+
id: ProposalIndex;
|
|
60
|
+
proposal: PalletTreasuryProposal;
|
|
61
|
+
}
|
|
62
|
+
export interface DeriveTreasuryProposals {
|
|
63
|
+
approvals: DeriveTreasuryProposal[];
|
|
64
|
+
proposalCount: ProposalIndex;
|
|
65
|
+
proposals: DeriveTreasuryProposal[];
|
|
66
|
+
}
|
|
67
|
+
export interface VoterPosition {
|
|
68
|
+
globalIndex: BN;
|
|
69
|
+
index: BN;
|
|
70
|
+
setIndex: SetIndex;
|
|
71
|
+
}
|
|
72
|
+
export type DeriveVoterPositions = Record<string, VoterPosition>;
|
|
73
|
+
export interface DeriveBounty {
|
|
74
|
+
bounty: PalletBountiesBounty;
|
|
75
|
+
description: string;
|
|
76
|
+
index: BountyIndex;
|
|
77
|
+
proposals: DeriveCollectiveProposal[];
|
|
78
|
+
}
|
|
79
|
+
export type DeriveBounties = DeriveBounty[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Compact } from '@pezkuwi/types';
|
|
2
|
+
import type { BlockNumber } from '@pezkuwi/types/interfaces';
|
|
3
|
+
interface CompatHeader {
|
|
4
|
+
number: Compact<BlockNumber> | BlockNumber;
|
|
5
|
+
}
|
|
6
|
+
export declare function unwrapBlockNumber(hdr: CompatHeader): BlockNumber;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { DeriveApi } from '../types.js';
|
|
3
|
+
export declare function firstObservable<T>(obs: Observable<T[]>): Observable<T>;
|
|
4
|
+
export declare function firstMemo<T, A extends any[]>(fn: (api: DeriveApi, ...args: A) => Observable<T[]>): (instanceId: string, api: DeriveApi) => (...args: A) => Observable<T>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
type LazySection<T> = Record<string, T>;
|
|
2
|
+
type LazyRecord<T> = Record<string, LazySection<T>>;
|
|
3
|
+
export declare function lazyDeriveSection<T>(result: LazyRecord<T>, section: string, getKeys: (s: string) => string[], creator: (s: string, m: string) => T): void;
|
|
4
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Jaco Greeff <jacogr@gmail.com>",
|
|
3
|
+
"bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
|
|
4
|
+
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/api-derive#readme",
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"name": "@pezkuwi/api-derive",
|
|
11
|
+
"repository": {
|
|
12
|
+
"directory": "packages/api-derive",
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/pezkuwichain/pezkuwi-api.git"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./packageDetect.js",
|
|
18
|
+
"./packageDetect.cjs"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"version": "16.5.5",
|
|
22
|
+
"main": "index.js",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@pezkuwi/api": "16.5.5",
|
|
25
|
+
"@pezkuwi/api-augment": "16.5.5",
|
|
26
|
+
"@pezkuwi/api-base": "16.5.5",
|
|
27
|
+
"@pezkuwi/rpc-core": "16.5.5",
|
|
28
|
+
"@pezkuwi/types": "16.5.5",
|
|
29
|
+
"@pezkuwi/types-codec": "16.5.5",
|
|
30
|
+
"@pezkuwi/util": "14.0.5",
|
|
31
|
+
"@pezkuwi/util-crypto": "14.0.5",
|
|
32
|
+
"rxjs": "^7.8.1",
|
|
33
|
+
"tslib": "^2.8.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@pezkuwi/api": "16.5.5",
|
|
37
|
+
"@pezkuwi/api-augment": "16.5.5",
|
|
38
|
+
"@pezkuwi/rpc-augment": "16.5.5",
|
|
39
|
+
"@pezkuwi/rpc-provider": "16.5.5",
|
|
40
|
+
"@pezkuwi/types-support": "16.5.5"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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, AccountIndex, Address } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type { DeriveApi } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { map, of } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
import { assertReturn, isU8a } from '@pezkuwi/util';
|
|
11
|
+
import { decodeAddress } from '@pezkuwi/util-crypto';
|
|
12
|
+
|
|
13
|
+
import { memo } from '../util/index.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @name accountId
|
|
17
|
+
* @param {(Address | AccountId | AccountIndex | string | null)} address An accounts address in various formats.
|
|
18
|
+
* @description Resolves an address (in different formats) to its corresponding `AccountId`.
|
|
19
|
+
* @example
|
|
20
|
+
* ```javascript
|
|
21
|
+
* const ALICE = "F7Hs";
|
|
22
|
+
*
|
|
23
|
+
* api.derive.accounts.accountId(ALICE, (accountId) => {
|
|
24
|
+
* console.log(`Resolved AccountId: ${accountId}`);
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function accountId (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
|
29
|
+
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => {
|
|
30
|
+
const decoded = isU8a(address)
|
|
31
|
+
? address
|
|
32
|
+
: decodeAddress((address || '').toString());
|
|
33
|
+
|
|
34
|
+
if (decoded.length > 8) {
|
|
35
|
+
return of(api.registry.createType(decoded.length === 20 ? 'AccountId20' : 'AccountId', decoded));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
|
39
|
+
|
|
40
|
+
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
|
41
|
+
map((a) => assertReturn(a, 'Unable to retrieve accountId'))
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
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, Address, Balance } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type{ PalletElectionsPhragmenSeatHolder } from '@pezkuwi/types/lookup';
|
|
7
|
+
import type { Codec } from '@pezkuwi/types/types';
|
|
8
|
+
import type { Option } from '@pezkuwi/types-codec';
|
|
9
|
+
import type { DeriveAccountFlags, DeriveApi } from '../types.js';
|
|
10
|
+
|
|
11
|
+
import { map, of } from 'rxjs';
|
|
12
|
+
|
|
13
|
+
import { isFunction } from '@pezkuwi/util';
|
|
14
|
+
|
|
15
|
+
import { memo } from '../util/index.js';
|
|
16
|
+
|
|
17
|
+
type FlagsIntermediate = [
|
|
18
|
+
PalletElectionsPhragmenSeatHolder[] | [AccountId, Balance][] | undefined,
|
|
19
|
+
AccountId[],
|
|
20
|
+
AccountId[],
|
|
21
|
+
AccountId[],
|
|
22
|
+
Option<AccountId> | AccountId | undefined
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function parseFlags (address: AccountId | Address | string | null | undefined, [electionsMembers, councilMembers, technicalCommitteeMembers, societyMembers, sudoKey]: FlagsIntermediate): DeriveAccountFlags {
|
|
26
|
+
const addrStr = address?.toString();
|
|
27
|
+
const isIncluded = (id: AccountId | Address | string) =>
|
|
28
|
+
id.toString() === addrStr;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
isCouncil: (electionsMembers?.map((r) => Array.isArray(r) ? r[0] : r.who) || councilMembers || []).some(isIncluded),
|
|
32
|
+
isSociety: (societyMembers || []).some(isIncluded),
|
|
33
|
+
isSudo: sudoKey?.toString() === addrStr,
|
|
34
|
+
isTechCommittee: (technicalCommitteeMembers || []).some(isIncluded)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function _flags (instanceId: string, api: DeriveApi): () => Observable<FlagsIntermediate> {
|
|
39
|
+
return memo(instanceId, (): Observable<FlagsIntermediate> => {
|
|
40
|
+
const results: unknown[] = [undefined, [], [], [], undefined];
|
|
41
|
+
const calls = [
|
|
42
|
+
(api.query.elections || api.query['phragmenElection'] || api.query['electionsPhragmen'])?.members,
|
|
43
|
+
api.query.council?.members,
|
|
44
|
+
api.query.technicalCommittee?.members,
|
|
45
|
+
api.query.society?.members,
|
|
46
|
+
api.query.sudo?.key
|
|
47
|
+
];
|
|
48
|
+
const filtered = calls.filter((c) => c);
|
|
49
|
+
|
|
50
|
+
if (!filtered.length) {
|
|
51
|
+
return of(results as FlagsIntermediate);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return api.queryMulti(filtered).pipe(
|
|
55
|
+
map((values: Codec[]): FlagsIntermediate => {
|
|
56
|
+
let resultIndex = -1;
|
|
57
|
+
|
|
58
|
+
for (let i = 0, count = calls.length; i < count; i++) {
|
|
59
|
+
if (isFunction(calls[i])) {
|
|
60
|
+
results[i] = values[++resultIndex];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return results as FlagsIntermediate;
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @name flags
|
|
72
|
+
* @param {(AccountId | Address | string | null)} address The account identifier.
|
|
73
|
+
* @description Retrieves the membership flags for a given account.
|
|
74
|
+
* @example
|
|
75
|
+
* const ALICE = "F7Hs";
|
|
76
|
+
*
|
|
77
|
+
* api.derive.accounts.flags(ALICE, (flags) => {
|
|
78
|
+
* console.log(
|
|
79
|
+
* `Account Flags:`,
|
|
80
|
+
* Object.keys(flags).map((flag) => `${flag}: ${flags[flag]}`)
|
|
81
|
+
* );
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
export function flags (instanceId: string, api: DeriveApi): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
|
85
|
+
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> =>
|
|
86
|
+
api.derive.accounts._flags().pipe(
|
|
87
|
+
map((r) => parseFlags(address, r))
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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, AccountIndex, Address } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type { AccountIdAndIndex, DeriveApi } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { map, of } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
import { isU8a } from '@pezkuwi/util';
|
|
11
|
+
import { decodeAddress } from '@pezkuwi/util-crypto';
|
|
12
|
+
|
|
13
|
+
import { memo } from '../util/index.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @name idAndIndex
|
|
17
|
+
* @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address An accounts address in various formats.
|
|
18
|
+
* @description An array containing the [[AccountId]] and [[AccountIndex]] as optional values.
|
|
19
|
+
* @example
|
|
20
|
+
* ```javascript
|
|
21
|
+
* api.derive.accounts.idAndIndex('F7Hs', ([id, ix]) => {
|
|
22
|
+
* console.log(`AccountId #${id} with corresponding AccountIndex ${ix}`);
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function idAndIndex (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> {
|
|
27
|
+
return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> => {
|
|
28
|
+
try {
|
|
29
|
+
// yes, this can fail, don't care too much, catch will catch it
|
|
30
|
+
const decoded = isU8a(address)
|
|
31
|
+
? address
|
|
32
|
+
: decodeAddress((address || '').toString());
|
|
33
|
+
|
|
34
|
+
if (decoded.length > 8) {
|
|
35
|
+
const accountId = api.registry.createType(decoded.length === 20 ? 'AccountId20' : 'AccountId', decoded);
|
|
36
|
+
|
|
37
|
+
return api.derive.accounts.idToIndex(accountId).pipe(
|
|
38
|
+
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
|
43
|
+
|
|
44
|
+
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
|
45
|
+
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
|
46
|
+
);
|
|
47
|
+
} catch {
|
|
48
|
+
return of([undefined, undefined]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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, AccountIndex } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type { AccountIndexes, DeriveApi } from '../types.js';
|
|
7
|
+
|
|
8
|
+
import { map } from 'rxjs';
|
|
9
|
+
|
|
10
|
+
import { memo } from '../util/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @name idToIndex
|
|
14
|
+
* @description Retrieves the corresponding AccountIndex.
|
|
15
|
+
* @param {( AccountId | string )} accountId An accounts Id in different formats.
|
|
16
|
+
* @example
|
|
17
|
+
* ```javascript
|
|
18
|
+
* const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
|
19
|
+
* api.derive.accounts.idToIndex(ALICE, (accountIndex) => {
|
|
20
|
+
* console.log(`The AccountIndex of ${ALICE} is ${accountIndex}`);
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function idToIndex (instanceId: string, api: DeriveApi): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
|
25
|
+
return memo(instanceId, (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
|
26
|
+
api.derive.accounts.indexes().pipe(
|
|
27
|
+
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
|
28
|
+
indexes[accountId.toString()]
|
|
29
|
+
)
|
|
30
|
+
));
|
|
31
|
+
}
|