@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,129 @@
|
|
|
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 { AugmentedConsts } from '@pezkuwi/api-base/types';
|
|
6
|
+
import type { u64 } from '@pezkuwi/types';
|
|
7
|
+
import type { Header, Index } from '@pezkuwi/types/interfaces';
|
|
8
|
+
import type { AnyNumber, Codec, IExtrinsicEra } from '@pezkuwi/types/types';
|
|
9
|
+
import type { BN } from '@pezkuwi/util';
|
|
10
|
+
import type { DeriveApi } from '../types.js';
|
|
11
|
+
|
|
12
|
+
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
|
13
|
+
|
|
14
|
+
import { isNumber, isUndefined } from '@pezkuwi/util';
|
|
15
|
+
|
|
16
|
+
import { unwrapBlockNumber } from '../util/index.js';
|
|
17
|
+
import { FALLBACK_MAX_HASH_COUNT, FALLBACK_PERIOD, MAX_FINALITY_LAG, MORTAL_PERIOD } from './constants.js';
|
|
18
|
+
|
|
19
|
+
interface Result {
|
|
20
|
+
header: Header | null;
|
|
21
|
+
mortalLength: number;
|
|
22
|
+
nonce: Index;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function latestNonce (api: DeriveApi, address: string): Observable<Index> {
|
|
26
|
+
return api.derive.balances.account(address).pipe(
|
|
27
|
+
map(({ accountNonce }) => accountNonce)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function nextNonce (api: DeriveApi, address: string): Observable<Index> {
|
|
32
|
+
if (api.call.accountNonceApi) {
|
|
33
|
+
return api.call.accountNonceApi.accountNonce(address);
|
|
34
|
+
} else {
|
|
35
|
+
return api.rpc.system?.accountNextIndex
|
|
36
|
+
? api.rpc.system.accountNextIndex(address)
|
|
37
|
+
: latestNonce(api, address);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function signingHeader (api: DeriveApi): Observable<Header> {
|
|
42
|
+
return combineLatest([
|
|
43
|
+
api.rpc.chain.getHeader().pipe(
|
|
44
|
+
switchMap((header) =>
|
|
45
|
+
// check for chains at genesis (until block 1 is produced, e.g. 6s), since
|
|
46
|
+
// we do need to allow transactions at chain start (also dev/seal chains)
|
|
47
|
+
header.parentHash.isEmpty
|
|
48
|
+
? of(header)
|
|
49
|
+
// in the case of the current block, we use the parent to minimize the
|
|
50
|
+
// impact of forks on the system, but not completely remove it
|
|
51
|
+
: api.rpc.chain.getHeader(header.parentHash).pipe(
|
|
52
|
+
catchError(() => of(header))
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
),
|
|
56
|
+
api.rpc.chain.getFinalizedHead().pipe(
|
|
57
|
+
switchMap((hash) =>
|
|
58
|
+
api.rpc.chain.getHeader(hash).pipe(
|
|
59
|
+
catchError(() => of(null))
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
]).pipe(
|
|
64
|
+
map(([current, finalized]) =>
|
|
65
|
+
// determine the hash to use, current when lag > max, else finalized
|
|
66
|
+
!finalized || unwrapBlockNumber(current).sub(unwrapBlockNumber(finalized)).gt(MAX_FINALITY_LAG)
|
|
67
|
+
? current
|
|
68
|
+
: finalized
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface Aura {
|
|
74
|
+
slotDuration: u64 & AugmentedConsts<'rxjs'>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function babeOrAuraPeriod (api: DeriveApi): BN | undefined {
|
|
78
|
+
const period = api.consts.babe?.expectedBlockTime ||
|
|
79
|
+
// this will be present ones https://github.com/paritytech/polkadot-sdk/pull/3732 is merged
|
|
80
|
+
|
|
81
|
+
// eslint-disable-next-line
|
|
82
|
+
(api.consts['aura'] as unknown as Aura)?.['slotDuration'] ||
|
|
83
|
+
api.consts.timestamp?.minimumPeriod.muln(2);
|
|
84
|
+
|
|
85
|
+
return period && period.isZero && !period.isZero() ? period : undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @name signingInfo
|
|
90
|
+
* @description Retrieves signing-related information for an account, including the nonce, block header, and mortal length.
|
|
91
|
+
* @param {string} address The account address for which signing information is needed.
|
|
92
|
+
* @param { BN | bigint | Uint8Array | number | string } nonce? (Optional) The nonce to use. If `undefined`, the latest nonce is retrieved.
|
|
93
|
+
* @param { IExtrinsicEra | number } era? (Optional) The transaction era.
|
|
94
|
+
* @example
|
|
95
|
+
* ```javascript
|
|
96
|
+
* const info = await api.derive.tx.signingInfo(
|
|
97
|
+
* "14mM9FRDDtwSYicjNxSvMfQkap8o4m9zHq7hNW4JpbSL4PPU"
|
|
98
|
+
* );
|
|
99
|
+
* console.log(info);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function signingInfo (_instanceId: string, api: DeriveApi): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable<Result> {
|
|
103
|
+
// no memo, we want to do this fresh on each run
|
|
104
|
+
return (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number): Observable<Result> =>
|
|
105
|
+
combineLatest([
|
|
106
|
+
// retrieve nonce if none was specified
|
|
107
|
+
isUndefined(nonce)
|
|
108
|
+
? latestNonce(api, address)
|
|
109
|
+
: nonce === -1
|
|
110
|
+
? nextNonce(api, address)
|
|
111
|
+
: of(api.registry.createType('Index', nonce)),
|
|
112
|
+
// if no era (create) or era > 0 (mortal), do block retrieval
|
|
113
|
+
(isUndefined(era) || (isNumber(era) && era > 0))
|
|
114
|
+
? signingHeader(api)
|
|
115
|
+
: of(null)
|
|
116
|
+
]).pipe(
|
|
117
|
+
map(([nonce, header]) => ({
|
|
118
|
+
header,
|
|
119
|
+
mortalLength: Math.min(
|
|
120
|
+
api.consts.system?.blockHashCount?.toNumber() || FALLBACK_MAX_HASH_COUNT,
|
|
121
|
+
MORTAL_PERIOD
|
|
122
|
+
.div(babeOrAuraPeriod(api) || FALLBACK_PERIOD)
|
|
123
|
+
.iadd(MAX_FINALITY_LAG)
|
|
124
|
+
.toNumber()
|
|
125
|
+
),
|
|
126
|
+
nonce
|
|
127
|
+
}))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { AccountId, Header } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
6
|
+
import type { HeaderExtended } from './types.js';
|
|
7
|
+
|
|
8
|
+
import { extractAuthor } from './util.js';
|
|
9
|
+
|
|
10
|
+
export function createHeaderExtended (registry: Registry, header?: Header, validators?: AccountId[] | null, author?: AccountId | null): HeaderExtended {
|
|
11
|
+
// an instance of the base extrinsic for us to extend
|
|
12
|
+
const HeaderBase = registry.createClass('Header');
|
|
13
|
+
|
|
14
|
+
class Implementation extends HeaderBase implements HeaderExtended {
|
|
15
|
+
readonly #author?: AccountId | undefined;
|
|
16
|
+
|
|
17
|
+
constructor (registry: Registry, header?: Header, validators?: AccountId[] | null, author?: AccountId | null) {
|
|
18
|
+
super(registry, header);
|
|
19
|
+
|
|
20
|
+
this.#author = author || extractAuthor(this.digest, validators || []);
|
|
21
|
+
this.createdAtHash = header?.createdAtHash;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description Convenience method, returns the author for the block
|
|
26
|
+
*/
|
|
27
|
+
public get author (): AccountId | undefined {
|
|
28
|
+
return this.#author;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return new Implementation(registry, header, validators, author);
|
|
33
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { AccountId, DispatchError, DispatchInfo, EventRecord, Extrinsic, SignedBlock } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
6
|
+
import type { SignedBlockExtended, TxWithEvent } from './types.js';
|
|
7
|
+
|
|
8
|
+
import { extractAuthor } from './util.js';
|
|
9
|
+
|
|
10
|
+
function mapExtrinsics (extrinsics: Extrinsic[], records: EventRecord[]): TxWithEvent[] {
|
|
11
|
+
return extrinsics.map((extrinsic, index): TxWithEvent => {
|
|
12
|
+
let dispatchError: DispatchError | undefined;
|
|
13
|
+
let dispatchInfo: DispatchInfo | undefined;
|
|
14
|
+
|
|
15
|
+
const events = records
|
|
16
|
+
.filter(({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index))
|
|
17
|
+
.map(({ event }) => {
|
|
18
|
+
if (event.section === 'system') {
|
|
19
|
+
if (event.method === 'ExtrinsicSuccess') {
|
|
20
|
+
dispatchInfo = event.data[0] as DispatchInfo;
|
|
21
|
+
} else if (event.method === 'ExtrinsicFailed') {
|
|
22
|
+
dispatchError = event.data[0] as DispatchError;
|
|
23
|
+
dispatchInfo = event.data[1] as DispatchInfo;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return event;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { dispatchError, dispatchInfo, events, extrinsic };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createSignedBlockExtended (registry: Registry, block?: SignedBlock, events?: EventRecord[], validators?: AccountId[] | null, author?: AccountId | null): SignedBlockExtended {
|
|
35
|
+
// an instance of the base extrinsic for us to extend
|
|
36
|
+
const SignedBlockBase = registry.createClass('SignedBlock');
|
|
37
|
+
|
|
38
|
+
class Implementation extends SignedBlockBase implements SignedBlockExtended {
|
|
39
|
+
readonly #author?: AccountId | undefined;
|
|
40
|
+
readonly #events: EventRecord[];
|
|
41
|
+
readonly #extrinsics: TxWithEvent[];
|
|
42
|
+
|
|
43
|
+
constructor (registry: Registry, block?: SignedBlock, events?: EventRecord[], validators?: AccountId[] | null, author?: AccountId | null) {
|
|
44
|
+
super(registry, block);
|
|
45
|
+
|
|
46
|
+
this.#author = author || extractAuthor(this.block.header.digest, validators || []);
|
|
47
|
+
this.#events = events || ([] as EventRecord[]);
|
|
48
|
+
this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events);
|
|
49
|
+
this.createdAtHash = block?.createdAtHash;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description Convenience method, returns the author for the block
|
|
54
|
+
*/
|
|
55
|
+
public get author (): AccountId | undefined {
|
|
56
|
+
return this.#author;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @description Convenience method, returns the events associated with the block
|
|
61
|
+
*/
|
|
62
|
+
public get events (): EventRecord[] {
|
|
63
|
+
return this.#events;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description Returns the extrinsics and their events, mapped
|
|
68
|
+
*/
|
|
69
|
+
public get extrinsics (): TxWithEvent[] {
|
|
70
|
+
return this.#extrinsics;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return new Implementation(registry, block, events, validators, author);
|
|
75
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { AccountId, DispatchError, DispatchInfo, Event, EventRecord, Extrinsic, Header, SignedBlock } from '@pezkuwi/types/interfaces';
|
|
5
|
+
|
|
6
|
+
export interface HeaderExtended extends Header {
|
|
7
|
+
readonly author: AccountId | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SignedBlockExtended extends SignedBlock {
|
|
11
|
+
readonly author: AccountId | undefined;
|
|
12
|
+
readonly events: EventRecord[];
|
|
13
|
+
readonly extrinsics: TxWithEvent[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TxWithEvent {
|
|
17
|
+
dispatchError?: DispatchError | undefined;
|
|
18
|
+
dispatchInfo?: DispatchInfo | undefined;
|
|
19
|
+
events: Event[];
|
|
20
|
+
extrinsic: Extrinsic;
|
|
21
|
+
}
|
package/src/type/util.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { AccountId, Digest } from '@pezkuwi/types/interfaces';
|
|
5
|
+
|
|
6
|
+
export function extractAuthor (digest: Digest, sessionValidators: AccountId[]): AccountId | undefined {
|
|
7
|
+
const [citem] = digest.logs.filter((e) => e.isConsensus);
|
|
8
|
+
const preRuntimeItems = digest.logs.filter((e) => e.isPreRuntime);
|
|
9
|
+
const [sitem] = digest.logs.filter((e) => e.isSeal);
|
|
10
|
+
let accountId: AccountId | undefined;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
// This is critical to be first for BABE (before Consensus)
|
|
14
|
+
// If not first, we end up dropping the author at session-end
|
|
15
|
+
// Iterate through ALL preRuntime logs to find a recognized engine
|
|
16
|
+
// (parachains may have multiple preRuntime logs, e.g., CMLS + aura)
|
|
17
|
+
for (const pitem of preRuntimeItems) {
|
|
18
|
+
const [engine, data] = pitem.asPreRuntime;
|
|
19
|
+
|
|
20
|
+
accountId = engine.extractAuthor(data, sessionValidators);
|
|
21
|
+
|
|
22
|
+
// Stop at first recognized engine that returns an author
|
|
23
|
+
if (accountId) {
|
|
24
|
+
return accountId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!accountId && citem) {
|
|
29
|
+
const [engine, data] = citem.asConsensus;
|
|
30
|
+
|
|
31
|
+
accountId = engine.extractAuthor(data, sessionValidators);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// SEAL, still used in e.g. Kulupu for pow
|
|
35
|
+
if (!accountId && sitem) {
|
|
36
|
+
const [engine, data] = sitem.asSeal;
|
|
37
|
+
|
|
38
|
+
accountId = engine.extractAuthor(data, sessionValidators);
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// ignore
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return accountId;
|
|
45
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { ApiInterfaceRx } from '@pezkuwi/api-base/types';
|
|
5
|
+
import type { u32 } from '@pezkuwi/types';
|
|
6
|
+
import type { Balance, BlockNumber, BountyIndex, Hash, Proposal, ProposalIndex, SetIndex, Votes } from '@pezkuwi/types/interfaces';
|
|
7
|
+
import type { PalletBountiesBounty, PalletTreasuryProposal } from '@pezkuwi/types/lookup';
|
|
8
|
+
import type { BN } from '@pezkuwi/util';
|
|
9
|
+
import type { ExactDerive } from './derive.js';
|
|
10
|
+
|
|
11
|
+
export * from './accounts/types.js';
|
|
12
|
+
export * from './bagsList/types.js';
|
|
13
|
+
export * from './balances/types.js';
|
|
14
|
+
export * from './council/types.js';
|
|
15
|
+
export * from './crowdloan/types.js';
|
|
16
|
+
export * from './democracy/types.js';
|
|
17
|
+
export * from './elections/types.js';
|
|
18
|
+
export * from './parachains/types.js';
|
|
19
|
+
export * from './session/types.js';
|
|
20
|
+
export * from './society/types.js';
|
|
21
|
+
export * from './staking/types.js';
|
|
22
|
+
export * from './type/types.js';
|
|
23
|
+
|
|
24
|
+
export interface DeriveApi extends ApiInterfaceRx {
|
|
25
|
+
derive: ExactDerive;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DeriveContractFees {
|
|
29
|
+
callBaseFee: BN;
|
|
30
|
+
contractFee: BN;
|
|
31
|
+
creationFee: BN;
|
|
32
|
+
rentByteFee: BN;
|
|
33
|
+
rentDepositOffset: BN;
|
|
34
|
+
surchargeReward: BN;
|
|
35
|
+
tombstoneDeposit: BN;
|
|
36
|
+
transactionBaseFee: BN;
|
|
37
|
+
transactionByteFee: BN;
|
|
38
|
+
transferFee: BN;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DeriveCollectiveProposal {
|
|
42
|
+
hash: Hash;
|
|
43
|
+
proposal: Proposal | null;
|
|
44
|
+
votes: Votes | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DeriveFees {
|
|
48
|
+
creationFee: Balance;
|
|
49
|
+
existentialDeposit: Balance;
|
|
50
|
+
transactionBaseFee: Balance;
|
|
51
|
+
transactionByteFee: Balance;
|
|
52
|
+
transferFee: Balance;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface DeriveHeartbeatAuthor {
|
|
56
|
+
blockCount: u32;
|
|
57
|
+
hasMessage: boolean;
|
|
58
|
+
isOnline: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type DeriveHeartbeats = Record<string, DeriveHeartbeatAuthor>;
|
|
62
|
+
|
|
63
|
+
export interface RecentlyOffline {
|
|
64
|
+
blockNumber: BlockNumber;
|
|
65
|
+
count: BN;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type DeriveRecentlyOffline = Record<string, RecentlyOffline[]>;
|
|
69
|
+
|
|
70
|
+
export interface DeriveTreasuryProposal {
|
|
71
|
+
council: DeriveCollectiveProposal[];
|
|
72
|
+
id: ProposalIndex;
|
|
73
|
+
proposal: PalletTreasuryProposal;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface DeriveTreasuryProposals {
|
|
77
|
+
approvals: DeriveTreasuryProposal[];
|
|
78
|
+
proposalCount: ProposalIndex;
|
|
79
|
+
proposals: DeriveTreasuryProposal[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface VoterPosition {
|
|
83
|
+
globalIndex: BN;
|
|
84
|
+
index: BN;
|
|
85
|
+
setIndex: SetIndex;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type DeriveVoterPositions = Record<string, VoterPosition>;
|
|
89
|
+
|
|
90
|
+
export interface DeriveBounty {
|
|
91
|
+
bounty: PalletBountiesBounty;
|
|
92
|
+
description: string;
|
|
93
|
+
index: BountyIndex;
|
|
94
|
+
proposals: DeriveCollectiveProposal[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type DeriveBounties = DeriveBounty[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
|
5
|
+
|
|
6
|
+
import type { ApprovalFlag } from '@pezkuwi/types/interfaces';
|
|
7
|
+
|
|
8
|
+
import { TypeRegistry } from '@pezkuwi/types/create';
|
|
9
|
+
|
|
10
|
+
import { approvalFlagsToBools } from './approvalFlagsToBools.js';
|
|
11
|
+
|
|
12
|
+
describe('approvalFlagsToBools', (): void => {
|
|
13
|
+
const registry = new TypeRegistry();
|
|
14
|
+
|
|
15
|
+
it('translates and empty array to empty', (): void => {
|
|
16
|
+
expect(
|
|
17
|
+
approvalFlagsToBools([] as ApprovalFlag[])
|
|
18
|
+
).toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('translates a single input', (): void => {
|
|
22
|
+
expect(
|
|
23
|
+
approvalFlagsToBools([
|
|
24
|
+
registry.createType('ApprovalFlag', 0b1010)
|
|
25
|
+
])
|
|
26
|
+
).toEqual([false, true, false, true]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('translates multiple inputs', (): void => {
|
|
30
|
+
expect(
|
|
31
|
+
approvalFlagsToBools([
|
|
32
|
+
registry.createType('ApprovalFlag', 0b0000),
|
|
33
|
+
registry.createType('ApprovalFlag', 0b1100)
|
|
34
|
+
])
|
|
35
|
+
).toEqual([false, false, false, true, true]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Vec } from '@pezkuwi/types';
|
|
5
|
+
import type { ApprovalFlag } from '@pezkuwi/types/interfaces/elections';
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export function approvalFlagsToBools (flags: Vec<ApprovalFlag> | ApprovalFlag[]): boolean[] {
|
|
9
|
+
const bools: boolean[] = [];
|
|
10
|
+
|
|
11
|
+
for (let i = 0, count = flags.length; i < count; i++) {
|
|
12
|
+
const str = flags[i].toString(2);
|
|
13
|
+
|
|
14
|
+
// read from lowest bit to highest
|
|
15
|
+
for (const bit of str.split('').reverse()) {
|
|
16
|
+
bools.push(!!parseInt(bit, 10));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// slice off trailing "false" values, as in substrate
|
|
21
|
+
const lastApproval = bools.lastIndexOf(true);
|
|
22
|
+
|
|
23
|
+
return lastApproval >= 0
|
|
24
|
+
? bools.slice(0, lastApproval + 1)
|
|
25
|
+
: [];
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { Compact } from '@pezkuwi/types';
|
|
5
|
+
import type { BlockNumber } from '@pezkuwi/types/interfaces';
|
|
6
|
+
|
|
7
|
+
import { isCompact } from '@pezkuwi/util';
|
|
8
|
+
|
|
9
|
+
interface CompatHeader { number: Compact<BlockNumber> | BlockNumber }
|
|
10
|
+
|
|
11
|
+
export function unwrapBlockNumber (hdr: CompatHeader): BlockNumber {
|
|
12
|
+
return isCompact<BlockNumber>(hdr.number)
|
|
13
|
+
? hdr.number.unwrap()
|
|
14
|
+
: hdr.number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { DeriveCache } from './types.js';
|
|
5
|
+
|
|
6
|
+
import { deriveNoopCache } from './cacheImpl.js';
|
|
7
|
+
|
|
8
|
+
interface CacheValue<T> {
|
|
9
|
+
v: T;
|
|
10
|
+
x: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CACHE_EXPIRY = 7 * (24 * 60) * (60 * 1000);
|
|
14
|
+
|
|
15
|
+
let deriveCache: DeriveCache;
|
|
16
|
+
|
|
17
|
+
function wrapCache (keyStart: string, cache: DeriveCache): DeriveCache {
|
|
18
|
+
return {
|
|
19
|
+
del: (partial: string): void => cache.del(`${keyStart}${partial}`),
|
|
20
|
+
forEach: cache.forEach,
|
|
21
|
+
get: <T> (partial: string): T | undefined => {
|
|
22
|
+
const key = `${keyStart}${partial}`;
|
|
23
|
+
const cached = cache.get<CacheValue<T>>(key);
|
|
24
|
+
|
|
25
|
+
if (cached) {
|
|
26
|
+
cached.x = Date.now();
|
|
27
|
+
cache.set(key, cached);
|
|
28
|
+
|
|
29
|
+
return cached.v;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
},
|
|
34
|
+
set: (partial: string, v: unknown): void => {
|
|
35
|
+
cache.set(`${keyStart}${partial}`, { v, x: Date.now() });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function clearCache (cache: DeriveCache): void {
|
|
41
|
+
// clear all expired values
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const all: string[] = [];
|
|
44
|
+
|
|
45
|
+
cache.forEach((key: string, { x }: CacheValue<any>): void => {
|
|
46
|
+
((now - x) > CACHE_EXPIRY) && all.push(key);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// don't do delete inside loop, just in-case
|
|
50
|
+
all.forEach((key) => cache.del(key));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function setDeriveCache (prefix = '', cache?: DeriveCache): void {
|
|
54
|
+
deriveCache = cache
|
|
55
|
+
? wrapCache(`derive:${prefix}:`, cache)
|
|
56
|
+
: deriveNoopCache;
|
|
57
|
+
|
|
58
|
+
if (cache) {
|
|
59
|
+
clearCache(cache);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setDeriveCache();
|
|
64
|
+
|
|
65
|
+
export { deriveCache };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { DeriveCache } from './types.js';
|
|
5
|
+
|
|
6
|
+
const mapCache = new Map<string, any>();
|
|
7
|
+
|
|
8
|
+
export const deriveMapCache: DeriveCache = {
|
|
9
|
+
del: (key: string): void => {
|
|
10
|
+
mapCache.delete(key);
|
|
11
|
+
},
|
|
12
|
+
forEach: (cb: (key: string, value: any) => void): void => {
|
|
13
|
+
for (const [k, v] of mapCache.entries()) {
|
|
14
|
+
cb(k, v);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
get: <T = any> (key: string): T | undefined => {
|
|
18
|
+
return mapCache.get(key) as T;
|
|
19
|
+
},
|
|
20
|
+
set: (key: string, value: any): void => {
|
|
21
|
+
mapCache.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const deriveNoopCache: DeriveCache = {
|
|
26
|
+
del: (): void => undefined,
|
|
27
|
+
forEach: () => undefined,
|
|
28
|
+
get: (): undefined => undefined,
|
|
29
|
+
set: (_: string, value: unknown): unknown => value
|
|
30
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { DeriveApi } from '../types.js';
|
|
6
|
+
|
|
7
|
+
import { map } from 'rxjs';
|
|
8
|
+
|
|
9
|
+
import { memo } from '@pezkuwi/rpc-core';
|
|
10
|
+
|
|
11
|
+
export function firstObservable <T> (obs: Observable<T[]>): Observable<T> {
|
|
12
|
+
return obs.pipe(map(([a]) => a));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function firstMemo <T, A extends any[]> (fn: (api: DeriveApi, ...args: A) => Observable<T[]>): (instanceId: string, api: DeriveApi) => (...args: A) => Observable<T> {
|
|
16
|
+
return (instanceId: string, api: DeriveApi) =>
|
|
17
|
+
memo(instanceId, (...args: A) =>
|
|
18
|
+
firstObservable<T>(fn(api, ...args))
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// all named
|
|
5
|
+
export { drr, memo } from '@pezkuwi/rpc-core';
|
|
6
|
+
|
|
7
|
+
// all starred
|
|
8
|
+
export * from './approvalFlagsToBools.js';
|
|
9
|
+
export * from './blockNumber.js';
|
|
10
|
+
export * from './cache.js';
|
|
11
|
+
export * from './cacheImpl.js';
|
|
12
|
+
export * from './first.js';
|
|
13
|
+
export * from './lazy.js';
|
package/src/util/lazy.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { lazyMethod, lazyMethods } from '@pezkuwi/util';
|
|
5
|
+
|
|
6
|
+
type LazySection <T> = Record<string, T>;
|
|
7
|
+
|
|
8
|
+
type LazyRecord <T> = Record<string, LazySection<T>>;
|
|
9
|
+
|
|
10
|
+
export function lazyDeriveSection <T> (result: LazyRecord<T>, section: string, getKeys: (s: string) => string[], creator: (s: string, m: string) => T): void {
|
|
11
|
+
lazyMethod(result, section, () =>
|
|
12
|
+
lazyMethods({}, getKeys(section), (method: string) =>
|
|
13
|
+
creator(section, method)
|
|
14
|
+
)
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface DeriveCache {
|
|
5
|
+
del: (key: string) => void;
|
|
6
|
+
forEach: (cb: (key: string, value: any) => void) => void;
|
|
7
|
+
get: <T = any> (key: string) => T | undefined;
|
|
8
|
+
set: (key: string, value: any) => void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "..",
|
|
5
|
+
"outDir": "./build",
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
},
|
|
8
|
+
"exclude": [
|
|
9
|
+
"**/test/*",
|
|
10
|
+
"**/checkTypes.manual.ts",
|
|
11
|
+
"**/mod.ts",
|
|
12
|
+
"**/*.spec.ts"
|
|
13
|
+
],
|
|
14
|
+
"references": [
|
|
15
|
+
{ "path": "../api-base/tsconfig.build.json" },
|
|
16
|
+
{ "path": "../api-augment/tsconfig.build.json" },
|
|
17
|
+
{ "path": "../rpc-core/tsconfig.build.json" },
|
|
18
|
+
{ "path": "../types/tsconfig.build.json" },
|
|
19
|
+
{ "path": "../types-codec/tsconfig.build.json" }
|
|
20
|
+
]
|
|
21
|
+
}
|