Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbb5a021a0 | ||
|
|
da7f32d96f | ||
|
|
591784cd65 | ||
|
|
ddd2f2dfe5 | ||
|
|
56f297d3b9 | ||
|
|
fa7669f0af | ||
|
|
2aa8525fe7 | ||
|
|
9254c5781f | ||
|
|
e13f3bea65 | ||
|
|
59c2327768 | ||
|
|
4b0c6aa515 | ||
|
|
6276e45155 | ||
|
|
c7cb1d84ab | ||
|
|
1a6025e012 | ||
|
|
83655c92c4 | ||
|
|
63a55d2f8a | ||
|
|
c32953b2ea | ||
|
|
e51cd1a2f7 | ||
|
|
e58694566e | ||
|
|
248561ca14 | ||
|
|
d4a9b43e88 | ||
|
|
f717663f50 | ||
|
|
49ebae9a55 | ||
|
|
7a1419e73a | ||
|
|
d15d05918c | ||
|
|
969151c4a7 | ||
|
|
23717bb180 | ||
|
|
e32ac213b9 | ||
|
|
584cbb994b | ||
|
|
dcb7760a0e | ||
|
|
fd6ba08f58 | ||
|
|
a30329b47d | ||
|
|
610f03d006 | ||
|
|
1cc9756d0e | ||
|
|
bf753cb858 | ||
|
|
9a2cd1c446 | ||
|
|
4a7bfe96e1 | ||
|
|
7c51354186 | ||
|
|
8a7707eb41 | ||
|
|
88eac8e654 | ||
|
|
c637d699bc | ||
|
|
d2450a9382 | ||
|
|
4dd6b82471 | ||
|
|
93ce2210da | ||
|
|
2463b52381 | ||
|
|
bc1cdc17e0 | ||
|
|
47ddfd75f7 | ||
|
|
9643a2e026 | ||
|
|
5ceaa53c59 | ||
|
|
edc09b56b4 | ||
|
|
9b940738d4 | ||
|
|
b86610381a | ||
|
|
dfe4bb32f0 | ||
|
|
b81c73b6ec | ||
|
|
9bb2549d0b | ||
|
|
ab90f8bd41 | ||
|
|
221712753f | ||
|
|
ed28a990af | ||
|
|
055f32d1d9 | ||
|
|
a175ce87d7 | ||
|
|
f0f1714b12 | ||
|
|
3778bd893b | ||
|
|
d4436e19fa | ||
|
|
4cf93fd4c0 | ||
|
|
6d94896764 | ||
|
|
bacb757d7d | ||
|
|
7be3cc949f | ||
|
|
41cc8b34aa | ||
|
|
4bbba5bb35 | ||
|
|
feae323f5c | ||
|
|
b363833a9f | ||
|
|
f083ea3861 | ||
|
|
f62e7f8bf9 | ||
|
|
fedb0a3f09 | ||
|
|
38928448bf | ||
|
|
cfbde5f6bd | ||
|
|
4b0e0bc6d3 | ||
|
|
9acb79f500 | ||
|
|
5dc0b38881 | ||
|
|
fab6f7e883 | ||
|
|
66e635e909 | ||
|
|
6e496d5a3c | ||
|
|
ca172c9a53 | ||
|
|
e9b83a9ff6 | ||
|
|
cf18d97b3a | ||
|
|
0b1c715408 | ||
|
|
5d493e1a03 | ||
|
|
e5437ef9e9 | ||
|
|
b56bed39e1 | ||
|
|
e789f91850 | ||
|
|
a236eb9453 | ||
|
|
7ef01b8534 | ||
|
|
0e58545a9d | ||
|
|
c474123777 | ||
|
|
93edfcf560 | ||
|
|
e5a67d82fa | ||
|
|
194f6aece1 | ||
|
|
3b4fef8f6e | ||
|
|
6c7323ee3a | ||
|
|
a97b50decb | ||
|
|
52accf6444 | ||
|
|
5b8eb231cc | ||
|
|
5ea62367d3 | ||
|
|
49a034a1a0 | ||
|
|
62a476cb4c | ||
|
|
b283673812 | ||
|
|
b6a075fefb | ||
|
|
afa844ae01 | ||
|
|
353ef59a1c | ||
|
|
6228999e6f | ||
|
|
56db42fedf | ||
|
|
df44693e5d | ||
|
|
cfa25f8dda | ||
|
|
bc8934f3c3 | ||
|
|
bc67c72e9b | ||
|
|
22d85e745a | ||
|
|
60ba2952f7 | ||
|
|
bb10d2813f | ||
|
|
80b581f0df | ||
|
|
ef37c421ac | ||
|
|
6e1e8e622b | ||
|
|
ec38a1510f | ||
|
|
e550ca5a71 | ||
|
|
80241f732f | ||
|
|
84fc0be12e | ||
|
|
e1f14e8a83 | ||
|
|
1155724604 | ||
|
|
3bb9541943 | ||
|
|
25288f664a | ||
|
|
879c5d7b44 | ||
|
|
cdaec1953c | ||
|
|
f4bf7a9c52 | ||
|
|
7b46c6aa15 | ||
|
|
d28f4ccfa0 | ||
|
|
e5b05dc700 | ||
|
|
bf9831753e | ||
|
|
5e1670dbae | ||
|
|
0d0a230c86 | ||
|
|
9989b69b46 | ||
|
|
66693253ef | ||
|
|
cbffc37dcf | ||
|
|
74ee42ed66 | ||
|
|
f642e2399f | ||
|
|
8cefb055db | ||
|
|
1f31756019 | ||
|
|
4d6a1da6d5 | ||
|
|
d62e720627 | ||
|
|
4af4470998 | ||
|
|
8bb6218132 | ||
|
|
f4197f8752 | ||
|
|
7cfad3b1c4 | ||
|
|
ff67a659b6 | ||
|
|
a5c69a42fc | ||
|
|
3facbf00eb | ||
|
|
5a6eece6d6 | ||
|
|
9219fa3197 | ||
|
|
32b9a39b1e | ||
|
|
61a7fe6307 | ||
|
|
ca755d3e0d | ||
|
|
442dba42ba | ||
|
|
ba80dd8873 | ||
|
|
1d35302dca | ||
|
|
39c3121437 | ||
|
|
d7de1d84fb | ||
|
|
0ee1dfb353 | ||
|
|
0a6f1d87d4 | ||
|
|
b7c563391c | ||
|
|
b648c4ba6c | ||
|
|
0eb995c9a1 | ||
|
|
936d14ffea | ||
|
|
72c7a0a34b | ||
|
|
8402013e97 | ||
|
|
fde6b72974 | ||
|
|
d98d4d6908 | ||
|
|
ed384666ee | ||
|
|
4e64e3d654 | ||
|
|
72b4b51915 | ||
|
|
81f5bf96f5 | ||
|
|
e935281b77 | ||
|
|
e132330c0b | ||
|
|
21594aa660 | ||
|
|
6fb7989b41 | ||
|
|
1f38a38bd5 | ||
|
|
e918aa8b14 | ||
|
|
4a33b18ac4 | ||
|
|
cb97fd1a48 | ||
|
|
51600bc560 | ||
|
|
12344ed980 | ||
|
|
0b6773a744 | ||
|
|
17a38e9c09 | ||
|
|
70499fe6ac | ||
|
|
64493e0091 | ||
|
|
ae3efb31f8 | ||
|
|
6da58d0698 | ||
|
|
07f40c1429 | ||
|
|
f5f67e795e | ||
|
|
5b0652c272 | ||
|
|
53ef5f7c56 | ||
|
|
71f99875e4 | ||
|
|
a097075bfe | ||
|
|
527f840950 | ||
|
|
7fadc7eedb | ||
|
|
35663319d9 | ||
|
|
b9d9670d18 | ||
|
|
fd027f452c | ||
|
|
10a6e03f85 | ||
|
|
522eb8359f | ||
|
|
d1fd7f75af | ||
|
|
bb61b1e6ac | ||
|
|
7c17baa5be | ||
|
|
9e7c0a1959 | ||
|
|
db2e97bf66 | ||
|
|
057f6b6041 | ||
|
|
ca82336087 | ||
|
|
761ceaeaa3 | ||
|
|
0cbca0adb8 | ||
|
|
d24db4fd6a | ||
|
|
4a893b9feb | ||
|
|
71a0a84f26 | ||
|
|
44d241f489 | ||
|
|
a4cb5f558d | ||
|
|
aef4d07c48 | ||
|
|
6a5f1bbbf4 | ||
|
|
e60ef2d677 | ||
|
|
f4622d05db | ||
|
|
47d7900809 | ||
|
|
2c86e9347b | ||
|
|
5827d298ad | ||
|
|
60e0f69920 | ||
|
|
97f1ee17b0 | ||
|
|
85215a308d | ||
|
|
89fa4edcf7 | ||
|
|
ec42fb9bff | ||
|
|
96d696dbf3 | ||
|
|
b7992ecc0b | ||
|
|
0acae6e158 | ||
|
|
6afea5043e | ||
|
|
c9ee8d9942 | ||
|
|
55f4e150c0 | ||
|
|
3e3e9c5f5a | ||
|
|
66215890dd | ||
|
|
bf6c7ee0c3 | ||
|
|
f726edf725 | ||
|
|
d917861a77 | ||
|
|
12a54efde5 | ||
|
|
9ae87bed78 | ||
|
|
7f5a52258c | ||
|
|
2c212e6b4d | ||
|
|
3d75744a20 | ||
|
|
d2ff259989 | ||
|
|
cac2ef30a1 | ||
|
|
ea38dedcc1 | ||
|
|
0bd632e612 | ||
|
|
4ce7163bb1 | ||
|
|
72fbd3f829 | ||
|
|
f20fadb51c | ||
|
|
0e0183dc99 | ||
|
|
fa71e129c2 | ||
|
|
cb68842da6 | ||
|
|
44f348ecc5 | ||
|
|
891a6106f0 | ||
|
|
90fcc234a9 | ||
|
|
72fcd97cdb | ||
|
|
2ded2052b7 | ||
|
|
a8da5707f2 | ||
|
|
f508668c46 | ||
|
|
15ed0723f1 | ||
|
|
c9b0502542 | ||
|
|
0d5a841a81 | ||
|
|
e47b8c1e73 | ||
|
|
50fe50d1a8 | ||
|
|
9e4669b8b4 | ||
|
|
1e383315e2 | ||
|
|
6f66eb2b66 | ||
|
|
0864340ae2 | ||
|
|
a3f5c65b5d | ||
|
|
7f94137b2d | ||
|
|
d65587f58d | ||
|
|
8959455401 | ||
|
|
8e40e38bd6 | ||
|
|
c646717576 |
@@ -39,3 +39,10 @@
|
||||
6.0.4
|
||||
6.0.5
|
||||
6.1.2
|
||||
|
||||
6.4.2
|
||||
6.5.2
|
||||
6.7.2
|
||||
6.9.2
|
||||
6.10.2
|
||||
6.10.3
|
||||
@@ -1,3 +1,17 @@
|
||||
checks:
|
||||
argument-count:
|
||||
config:
|
||||
threshold: 5
|
||||
method-complexity:
|
||||
config:
|
||||
threshold: 7
|
||||
method-count:
|
||||
config:
|
||||
threshold: 25
|
||||
method-lines:
|
||||
config:
|
||||
threshold: 30
|
||||
|
||||
exclude_patterns:
|
||||
- "**/*.spec.js"
|
||||
- "**/*.spec.ts"
|
||||
|
||||
@@ -2,7 +2,7 @@ name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '30 1/2 * * *'
|
||||
- cron: '10 1/3 * * *'
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 'Close stale issues and PRs'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '30 2/2 * * *'
|
||||
- cron: '55 1/3 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ tmp/
|
||||
cc-test-reporter
|
||||
lerna-debug.log*
|
||||
npm-debug.log*
|
||||
package-lock.json
|
||||
tsconfig.*buildinfo
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
package-lock.json
|
||||
|
||||
+192
@@ -1,5 +1,197 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 6.12.1 Dec 13, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of contracts on the current Substrate master version and TS users who generate metadata v14 interfaces.
|
||||
|
||||
Changes:
|
||||
|
||||
- Add support for contracts V2 ABI metadata
|
||||
- `CheckNonZeroSender` signed extension support
|
||||
- Remove old-style capabilities detection (unneeded with metadata v14+)
|
||||
- Generated TS Enum interfaces now expose the `type` (with allowed values)
|
||||
- Split local & package imports in generated TS interfaces
|
||||
- Add Kusama 9130 upgrade block
|
||||
- Internal maintainability cleanups
|
||||
|
||||
|
||||
## 6.11.1 Dec 5, 2021
|
||||
|
||||
Upgrade priority: Low. Maintenance upgrade, tracking the latest `@polkadot` libraries.
|
||||
|
||||
Changes:
|
||||
|
||||
- Align `state_traceBlock` RPC with Substrate
|
||||
- Bump static metadata for latest Substrate, Polkadot & Kusama
|
||||
|
||||
|
||||
## 6.10.3 Nov 30, 2021
|
||||
|
||||
Upgrade priority: Medium. Recommended for 6.10.x users
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix ss58Prefix extraction
|
||||
|
||||
|
||||
## 6.10.2 Nov 30, 2021
|
||||
|
||||
Upgrade priority: Low. Aligns TS augmentation and decoration with older behavior for ALL_CAPS identifiers.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust augmentation interface consistency with top-level declarations
|
||||
- Update `@polkadot/util` to 8.0.4 with adjusted `stringCamelCase`
|
||||
|
||||
|
||||
## 6.10.1 Nov 29, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of `HttpProvider` and for chains generating types using TS augmentation.
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix for HttpProvider init (RPC sections with only subscriptions)
|
||||
- Re-order imports in lookup type augmentation interfaces
|
||||
- Bump static metadata for latest Substrate, Polkadot & Kusama
|
||||
|
||||
|
||||
## 6.9.2 Nov 22, 2021
|
||||
|
||||
Upgrade priority: Medium. Pulls in `@polkadot/util-crypto` fix for TS projects.
|
||||
|
||||
Changes:
|
||||
|
||||
- Update `@polkadot/util-crypto` with TS compilation work-around
|
||||
|
||||
|
||||
## 6.9.1 Nov 21, 2021
|
||||
|
||||
Upgrade priority: Medium. Recommended for metadata v14 parachains. For TS users, the package now support TypeScript 4.5.2 and allows extraction of user types from metadata v14.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Lookup TS generation for all metadata v14 chains (Thanks to https://github.com/savudani8)
|
||||
- Update `BeefySignedCommitment` type (Thanks to https://github.com/czl1378)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust runtime `*::{Call, Event}` matching for metadata v14
|
||||
- Adjust derive decoration with (optional) known methods
|
||||
- Expose `*{Call, Event, Error}` TS types for metadata v14
|
||||
- Align Option `.toJSON` output with Substrate input
|
||||
- Optimize Enum, Struct, Option & Number decoding paths
|
||||
- Ajust PascalCase conversions with function from util
|
||||
- Prepare pre-v13 types for optional injection
|
||||
- Adjustments for TS 4.5.2 support (flatten type infers)
|
||||
|
||||
|
||||
## 6.8.1 Nov 11, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for chains with non-MultiSignature variants where `paymentInfo` is required.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust `paymentInfo` signatures to cater for non-MultiSignature variants
|
||||
- Remove `::generic::` from names & namespaces under metadata v14
|
||||
- Add Polkadot 9122 upgrade block
|
||||
- Cleanup Polkadot/Kusama/Westend/Rococo known types (>= v14 metadata)
|
||||
- Internal `decorateMethod{Promise, Rx}` renamed to `to{Promise, Rx}Method`
|
||||
- Add RPC provider-level LRU for historic requests
|
||||
- Add optional known runtime version param to internal `rx.queryAt`
|
||||
|
||||
|
||||
## 6.7.2 Nov 9, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for chains on metadata v14 with non-default `Address` implementations.
|
||||
|
||||
Changes:
|
||||
|
||||
- Detect `AccountId` & `Address` types via `SpRuntime*` definitions
|
||||
- Adjust api-derive call ordering when using `.queryAt`
|
||||
|
||||
|
||||
## 6.7.1 Nov 7, 2021
|
||||
|
||||
Upgrade priority: Low. Internal maintenance updates, focussed on internal optimizations.
|
||||
|
||||
Changelog:
|
||||
|
||||
- Optimize Extrinsic & block handling (Thanks to https://github.com/nazar-pc)
|
||||
- Add `account::AccountId20` mapping (Thanks to https://github.com/joelamouche)
|
||||
|
||||
Changes:
|
||||
|
||||
- Use new-gen `voteLockingPeriod` in democracy derives (as available)
|
||||
- Dynamically inject getters for `Extrinsic` payloads
|
||||
- Optimize caching for complex constructed type classes per registry
|
||||
- Convert metadata, rpc and api to use lazy decoration
|
||||
- Split u8a decoding paths for `Vec` (different from general path)
|
||||
- Keep track of initial u8a decoded length inside base Codecs
|
||||
- Extract multi property assignments for `Struct`, `Set`, `Json` & `Enum`
|
||||
- Move `PortableRegistry` location inside `@polkadot/types/metadata`
|
||||
- Bump static metadata for latest Substrate, Polkadot & Kusama
|
||||
|
||||
|
||||
## 6.6.1 Nov 1, 2021
|
||||
|
||||
Upgrade priority: Low. Internal maintenance updates.
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix construction for `palletVersion` keys with correct prefix
|
||||
- Add Polkadot `EthereumAddress` as a known `PortableRegistry` override
|
||||
- De-dupe `PortableRegistry` namespace splitting operations
|
||||
- Optimize internal `AbstractArray` & `Struct` u8a decoding
|
||||
- Shortcut `Struct` construction from `Struct` instance
|
||||
- Use internal `lookupName` in `createClass` (allows deeply recursive lookups)
|
||||
- Codec `toHex()` will now correctly return the TS `HexString` type
|
||||
- Update known upgrade blocks for Westend & Kusama
|
||||
- Bump static metadata for latest Substrate, Polkadot & Kusama
|
||||
|
||||
|
||||
## 6.5.2 Oct 26, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users with `.at` queries on unknown blocks.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust `toHuman` on `Call` to return names & (not only) values
|
||||
- Allow for optional known `RuntimeVersion` to short-circuit `api.at`
|
||||
- Ensure `Struct` decodes fully on `null` input (equivalent to `undefined` & `{}`)
|
||||
|
||||
|
||||
## 6.5.1 Oct 24, 2021
|
||||
|
||||
Upgrade priority: Low. Internal maintenance upgrades.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Add `Auction` to Polkadot pre-0.9.11 `ProxyType` (Thanks to https://github.com/wirednkod)
|
||||
|
||||
Changes:
|
||||
|
||||
- Ecah module now exposes the Substrate-added `palletVersion` storage item
|
||||
- Adjust Websocket `maxReceivedFrameSize` under Node
|
||||
- `TypeDef` structures now contain the `typeName` from metadata v14 on fields
|
||||
- Fix browser bundle imports for xcm-mapping (move to `types-known`)
|
||||
- Expose all extracted type names in `PortableRegistry`
|
||||
- Adjust `toJSON` (Ascii) output detection on `Raw`
|
||||
- Adjust `api.rpc.*.*.raw(..args)` return to the actual over-the-wire JSON result
|
||||
- Remove `api.rpc.*.*.json(..args)` since it now overlaps with new `.raw`
|
||||
- Bump static metadata for latest Substrate, Polkadot & Kusama
|
||||
|
||||
|
||||
## 6.4.2 Oct 18, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for Westmint runtime 500+
|
||||
|
||||
Changes:
|
||||
|
||||
- Ensure `SignerPayload` correctly serializes `Option` with `None`
|
||||
- Add Ethereum `BlockV{0, 1, 2}` types, aligning with latest Frontier
|
||||
- Additional tests for metadata serialization/de-serialization
|
||||
|
||||
|
||||
## 6.4.1 Oct 17, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for Kusama & Polkadot runtime 9110+
|
||||
|
||||
+20
-14
@@ -1,40 +1,46 @@
|
||||
{
|
||||
"repository": "https://github.com/polkadot-js/api",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api#readme",
|
||||
"license": "Apache-2",
|
||||
"packageManager": "yarn@3.0.1",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/api.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "commonjs",
|
||||
"version": "6.12.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^4.4.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build:interfaces && polkadot-dev-build-ts",
|
||||
"build:extra": "(cd packages/typegen && copyfiles scripts/* build)",
|
||||
"build:interfaces": "polkadot-types-internal-interfaces",
|
||||
"build:release": "polkadot-ci-ghact-build",
|
||||
"build:rollup": "polkadot-exec-rollup --config",
|
||||
"docs:metadata": "polkadot-types-internal-metadata",
|
||||
"chain:info": "polkadot-types-chain-info",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"clean": "polkadot-dev-clean-build",
|
||||
"docs:metadata": "polkadot-types-internal-metadata",
|
||||
"lint": "polkadot-dev-run-lint",
|
||||
"postinstall": "polkadot-dev-yarn-only",
|
||||
"test": "polkadot-dev-run-test --coverage --forceExit --runInBand --testPathIgnorePatterns e2e",
|
||||
"test:one": "polkadot-dev-run-test --detectOpenHandles --forceExit",
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.15.8",
|
||||
"@babel/register": "^7.15.3",
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/dev": "^0.63.3",
|
||||
"@polkadot/ts": "^0.4.9",
|
||||
"@babel/core": "^7.16.0",
|
||||
"@babel/register": "^7.16.0",
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/dev": "^0.63.39",
|
||||
"@polkadot/ts": "^0.4.18",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/jest": "^27.0.3",
|
||||
"copyfiles": "^2.4.1"
|
||||
},
|
||||
"version": "6.4.1",
|
||||
"packageManager": "yarn@3.0.1"
|
||||
"resolutions": {
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "6.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"contributors": [],
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/api-contract",
|
||||
"repository": {
|
||||
"directory": "packages/api-contract",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/api.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/api",
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"type": "module",
|
||||
"version": "6.12.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/api": "6.4.1",
|
||||
"@polkadot/types": "6.4.1",
|
||||
"@polkadot/util": "^7.5.1",
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/api": "6.12.1",
|
||||
"@polkadot/types": "6.12.1",
|
||||
"@polkadot/util": "^8.1.2",
|
||||
"rxjs": "^7.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -14,6 +14,7 @@ import { Abi } from '.';
|
||||
|
||||
interface SpecDef {
|
||||
messages: {
|
||||
label: string;
|
||||
name: string[] | string
|
||||
}[]
|
||||
}
|
||||
@@ -28,6 +29,9 @@ interface JSONAbi {
|
||||
spec: SpecDef;
|
||||
V1: {
|
||||
spec: SpecDef;
|
||||
},
|
||||
V2: {
|
||||
spec: SpecDef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +51,19 @@ function stringifyJson (registry: Registry): string {
|
||||
|
||||
describe('Abi', (): void => {
|
||||
describe('ABI', (): void => {
|
||||
Object.entries(abis).forEach(([abiName, abi]: [string, JSONAbi]) => {
|
||||
Object.entries(abis).forEach(([abiName, _abi]) => {
|
||||
const abi = _abi as unknown as JSONAbi;
|
||||
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
try {
|
||||
const messageIds = (abi.V1 ? abi.V1 : abi).spec.messages.map(({ name }) => Array.isArray(name) ? name[0] : name);
|
||||
const inkAbi = new Abi(abis[abiName] as AnyJson);
|
||||
const messageIds = (abi.V2 || abi.V1 || abi).spec.messages.map(({ label, name }) =>
|
||||
label || (
|
||||
Array.isArray(name)
|
||||
? name[0]
|
||||
: name
|
||||
)
|
||||
);
|
||||
const inkAbi = new Abi(abis[abiName]);
|
||||
|
||||
expect(inkAbi.messages.map(({ identifier }) => identifier)).toEqual(messageIds);
|
||||
} catch (error) {
|
||||
@@ -66,7 +78,7 @@ describe('Abi', (): void => {
|
||||
describe('TypeDef', (): void => {
|
||||
Object.keys(abis).forEach((abiName) => {
|
||||
it(`initializes from a contract ABI (${abiName})`, (): void => {
|
||||
const abi = new Abi(abis[abiName] as AnyJson);
|
||||
const abi = new Abi(abis[abiName]);
|
||||
const json = stringifyJson(abi.registry);
|
||||
const cmpPath = path.join(__dirname, `../../test/compare/${abiName}.test.json`);
|
||||
|
||||
@@ -87,8 +99,8 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('has the correct hash for the source', (): void => {
|
||||
const bundle = abis.ink_v0_flipperBundle as JSONAbi;
|
||||
const abi = new Abi(bundle as unknown as AnyJson);
|
||||
const abi = new Abi(abis.ink_v0_flipperBundle);
|
||||
const bundle = abis.ink_v0_flipperBundle as unknown as JSONAbi;
|
||||
|
||||
// manual
|
||||
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Bytes } from '@polkadot/types';
|
||||
import type { ChainProperties, ContractConstructorSpec, ContractEventSpec, ContractMessageParamSpec, ContractMessageSpec, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, Codec, Registry } from '@polkadot/types/types';
|
||||
import type { Bytes, PortableRegistry } from '@polkadot/types';
|
||||
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
|
||||
import type { Codec, Registry } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types';
|
||||
|
||||
import { TypeDefInfo, TypeRegistry } from '@polkadot/types';
|
||||
import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { toLatest } from './toLatest';
|
||||
|
||||
interface V0AbiJson {
|
||||
metadataVersion: string;
|
||||
spec: {
|
||||
constructors: unknown[];
|
||||
events: unknown[];
|
||||
messages: unknown[];
|
||||
};
|
||||
types: unknown[];
|
||||
}
|
||||
import { v0ToLatest, v1ToLatest } from './toLatest';
|
||||
|
||||
const l = logger('Abi');
|
||||
|
||||
@@ -35,17 +25,30 @@ function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string
|
||||
return assertReturn(message, () => `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`);
|
||||
}
|
||||
|
||||
function parseJson (json: AnyJson, chainProperties?: ChainProperties): [AnyJson, Registry, ContractMetadataLatest, ContractProjectInfo] {
|
||||
// FIXME: This is still workable with V0, V1 & V2, but certainly is not a scalable
|
||||
// approach (right at this point don't quite have better ideas that is not as complex
|
||||
// as the conversion tactics in the runtime Metadata)
|
||||
function getLatestMeta (registry: Registry, json: Record<string, unknown>): ContractMetadataLatest {
|
||||
const metadata = registry.createType('ContractMetadata',
|
||||
isObject(json.V2)
|
||||
? { V2: json.V2 }
|
||||
: isObject(json.V1)
|
||||
? { V1: json.V1 }
|
||||
: { V0: json }
|
||||
);
|
||||
|
||||
return metadata.isV2
|
||||
? metadata.asV2
|
||||
: metadata.isV1
|
||||
? v1ToLatest(registry, metadata.asV1)
|
||||
: v0ToLatest(registry, metadata.asV0);
|
||||
}
|
||||
|
||||
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataLatest, ContractProjectInfo] {
|
||||
const registry = new TypeRegistry();
|
||||
const info = registry.createType('ContractProjectInfo', json);
|
||||
const metadata = registry.createType('ContractMetadata', isString((json as unknown as V0AbiJson).metadataVersion)
|
||||
? { V0: json }
|
||||
: { V1: (json as Record<string, AnyJson>).V1 }
|
||||
);
|
||||
const latest = metadata.isV0
|
||||
? toLatest(registry, metadata.asV0)
|
||||
: metadata.asV1;
|
||||
const lookup = registry.createType('PortableRegistry', { types: latest.types });
|
||||
const latest = getLatestMeta(registry, json);
|
||||
const lookup = registry.createType<PortableRegistry>('PortableRegistry', { types: latest.types });
|
||||
|
||||
// attach the lookup to the registry - now the types are known
|
||||
registry.setLookup(lookup);
|
||||
@@ -69,7 +72,7 @@ export class Abi {
|
||||
|
||||
public readonly info: ContractProjectInfo;
|
||||
|
||||
public readonly json: AnyJson;
|
||||
public readonly json: Record<string, unknown>;
|
||||
|
||||
public readonly messages: AbiMessage[];
|
||||
|
||||
@@ -77,22 +80,22 @@ export class Abi {
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
constructor (abiJson: AnyJson, chainProperties?: ChainProperties) {
|
||||
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
|
||||
[this.json, this.registry, this.metadata, this.info] = parseJson(
|
||||
isString(abiJson)
|
||||
? JSON.parse(abiJson) as AnyJson
|
||||
? JSON.parse(abiJson) as Record<string, unknown>
|
||||
: abiJson,
|
||||
chainProperties
|
||||
);
|
||||
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpec, index) =>
|
||||
this.constructors = this.metadata.spec.constructors.map((spec: ContractConstructorSpecLatest, index) =>
|
||||
this.#createMessage(spec, index, {
|
||||
isConstructor: true
|
||||
})
|
||||
);
|
||||
this.events = this.metadata.spec.events.map((spec: ContractEventSpec, index) =>
|
||||
this.events = this.metadata.spec.events.map((spec: ContractEventSpecLatest, index) =>
|
||||
this.#createEvent(spec, index)
|
||||
);
|
||||
this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpec, index): AbiMessage => {
|
||||
this.messages = this.metadata.spec.messages.map((spec: ContractMessageSpecLatest, index): AbiMessage => {
|
||||
const typeSpec = spec.returnType.unwrapOr(null);
|
||||
|
||||
return this.#createMessage(spec, index, {
|
||||
@@ -139,15 +142,15 @@ export class Abi {
|
||||
return findMessage(this.messages, messageOrId);
|
||||
}
|
||||
|
||||
#createArgs = (args: ContractMessageParamSpec[], spec: unknown): AbiParam[] => {
|
||||
return args.map(({ name, type }, index): AbiParam => {
|
||||
#createArgs = (args: ContractMessageParamSpecLatest[], spec: unknown): AbiParam[] => {
|
||||
return args.map(({ label, type }, index): AbiParam => {
|
||||
try {
|
||||
assert(isObject(type), 'Invalid type definition found');
|
||||
|
||||
const displayName = type.displayName.length
|
||||
? type.displayName[type.displayName.length - 1].toString()
|
||||
: undefined;
|
||||
const camelName = stringCamelCase(name);
|
||||
const camelName = stringCamelCase(label);
|
||||
|
||||
if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) {
|
||||
return {
|
||||
@@ -175,7 +178,7 @@ export class Abi {
|
||||
});
|
||||
};
|
||||
|
||||
#createEvent = (spec: ContractEventSpec, index: number): AbiEvent => {
|
||||
#createEvent = (spec: ContractEventSpecLatest, index: number): AbiEvent => {
|
||||
const args = this.#createArgs(spec.args, spec);
|
||||
const event = {
|
||||
args,
|
||||
@@ -184,16 +187,16 @@ export class Abi {
|
||||
args: this.#decodeArgs(args, data),
|
||||
event
|
||||
}),
|
||||
identifier: spec.name.toString(),
|
||||
identifier: spec.label.toString(),
|
||||
index
|
||||
};
|
||||
|
||||
return event;
|
||||
};
|
||||
|
||||
#createMessage = (spec: ContractMessageSpec | ContractConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
|
||||
#createMessage = (spec: ContractMessageSpecLatest | ContractConstructorSpecLatest, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
|
||||
const args = this.#createArgs(spec.args, spec);
|
||||
const identifier = spec.name.toString();
|
||||
const identifier = spec.label.toString();
|
||||
const message = {
|
||||
...add,
|
||||
args,
|
||||
@@ -237,8 +240,8 @@ export class Abi {
|
||||
return message.fromU8a(trimmed.subarray(4));
|
||||
};
|
||||
|
||||
#encodeArgs = ({ name, selector }: ContractMessageSpec | ContractConstructorSpec, args: AbiParam[], data: unknown[]): Uint8Array => {
|
||||
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`);
|
||||
#encodeArgs = ({ label, selector }: ContractMessageSpecLatest | ContractConstructorSpecLatest, args: AbiParam[], data: unknown[]): Uint8Array => {
|
||||
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${label.toString()}', found ${data.length}`);
|
||||
|
||||
return compactAddLength(
|
||||
u8aConcat(
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import abis from '../../test/contracts';
|
||||
import { v0ToLatest, v1ToLatest } from './toLatest';
|
||||
|
||||
describe('v0ToLatest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const contract = registry.createType('ContractMetadata', { V0: abis.ink_v0_erc20 });
|
||||
const latest = v0ToLatest(registry, contract.asV0);
|
||||
|
||||
it('has the correct constructors', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors.map(({ label }) => label.toString())
|
||||
).toEqual(['new']);
|
||||
});
|
||||
|
||||
it('has the correct messages', (): void => {
|
||||
expect(
|
||||
latest.spec.messages.map(({ label }) => label.toString())
|
||||
).toEqual(['total_supply', 'balance_of', 'allowance', 'transfer', 'approve', 'transfer_from']);
|
||||
});
|
||||
|
||||
it('has the correct events', (): void => {
|
||||
expect(
|
||||
latest.spec.events.map(({ label }) => label.toString())
|
||||
).toEqual(['Transfer', 'Approval']);
|
||||
});
|
||||
|
||||
it('has the correct constructor arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['initial_supply']);
|
||||
});
|
||||
|
||||
it('has the correct message arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.messages[1].args.map(({ label }) => label.toString())
|
||||
).toEqual(['owner']);
|
||||
});
|
||||
|
||||
it('has the correct event arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.events[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['from', 'to', 'value']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('v1ToLatest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const contract = registry.createType('ContractMetadata', { V1: abis.ink_v1_flipper.V1 });
|
||||
const latest = v1ToLatest(registry, contract.asV1);
|
||||
|
||||
it('has the correct constructors', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors.map(({ label }) => label.toString())
|
||||
).toEqual(['new', 'default']);
|
||||
});
|
||||
|
||||
it('has the correct messages', (): void => {
|
||||
expect(
|
||||
latest.spec.messages.map(({ label }) => label.toString())
|
||||
).toEqual(['flip', 'get']);
|
||||
});
|
||||
|
||||
it('has the correct constructor arguments', (): void => {
|
||||
expect(
|
||||
latest.spec.constructors[0].args.map(({ label }) => label.toString())
|
||||
).toEqual(['init_value']);
|
||||
});
|
||||
});
|
||||
@@ -1,14 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ContractMetadataLatest, ContractMetadataV0 } from '@polkadot/types/interfaces';
|
||||
import type { ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { convertSiV0toV1 } from '@polkadot/types/generic/PortableRegistry';
|
||||
import { v0ToV1 } from './toV1';
|
||||
import { v1ToV2 } from './toV2';
|
||||
|
||||
export function toLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest {
|
||||
return registry.createType('ContractMetadataLatest', {
|
||||
...v0,
|
||||
types: convertSiV0toV1(registry, v0.types)
|
||||
});
|
||||
export function v1ToLatest (registry: Registry, v1: ContractMetadataV1): ContractMetadataLatest {
|
||||
return v1ToV2(registry, v1);
|
||||
}
|
||||
|
||||
export function v0ToLatest (registry: Registry, v0: ContractMetadataV0): ContractMetadataLatest {
|
||||
return v1ToLatest(registry, v0ToV1(registry, v0));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ContractMetadataV0, ContractMetadataV1 } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { convertSiV0toV1 } from '@polkadot/types';
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
export function v0ToV1 (registry: Registry, v0: ContractMetadataV0): ContractMetadataV1 {
|
||||
return registry.createType('ContractMetadataV1', objectSpread({}, v0, {
|
||||
types: convertSiV0toV1(registry, v0.types)
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Text } from '@polkadot/types';
|
||||
import type { ContractMetadataV1, ContractMetadataV2 } from '@polkadot/types/interfaces';
|
||||
import type { InterfaceTypes, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
type WithArgs = keyof typeof ARG_TYPES;
|
||||
|
||||
interface NamedEntry {
|
||||
name: Text | Text[];
|
||||
}
|
||||
|
||||
interface ArgsEntry <T extends WithArgs> extends NamedEntry {
|
||||
args: InterfaceTypes[`${T}V0`]['args'][0][];
|
||||
}
|
||||
|
||||
const ARG_TYPES = {
|
||||
ContractConstructorSpec: 'ContractMessageParamSpecV2',
|
||||
ContractEventSpec: 'ContractEventParamSpecV2',
|
||||
ContractMessageSpec: 'ContractMessageParamSpecV2'
|
||||
};
|
||||
|
||||
function v1ToV2Label (entry: NamedEntry): { label: Text } {
|
||||
return objectSpread({}, entry, {
|
||||
label: Array.isArray(entry.name)
|
||||
? entry.name[0]
|
||||
: entry.name
|
||||
});
|
||||
}
|
||||
|
||||
function v1ToV2Labels <T extends WithArgs> (registry: Registry, outType: T, all: ArgsEntry<T>[]): unknown[] {
|
||||
return all.map((e) =>
|
||||
registry.createType(`${outType}V2`, objectSpread(v1ToV2Label(e), {
|
||||
args: e.args.map((a) =>
|
||||
registry.createType(ARG_TYPES[outType], v1ToV2Label(a))
|
||||
)
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export function v1ToV2 (registry: Registry, v1: ContractMetadataV1): ContractMetadataV2 {
|
||||
return registry.createType('ContractMetadataV2', objectSpread({}, v1, {
|
||||
spec: objectSpread({}, v1.spec, {
|
||||
constructors: v1ToV2Labels(registry, 'ContractConstructorSpec', v1.spec.constructors),
|
||||
events: v1ToV2Labels(registry, 'ContractEventSpec', v1.spec.events),
|
||||
messages: v1ToV2Labels(registry, 'ContractMessageSpec', v1.spec.messages)
|
||||
})
|
||||
}));
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { AnyJson, Registry } from '@polkadot/types/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { assert, isFunction } from '@polkadot/util';
|
||||
@@ -16,14 +16,15 @@ export abstract class Base<ApiType extends ApiTypes> {
|
||||
|
||||
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||
this.abi = abi instanceof Abi
|
||||
? abi
|
||||
: new Abi(abi, api.registry.getChainProperties());
|
||||
this.api = api;
|
||||
this._decorateMethod = decorateMethod;
|
||||
|
||||
assert(!!(api && api.isConnected && api.tx && api.tx.contracts && Object.keys(api.tx.contracts).length), 'Your API has not been initialized correctly and it not decorated with the runtime interfaces for contracts as retrieved from the on-chain runtime');
|
||||
assert(!!(api && api.isConnected && api.tx), 'Your API has not been initialized correctly and is not connected to a chain');
|
||||
assert(!!(api.tx.contracts && Object.keys(api.tx.contracts).length), 'You need to connect to a chain with a runtime that supports contracts');
|
||||
assert(isFunction(api.tx.contracts.instantiateWithCode), 'You need to connect to a chain with a runtime with a V3 contracts module. The runtime does not expose api.tx.contracts.instantiateWithCode');
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, BlueprintOptions } from '../types';
|
||||
import type { MapConstructorExec } from './types';
|
||||
|
||||
@@ -18,6 +18,10 @@ import { Base } from './Base';
|
||||
import { Contract } from './Contract';
|
||||
import { createBluePrintTx, encodeSalt } from './util';
|
||||
|
||||
export interface BlueprintConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array): Blueprint<ApiType>;
|
||||
}
|
||||
|
||||
export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
public readonly contract?: Contract<ApiType>;
|
||||
|
||||
@@ -36,7 +40,7 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapConstructorExec<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.codeHash = this.registry.createType('Hash', codeHash);
|
||||
@@ -68,3 +72,13 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function extendBlueprint <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): BlueprintConstructor<ApiType> {
|
||||
return class extends Blueprint<ApiType> {
|
||||
static __BlueprintType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) {
|
||||
super(api, abi, codeHash, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { decorateMethodPromise } from '@polkadot/api';
|
||||
import { toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import v0contractFlipper from '../../test/contracts/ink/v0/flipper.contract.json';
|
||||
import v0abiFlipper from '../../test/contracts/ink/v0/flipper.json';
|
||||
@@ -19,19 +17,19 @@ const v0wasmFlipper = fs.readFileSync(path.join(__dirname, '../../test/contracts
|
||||
describe('Code', (): void => {
|
||||
it('can construct with an individual ABI/WASM combo', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v0abiFlipper as AnyJson, v0wasmFlipper, decorateMethodPromise)
|
||||
() => new Code(mockApi, v0abiFlipper as Record<string, unknown>, v0wasmFlipper, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('can construct with an .contract ABI (v0)', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v0contractFlipper as AnyJson, null, decorateMethodPromise)
|
||||
() => new Code(mockApi, v0contractFlipper as Record<string, unknown>, null, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it.only('can construct with an .contract ABI (v1)', (): void => {
|
||||
expect(
|
||||
() => new Code(mockApi, v1contractFlipper as AnyJson, null, decorateMethodPromise)
|
||||
() => new Code(mockApi, v1contractFlipper as Record<string, unknown>, null, toPromiseMethod)
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { EventRecord } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, BlueprintOptions } from '../types';
|
||||
import type { MapConstructorExec } from './types';
|
||||
|
||||
@@ -19,6 +19,10 @@ import { Blueprint } from './Blueprint';
|
||||
import { Contract } from './Contract';
|
||||
import { createBluePrintTx, encodeSalt } from './util';
|
||||
|
||||
export interface CodeConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined): Code<ApiType>;
|
||||
}
|
||||
|
||||
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
public readonly blueprint?: Blueprint<ApiType>;
|
||||
public readonly contract?: Contract<ApiType>;
|
||||
@@ -36,7 +40,7 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapConstructorExec<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.code = isWasm(this.abi.info.source.wasm)
|
||||
@@ -78,3 +82,13 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function extendCode <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType> {
|
||||
return class extends Code<ApiType> {
|
||||
static __CodeType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { Bytes } from '@polkadot/types';
|
||||
import type { AccountId, EventRecord, Weight } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types';
|
||||
import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types';
|
||||
|
||||
@@ -19,6 +19,10 @@ import { Abi } from '../Abi';
|
||||
import { applyOnEvent, extractOptions, isOptions } from '../util';
|
||||
import { Base } from './Base';
|
||||
|
||||
export interface ContractConstructor<ApiType extends ApiTypes> {
|
||||
new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId): Contract<ApiType>;
|
||||
}
|
||||
|
||||
// As per Rust, 5 * GAS_PER_SEC
|
||||
const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
|
||||
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
|
||||
@@ -59,7 +63,7 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
|
||||
readonly #tx: MapMessageTx<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.address = this.registry.createType('AccountId', address);
|
||||
@@ -161,3 +165,13 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function extendContract <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType> {
|
||||
return class extends Contract<ApiType> {
|
||||
static __ContractType = type;
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethod);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint, BlueprintSubmittableResult } from './Blueprint';
|
||||
export { Code, CodeSubmittableResult } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
export { Blueprint, BlueprintSubmittableResult, extendBlueprint } from './Blueprint';
|
||||
export { Code, CodeSubmittableResult, extendCode } from './Code';
|
||||
export { Contract, extendContract } from './Contract';
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs';
|
||||
|
||||
@@ -12,7 +10,7 @@ import abiIncrementer from '../test/contracts/ink/incrementer.json';
|
||||
import { BlueprintPromise, ContractPromise } from '.';
|
||||
|
||||
async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
const blueprint = new BlueprintPromise(api, abiIncrementer as AnyJson, '0x1234');
|
||||
const blueprint = new BlueprintPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
||||
|
||||
// new style
|
||||
await blueprint.tx.new({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
|
||||
@@ -23,7 +21,7 @@ async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMap): Promise<
|
||||
}
|
||||
|
||||
async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
const contract = new ContractPromise(api, abiIncrementer as AnyJson, '0x1234');
|
||||
const contract = new ContractPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
||||
|
||||
// queries
|
||||
await contract.query.get(pairs.alice.address, {});
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-contract', version: '6.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-contract', version: '6.12.1' };
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Blueprint as BaseBlueprint } from '../base';
|
||||
|
||||
export class Blueprint extends BaseBlueprint<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, decorateMethodPromise);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { decorateMethodPromise } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Code as BaseCode } from '../base';
|
||||
|
||||
export class Code extends BaseCode<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, decorateMethodPromise);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Contract as BaseContract } from '../base';
|
||||
|
||||
export class Contract extends BaseContract<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethodPromise);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint } from './Blueprint';
|
||||
export { Code } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
import { toPromiseMethod } from '@polkadot/api';
|
||||
|
||||
import { extendBlueprint, extendCode, extendContract } from '../base';
|
||||
|
||||
export const Blueprint = extendBlueprint<'promise'>('promise', toPromiseMethod);
|
||||
export const Code = extendCode<'promise'>('promise', toPromiseMethod);
|
||||
export const Contract = extendContract<'promise'>('promise', toPromiseMethod);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiRx, decorateMethodRx } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Blueprint as BaseBlueprint } from '../base';
|
||||
|
||||
export class Blueprint extends BaseBlueprint<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, decorateMethodRx);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiRx } from '@polkadot/api';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { decorateMethodRx } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Code as BaseCode } from '../base';
|
||||
|
||||
export class Code extends BaseCode<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
||||
super(api, abi, wasm, decorateMethodRx);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import { ApiRx, decorateMethodRx } from '@polkadot/api';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
import { Contract as BaseContract } from '../base';
|
||||
|
||||
export class Contract extends BaseContract<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethodRx);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Blueprint } from './Blueprint';
|
||||
export { Code } from './Code';
|
||||
export { Contract } from './Contract';
|
||||
import { toRxMethod } from '@polkadot/api';
|
||||
|
||||
import { extendBlueprint, extendCode, extendContract } from '../base';
|
||||
|
||||
export const Blueprint = extendBlueprint<'rxjs'>('rxjs', toRxMethod);
|
||||
export const Code = extendCode<'rxjs'>('rxjs', toRxMethod);
|
||||
export const Contract = extendContract<'rxjs'>('rxjs', toRxMethod);
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
[
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 0,
|
||||
"type": "u128",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 1,
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
"sub": [
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "Key",
|
||||
"name": "offsetKey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
},
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 3,
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "[u8;32]"
|
||||
},
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 6,
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
"sub": [
|
||||
{
|
||||
"info": "VecFixed",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "InkPrimitivesKey",
|
||||
"type": "[u8;32]",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 4,
|
||||
"type": "u8",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
"typeName": "Key",
|
||||
"name": "offsetKey"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Tuple",
|
||||
"lookupIndex": 7,
|
||||
"type": "(AccountId,AccountId)",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"sub": [
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
},
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Result",
|
||||
"lookupIndex": 8,
|
||||
"type": "Result<Null, Erc20Error>",
|
||||
"docs": [],
|
||||
"namespace": "Result",
|
||||
"sub": [
|
||||
{
|
||||
"name": "Ok",
|
||||
"info": "Null",
|
||||
"lookupIndex": 9,
|
||||
"type": "Null",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"name": "Error",
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "Erc20Error",
|
||||
"type": "Lookup10"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Null",
|
||||
"lookupIndex": 9,
|
||||
"type": "Null",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
},
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "Erc20Error",
|
||||
"type": "{\"_enum\":[\"InsufficientBalance\",\"InsufficientAllowance\"]}",
|
||||
"docs": [],
|
||||
"namespace": "erc20::erc20::Error",
|
||||
"sub": [
|
||||
{
|
||||
"info": "Null",
|
||||
"type": "Null",
|
||||
"index": 0,
|
||||
"name": "InsufficientBalance"
|
||||
},
|
||||
{
|
||||
"info": "Null",
|
||||
"type": "Null",
|
||||
"index": 1,
|
||||
"name": "InsufficientAllowance"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"info": "Option",
|
||||
"lookupIndex": 11,
|
||||
"type": "Option<AccountId>",
|
||||
"docs": [],
|
||||
"namespace": "Option",
|
||||
"sub": {
|
||||
"info": "Plain",
|
||||
"lookupIndex": 2,
|
||||
"type": "AccountId",
|
||||
"docs": [],
|
||||
"namespace": "ink_env::types::AccountId",
|
||||
"lookupNameRoot": "InkEnvAccountId"
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
[
|
||||
{
|
||||
"info": "Plain",
|
||||
"lookupIndex": 0,
|
||||
"type": "bool",
|
||||
"docs": [],
|
||||
"namespace": ""
|
||||
}
|
||||
]
|
||||
@@ -18,6 +18,7 @@
|
||||
"lookupIndex": 1,
|
||||
"lookupName": "RecursiveMyEnum",
|
||||
"type": "Lookup1",
|
||||
"typeName": "MyEnum",
|
||||
"index": 1,
|
||||
"name": "B"
|
||||
}
|
||||
|
||||
@@ -5,17 +5,12 @@ import ink from './ink';
|
||||
import solang from './solang';
|
||||
import user from './user';
|
||||
|
||||
const all: Record<string, any> = {};
|
||||
const all: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
function addExport (type: string, abis: Record<string, any>): void {
|
||||
Object.keys(abis).forEach((key): void => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
all[`${type}_${key}`] = abis[key];
|
||||
});
|
||||
}
|
||||
|
||||
addExport('ink', ink);
|
||||
addExport('solang', solang);
|
||||
addExport('user', user);
|
||||
Object.entries({ ink, solang, user }).forEach(([type, abis]) =>
|
||||
Object.entries(abis).forEach(([name, abi]): void => {
|
||||
all[`${type}_${name}`] = abi;
|
||||
})
|
||||
);
|
||||
|
||||
export default all;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
import * as v1 from './v1';
|
||||
import * as v2 from './v2';
|
||||
|
||||
const exp = createVersionedExport('v0', v0, {});
|
||||
|
||||
export default createVersionedExport('v1', v1, exp);
|
||||
export default createVersionedExport({ v0, v1, v2 });
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as erc20 } from './erc20.contract.json';
|
||||
export { default as flipper } from './flipper.contract.json';
|
||||
@@ -4,4 +4,4 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
|
||||
export default createVersionedExport('v0', v0, {});
|
||||
export default createVersionedExport({ v0 });
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
import { createVersionedExport } from '../util';
|
||||
import * as v0 from './v0';
|
||||
|
||||
export default createVersionedExport('v0', v0, {});
|
||||
export default createVersionedExport({ v0 });
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function createVersionedExport (version: string, orig: Record<string, unknown>, exp: Record<string, unknown>): Record<string, unknown> {
|
||||
Object.entries(orig).forEach(([name, json]): void => {
|
||||
exp[`${version}_${name}`] = json;
|
||||
});
|
||||
export function createVersionedExport (versioned: Record<string, Record<string, unknown>>): Record<string, Record<string, unknown>> {
|
||||
const result: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
return exp;
|
||||
Object.entries(versioned).forEach(([version, contracts]) =>
|
||||
Object.entries(contracts).forEach(([name, contract]): void => {
|
||||
result[`${version}_${name}`] = contract as Record<string, unknown>;
|
||||
})
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,34 +1,38 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "6.4.1",
|
||||
"type": "module",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"contributors": [],
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"license": "Apache-2.0",
|
||||
"maintainers": [],
|
||||
"name": "@polkadot/api-derive",
|
||||
"repository": {
|
||||
"directory": "packages/api-derive",
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/api.git"
|
||||
},
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
"license": "Apache-2.0",
|
||||
"repository": "github:polkadot-js/api",
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"type": "module",
|
||||
"version": "6.12.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@polkadot/api": "6.4.1",
|
||||
"@polkadot/rpc-core": "6.4.1",
|
||||
"@polkadot/types": "6.4.1",
|
||||
"@polkadot/util": "^7.5.1",
|
||||
"@polkadot/util-crypto": "^7.5.1",
|
||||
"@babel/runtime": "^7.16.3",
|
||||
"@polkadot/api": "6.12.1",
|
||||
"@polkadot/rpc-core": "6.12.1",
|
||||
"@polkadot/types": "6.12.1",
|
||||
"@polkadot/util": "^8.1.2",
|
||||
"@polkadot/util-crypto": "^8.1.2",
|
||||
"rxjs": "^7.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.5.1",
|
||||
"@polkadot/rpc-provider": "6.4.1"
|
||||
"@polkadot/keyring": "^8.1.2",
|
||||
"@polkadot/rpc-provider": "6.12.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,28 +12,25 @@ import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | string | null | undefined): Observable<AccountId> {
|
||||
const decoded = isU8a(address)
|
||||
? address
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length > 8) {
|
||||
return of(api.registry.createType('AccountId', decoded));
|
||||
}
|
||||
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||
map((accountId) => assertReturn(accountId, 'Unable to retrieve accountId'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name accountId
|
||||
* @param {(Address | AccountId | AccountIndex | string | null)} address - An accounts address in various formats.
|
||||
* @description An [[AccountId]]
|
||||
*/
|
||||
export function accountId (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> =>
|
||||
retrieve(api, address));
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => {
|
||||
const decoded = isU8a(address)
|
||||
? address
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length > 8) {
|
||||
return of(api.registry.createType('AccountId', decoded));
|
||||
}
|
||||
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||
map((a) => assertReturn(a, 'Unable to retrieve accountId'))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,15 +40,11 @@ function parseFlags (address: AccountId | Address | string | null | undefined, [
|
||||
*/
|
||||
export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
|
||||
const councilSection = api.query.phragmenElection
|
||||
? 'phragmenElection'
|
||||
: api.query.electionsPhragmen
|
||||
? 'electionsPhragmen'
|
||||
: 'elections';
|
||||
const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
|
||||
|
||||
return combineLatest([
|
||||
address && api.query[councilSection]?.members
|
||||
? api.query[councilSection].members<Vec<ITuple<[AccountId, Balance]>>>()
|
||||
address && elections?.members
|
||||
? elections.members<Vec<ITuple<[AccountId, Balance]>>>()
|
||||
: of(undefined),
|
||||
address && api.query.council?.members
|
||||
? api.query.council.members()
|
||||
@@ -63,7 +59,7 @@ export function flags (instanceId: string, api: ApiInterfaceRx): (address?: Acco
|
||||
? api.query.sudo.key()
|
||||
: of(undefined)
|
||||
]).pipe(
|
||||
map((result) => parseFlags(address, result))
|
||||
map((r) => parseFlags(address, r))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,31 +13,6 @@ import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | Uint8Array | string | null | undefined): Observable<AccountIdAndIndex> {
|
||||
try {
|
||||
// yes, this can fail, don't care too much, catch will catch it
|
||||
const decoded = isU8a(address)
|
||||
? address
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length > 8) {
|
||||
const accountId = api.registry.createType('AccountId', decoded);
|
||||
|
||||
return api.derive.accounts.idToIndex(accountId).pipe(
|
||||
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
} catch (error) {
|
||||
return of([undefined, undefined]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name idAndIndex
|
||||
* @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address - An accounts address in various formats.
|
||||
@@ -52,6 +27,28 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
||||
* ```
|
||||
*/
|
||||
export function idAndIndex (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> {
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> =>
|
||||
retrieve(api, address));
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> => {
|
||||
try {
|
||||
// yes, this can fail, don't care too much, catch will catch it
|
||||
const decoded = isU8a(address)
|
||||
? address
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length > 8) {
|
||||
const accountId = api.registry.createType('AccountId', decoded);
|
||||
|
||||
return api.derive.accounts.idToIndex(accountId).pipe(
|
||||
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
} catch (error) {
|
||||
return of([undefined, undefined]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { isHex, u8aToString } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
type IdentityInfoAdditional = PalletIdentityIdentityInfo['additional'][0];
|
||||
|
||||
@@ -104,13 +104,10 @@ export function identity (instanceId: string, api: ApiInterfaceRx): (accountId?:
|
||||
);
|
||||
}
|
||||
|
||||
export function hasIdentity (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId | Uint8Array | string) => Observable<DeriveHasIdentity> {
|
||||
return memo(instanceId, (accountId: AccountId | Uint8Array | string): Observable<DeriveHasIdentity> =>
|
||||
api.derive.accounts.hasIdentityMulti([accountId]).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const hasIdentity = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: AccountId | Uint8Array | string) =>
|
||||
api.derive.accounts.hasIdentityMulti([accountId])
|
||||
);
|
||||
|
||||
export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
|
||||
return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
|
||||
|
||||
@@ -165,9 +165,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstanc
|
||||
|
||||
return [
|
||||
vesting
|
||||
? Array.isArray(vesting)
|
||||
? vesting
|
||||
: [vesting]
|
||||
? Array.isArray(vesting) ? vesting : [vesting]
|
||||
: null,
|
||||
lockEmpty.map((e) => e ? api.registry.createType<Vec<PalletBalancesBalanceLock>>('Vec<BalanceLock>') : locks[++offset])
|
||||
];
|
||||
|
||||
@@ -42,14 +42,12 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
|
||||
? api.query.council.proposalCount<ProposalIndex>()
|
||||
: of(0)
|
||||
]).pipe(
|
||||
switchMap(() =>
|
||||
combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
switchMap(() => combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
])),
|
||||
switchMap(([keys, proposals]): Observable<Result> => {
|
||||
const ids = keys.map(({ args: [id] }) => id);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AnyFunction } from '@polkadot/types/types';
|
||||
|
||||
import { lazyDeriveSection } from './util/lazy';
|
||||
import * as accounts from './accounts';
|
||||
import * as balances from './balances';
|
||||
import * as bounties from './bounties';
|
||||
@@ -29,18 +30,21 @@ export * from './type';
|
||||
|
||||
interface Avail {
|
||||
instances: string[];
|
||||
methods: string[];
|
||||
withDetect?: boolean;
|
||||
}
|
||||
|
||||
export { lazyDeriveSection };
|
||||
|
||||
export const derive = { accounts, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
|
||||
|
||||
type DeriveSection<Section> = {
|
||||
[Method in keyof Section]: Section[Method] extends AnyFunction
|
||||
? ReturnType<Section[Method]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument
|
||||
[M in keyof Section]: Section[M] extends AnyFunction
|
||||
? ReturnType<Section[M]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument
|
||||
: never;
|
||||
};
|
||||
type DeriveAllSections<AllSections> = {
|
||||
[Section in keyof AllSections]: DeriveSection<AllSections[Section]>
|
||||
[S in keyof AllSections]: DeriveSection<AllSections[S]>
|
||||
};
|
||||
|
||||
type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable<any>;
|
||||
@@ -51,64 +55,110 @@ export type ExactDerive = DeriveAllSections<typeof derive>;
|
||||
|
||||
// Enable derive only if some of these modules are available
|
||||
const checks: Record<string, Avail> = {
|
||||
contracts: { instances: ['contracts'] },
|
||||
council: { instances: ['council'], withDetect: true },
|
||||
crowdloan: { instances: ['crowdloan'] },
|
||||
democracy: { instances: ['democracy'] },
|
||||
elections: { instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'], withDetect: true },
|
||||
imOnline: { instances: ['imOnline'] },
|
||||
membership: { instances: ['membership'] },
|
||||
parachains: { instances: ['parachains', 'registrar'] },
|
||||
session: { instances: ['session'] },
|
||||
society: { instances: ['society'] },
|
||||
staking: { instances: ['staking'] },
|
||||
technicalCommittee: { instances: ['technicalCommittee'], withDetect: true },
|
||||
treasury: { instances: ['treasury'] }
|
||||
contracts: {
|
||||
instances: ['contracts'],
|
||||
methods: []
|
||||
},
|
||||
council: {
|
||||
instances: ['council'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
crowdloan: {
|
||||
instances: ['crowdloan'],
|
||||
methods: []
|
||||
},
|
||||
democracy: {
|
||||
instances: ['democracy'],
|
||||
methods: []
|
||||
},
|
||||
elections: {
|
||||
instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
imOnline: {
|
||||
instances: ['imOnline'],
|
||||
methods: []
|
||||
},
|
||||
membership: {
|
||||
instances: ['membership'],
|
||||
methods: []
|
||||
},
|
||||
parachains: {
|
||||
instances: ['parachains', 'registrar'],
|
||||
methods: []
|
||||
},
|
||||
session: {
|
||||
instances: ['session'],
|
||||
methods: []
|
||||
},
|
||||
society: {
|
||||
instances: ['society'],
|
||||
methods: []
|
||||
},
|
||||
staking: {
|
||||
instances: ['staking'],
|
||||
methods: ['erasRewardPoints']
|
||||
},
|
||||
technicalCommittee: {
|
||||
instances: ['technicalCommittee'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
treasury: {
|
||||
instances: ['treasury'],
|
||||
methods: []
|
||||
}
|
||||
};
|
||||
|
||||
function getModuleInstances (api: ApiInterfaceRx, specName: string, moduleName: string): string[] {
|
||||
return api.registry.getModuleInstances(specName, moduleName) || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object that will inject `api` into all the functions inside
|
||||
* `allSections`, and keep the object architecture of `allSections`.
|
||||
*/
|
||||
/** @internal */
|
||||
function injectFunctions<AllSections> (instanceId: string, api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections<AllSections> {
|
||||
const queryKeys = Object.keys(api.query);
|
||||
function injectFunctions (instanceId: string, api: ApiInterfaceRx, derives: DeriveCustom): ExactDerive {
|
||||
const result: Record<string, Record<string, AnyFunction>> = {};
|
||||
const names = Object.keys(derives);
|
||||
const keys = Object.keys(api.query);
|
||||
const specName = api.runtimeVersion.specName.toString();
|
||||
|
||||
return Object
|
||||
.keys(allSections)
|
||||
.filter((sectionName) =>
|
||||
!checks[sectionName] ||
|
||||
checks[sectionName].instances.some((q) => queryKeys.includes(q)) ||
|
||||
(
|
||||
checks[sectionName].withDetect &&
|
||||
checks[sectionName].instances.some((q) =>
|
||||
(api.registry.getModuleInstances(specName, q) || []).some((q) => queryKeys.includes(q))
|
||||
)
|
||||
)
|
||||
const filterKeys = (q: string) => keys.includes(q);
|
||||
const filterInstances = (q: string) => getModuleInstances(api, specName, q).some(filterKeys);
|
||||
const filterMethods = (all: string[]) => (m: string) => all.some((q) => keys.includes(q) && api.query[q][m]);
|
||||
const getKeys = (s: string) => Object.keys(derives[s]);
|
||||
const creator = (s: string, m: string) => derives[s][m](instanceId, api);
|
||||
const isIncluded = (c: string) => (!checks[c] || (
|
||||
(checks[c].instances.some(filterKeys) && (
|
||||
!checks[c].methods.length ||
|
||||
checks[c].methods.every(filterMethods(checks[c].instances))
|
||||
)) ||
|
||||
(
|
||||
checks[c].withDetect &&
|
||||
checks[c].instances.some(filterInstances)
|
||||
)
|
||||
.reduce((derives, sectionName): DeriveAllSections<AllSections> => {
|
||||
const section = allSections[sectionName as keyof AllSections];
|
||||
));
|
||||
|
||||
derives[sectionName as keyof AllSections] = Object
|
||||
.entries(section)
|
||||
.reduce((methods, [methodName, creator]): DeriveSection<typeof section> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
|
||||
methods[methodName as keyof typeof section] = creator(instanceId, api);
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
|
||||
return methods;
|
||||
}, {} as DeriveSection<typeof section>);
|
||||
isIncluded(name) &&
|
||||
lazyDeriveSection(result, name, getKeys, creator);
|
||||
}
|
||||
|
||||
return derives;
|
||||
}, {} as DeriveAllSections<AllSections>);
|
||||
return result as ExactDerive;
|
||||
}
|
||||
|
||||
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
|
||||
// For now we just drop the custom derive typings
|
||||
/** @internal */
|
||||
export function decorateDerive (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
|
||||
export function getAvailableDerives (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
|
||||
return {
|
||||
...injectFunctions(instanceId, api, derive),
|
||||
...injectFunctions(instanceId, api, derive as DeriveCustom),
|
||||
...injectFunctions(instanceId, api, custom)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { unwrapBlockNumber } from './util';
|
||||
|
||||
/**
|
||||
* @name bestNumber
|
||||
@@ -21,9 +17,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumber (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.chain.subscribeNewHeads().pipe(
|
||||
map((header) => header.number.unwrap())
|
||||
));
|
||||
}
|
||||
export const bestNumber = unwrapBlockNumber(
|
||||
(api: ApiInterfaceRx) =>
|
||||
api.derive.chain.subscribeNewHeads()
|
||||
);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { unwrapBlockNumber } from './util';
|
||||
|
||||
/**
|
||||
* @name bestNumberFinalized
|
||||
@@ -22,9 +18,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumberFinalized (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
||||
map((header) => header.number.unwrap())
|
||||
));
|
||||
}
|
||||
export const bestNumberFinalized = unwrapBlockNumber(
|
||||
(api: ApiInterfaceRx) =>
|
||||
api.rpc.chain.subscribeFinalizedHeads()
|
||||
);
|
||||
|
||||
@@ -25,17 +25,20 @@ import { memo } from '../util';
|
||||
*/
|
||||
export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
|
||||
return memo(instanceId, (blockHash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
queryAt.system.events(),
|
||||
queryAt.session
|
||||
? queryAt.session.validators()
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
map(([signedBlock, events, validators]) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
queryAt.system.events(),
|
||||
queryAt.session
|
||||
? queryAt.session.validators()
|
||||
: of([])
|
||||
])
|
||||
)
|
||||
)
|
||||
]).pipe(
|
||||
map(([signedBlock, [events, validators]]) =>
|
||||
createSignedBlockExtended(api.registry, signedBlock, events, validators)
|
||||
),
|
||||
catchError((): Observable<undefined> =>
|
||||
|
||||
@@ -25,17 +25,18 @@ import { memo } from '../util';
|
||||
* console.log(`block #${number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
return memo(instanceId, (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
api.queryAt(hash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(hash),
|
||||
export function getHeader (instanceId: string, api: ApiInterfaceRx): (blockHash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
return memo(instanceId, (blockHash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(blockHash),
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
queryAt.session
|
||||
? queryAt.session.validators()
|
||||
: of([] as AccountId[])
|
||||
])
|
||||
),
|
||||
)
|
||||
)
|
||||
]).pipe(
|
||||
map(([header, validators]) =>
|
||||
createHeaderExtended(header.registry, header, validators)
|
||||
),
|
||||
|
||||
@@ -21,15 +21,15 @@ export function subscribeNewBlocks (instanceId: string, api: ApiInterfaceRx): ()
|
||||
const blockHash = header.createdAtHash || header.hash;
|
||||
|
||||
// we get the block first, setting up the registry
|
||||
return api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
of(header),
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
return combineLatest([
|
||||
of(header),
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
queryAt.system.events()
|
||||
])
|
||||
)
|
||||
)
|
||||
);
|
||||
]);
|
||||
}),
|
||||
map(([header, block, events]) =>
|
||||
createSignedBlockExtended(block.registry, block, events, header.validators)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Compact } from '@polkadot/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
// re-export these - since these needs to be resolvable from api-derive, i.e. without this
|
||||
// we would emit code with ../<somewhere>/src embedded in the *.d.ts files
|
||||
export type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
export type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
export function unwrapBlockNumber <T extends { number: Compact<BlockNumber> }> (fn: (api: ApiInterfaceRx) => Observable<T>): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
memo(instanceId, () => fn(api).pipe(
|
||||
map((r) => r.number.unwrap())
|
||||
));
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
export function getInstance (api: ApiInterfaceRx, section: string): string {
|
||||
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
|
||||
|
||||
return instances && instances.length
|
||||
? instances[0]
|
||||
: section;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
export function getInstance (api: ApiInterfaceRx, section: string): string {
|
||||
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
|
||||
|
||||
return instances && instances.length
|
||||
? instances[0]
|
||||
: section;
|
||||
}
|
||||
|
||||
export function withSection <T, F extends (...args: any[]) => Observable<T>> (_section: Collective, fn: (section: string, api: ApiInterfaceRx, instanceId: string) => F): (instanceId: string, api: ApiInterfaceRx) => F {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
memo(instanceId, fn(getInstance(api, _section), api, instanceId)) as unknown as F;
|
||||
}
|
||||
|
||||
export function callMethod <T> (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: ApiInterfaceRx) => () => Observable<T> {
|
||||
return (_section: Collective) =>
|
||||
withSection(_section, (section, api) =>
|
||||
(): Observable<T> =>
|
||||
isFunction(api.query[section]?.[method])
|
||||
? api.query[section as 'council'][method]() as unknown as Observable<T>
|
||||
: of(empty)
|
||||
);
|
||||
}
|
||||
@@ -1,24 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { of } from 'rxjs';
|
||||
import { callMethod } from './helpers';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { getInstance } from './getInstance';
|
||||
|
||||
export function members (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<AccountId[]> {
|
||||
const section = getInstance(api, _section);
|
||||
|
||||
return memo(instanceId, (): Observable<AccountId[]> =>
|
||||
isFunction(api.query[section]?.members)
|
||||
? api.query[section as 'council'].members()
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
export const members = callMethod<AccountId[]>('members', []);
|
||||
|
||||
@@ -5,24 +5,27 @@ import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { getInstance } from './getInstance';
|
||||
import { withSection } from './helpers';
|
||||
|
||||
export function prime (instanceId: string, api: ApiInterfaceRx, _section: string): () => Observable<AccountId | null> {
|
||||
const section = getInstance(api, _section);
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
return memo(instanceId, (): Observable<AccountId | null> =>
|
||||
isFunction(api.query[section as 'council']?.prime)
|
||||
? api.query[section as 'council'].prime<Option<AccountId>>().pipe(
|
||||
map((optPrime): AccountId | null =>
|
||||
optPrime.unwrapOr(null)
|
||||
export function prime (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<AccountId | null> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<AccountId | null> =>
|
||||
isFunction(api.query[section as 'council']?.prime)
|
||||
? api.query[section as 'council'].prime<Option<AccountId>>().pipe(
|
||||
map((optPrime): AccountId | null =>
|
||||
optPrime.unwrapOr(null)
|
||||
)
|
||||
)
|
||||
)
|
||||
: of(null)
|
||||
: of(null)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,18 +12,23 @@ import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { getInstance } from './getInstance';
|
||||
import { firstObservable } from '../util';
|
||||
import { callMethod, withSection } from './helpers';
|
||||
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
export type { Option, u32 } from '@polkadot/types';
|
||||
export type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
|
||||
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
|
||||
|
||||
function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
|
||||
return proposals
|
||||
.map((proposalOpt, index): DeriveCollectiveProposal | null =>
|
||||
proposalOpt && proposalOpt.isSome
|
||||
.map((o, index): DeriveCollectiveProposal | null =>
|
||||
o && o.isSome
|
||||
? {
|
||||
hash: api.registry.createType('Hash', hashes[index]),
|
||||
proposal: proposalOpt.unwrap(),
|
||||
proposal: o.unwrap(),
|
||||
votes: votes[index].unwrapOr(null)
|
||||
}
|
||||
: null
|
||||
@@ -31,77 +36,50 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive
|
||||
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
|
||||
}
|
||||
|
||||
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: string): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, (hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> =>
|
||||
(isFunction(api.query[section]?.proposals) && hashes.length
|
||||
? combineLatest([
|
||||
of(hashes),
|
||||
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
|
||||
// however we have had cases on Edgeware where the indices have moved around after an
|
||||
// upgrade, which results in invalid on-chain data
|
||||
combineLatest(hashes.map((hash) =>
|
||||
api.query[section].proposalOf<Option<Proposal>>(hash).pipe(
|
||||
catchError(() => of(null))
|
||||
)
|
||||
)),
|
||||
api.query[section].voting.multi<Option<Votes>>(hashes)
|
||||
])
|
||||
: of<Result>([[], [], []])
|
||||
).pipe(
|
||||
map((result) => parse(api, result))
|
||||
)
|
||||
function _proposalsFrom (section: string, api: ApiInterfaceRx, hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> {
|
||||
return (isFunction(api.query[section]?.proposals) && hashes.length
|
||||
? combineLatest([
|
||||
of(hashes),
|
||||
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
|
||||
// however we have had cases on Edgeware where the indices have moved around after an
|
||||
// upgrade, which results in invalid on-chain data
|
||||
combineLatest(hashes.map((h) =>
|
||||
api.query[section].proposalOf<Option<Proposal>>(h).pipe(
|
||||
catchError(() => of(null))
|
||||
)
|
||||
)),
|
||||
api.query[section].voting.multi<Option<Votes>>(hashes)
|
||||
])
|
||||
: of<Result>([[], [], []])
|
||||
).pipe(
|
||||
map((r) => parse(api, r))
|
||||
);
|
||||
}
|
||||
|
||||
export function hasProposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<boolean> {
|
||||
const section = getInstance(api, _section);
|
||||
|
||||
return memo(instanceId, (): Observable<boolean> =>
|
||||
of(isFunction(api.query[section]?.proposals))
|
||||
export function hasProposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<boolean> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<boolean> =>
|
||||
of(isFunction(api.query[section]?.proposals))
|
||||
);
|
||||
}
|
||||
|
||||
export function proposalCount (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<u32 | null> {
|
||||
const section = getInstance(api, _section);
|
||||
|
||||
return memo(instanceId, (): Observable<u32 | null> =>
|
||||
isFunction(api.query[section].proposalCount)
|
||||
? api.query[section as 'council'].proposalCount()
|
||||
: of(null)
|
||||
);
|
||||
}
|
||||
|
||||
export function proposalHashes (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<Hash[]> {
|
||||
const section = getInstance(api, _section);
|
||||
|
||||
return memo(instanceId, (): Observable<Hash[]> =>
|
||||
isFunction(api.query[section]?.proposals)
|
||||
? api.query[section as 'council'].proposals()
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<DeriveCollectiveProposal[]> {
|
||||
const section = getInstance(api, _section);
|
||||
const proposalsFrom = _proposalsFrom(instanceId, api, section);
|
||||
const getHashes = proposalHashes(instanceId, api, _section);
|
||||
|
||||
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
|
||||
getHashes().pipe(
|
||||
switchMap(proposalsFrom)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx, _section: Collective): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
const section = getInstance(api, _section);
|
||||
const proposalsFrom = _proposalsFrom(instanceId, api, section);
|
||||
|
||||
return memo(instanceId, (hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
|
||||
isFunction(api.query[section]?.proposals)
|
||||
? proposalsFrom([hash]).pipe(
|
||||
map(([proposal]) => proposal)
|
||||
export function proposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<DeriveCollectiveProposal[]> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<DeriveCollectiveProposal[]> =>
|
||||
api.derive[section as 'council'].proposalHashes().pipe(
|
||||
switchMap((all) => _proposalsFrom(section, api, all))
|
||||
)
|
||||
: of(null)
|
||||
);
|
||||
}
|
||||
|
||||
export function proposal (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
|
||||
isFunction(api.query[section]?.proposals)
|
||||
? firstObservable(_proposalsFrom(section, api, [hash]))
|
||||
: of(null)
|
||||
);
|
||||
}
|
||||
|
||||
export const proposalCount = callMethod<u32 | null>('proposalCount', null);
|
||||
export const proposalHashes = callMethod<Hash[]>('proposals', []);
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './members';
|
||||
export * from './prime';
|
||||
export * from './proposals';
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
|
||||
|
||||
export * from './votes';
|
||||
export * from './votesOf';
|
||||
|
||||
export const members = collectiveMembers('council');
|
||||
|
||||
export const hasProposals = collectiveHasProposals('council');
|
||||
export const proposal = collectiveProposal('council');
|
||||
export const proposalCount = collectiveProposalCount('council');
|
||||
export const proposalHashes = collectiveProposalHashes('council');
|
||||
export const proposals = collectiveProposals('council');
|
||||
|
||||
export const prime = collectivePrime('council');
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { members as collectiveMembers } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, collectiveMembers(instanceId, api, 'council'));
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { prime as collectivePrime } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
|
||||
return memo(instanceId, collectivePrime(instanceId, api, 'council'));
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { u32 } from '@polkadot/types';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { DeriveCollectiveProposal } from '../types';
|
||||
|
||||
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
|
||||
return memo(instanceId, collectiveHasProposals(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
return memo(instanceId, collectiveProposal(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
|
||||
return memo(instanceId, collectiveProposalCount(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
|
||||
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, collectiveProposals(instanceId, api, 'council'));
|
||||
}
|
||||
@@ -61,10 +61,8 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt
|
||||
// however we have had cases on Darwinia where the indices have moved around after an
|
||||
// upgrade, which results in invalid on-chain data
|
||||
combineLatest(blockNumbers.map((blockNumber) =>
|
||||
api.query.scheduler.agenda(blockNumber).pipe(
|
||||
// this does create an issue since it discards all at that block
|
||||
catchError(() => of(null))
|
||||
)
|
||||
// this does create an issue since it discards all at that block
|
||||
api.query.scheduler.agenda(blockNumber).pipe(catchError(() => of(null)))
|
||||
))
|
||||
])
|
||||
: of<[BlockNumber[], null[]]>([[], []]);
|
||||
@@ -78,30 +76,23 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
const result: SchedulerInfo[] = [];
|
||||
|
||||
blockNumbers.forEach((at, index): void => {
|
||||
(agendas[index] || [])
|
||||
.filter((opt) => opt.isSome)
|
||||
.forEach((optScheduled): void => {
|
||||
const scheduled = optScheduled.unwrap();
|
||||
(agendas[index] || []).filter((o) => o.isSome).forEach((o): void => {
|
||||
const scheduled = o.unwrap();
|
||||
|
||||
if (scheduled.maybeId.isSome) {
|
||||
const id = scheduled.maybeId.unwrap().toHex();
|
||||
if (scheduled.maybeId.isSome) {
|
||||
const id = scheduled.maybeId.unwrap().toHex();
|
||||
|
||||
if (id.startsWith(DEMOCRACY_ID)) {
|
||||
const [, index] = api.registry.createType('(u64, ReferendumIndex)', id);
|
||||
const imageHash = scheduled.call.args[0] as Hash;
|
||||
|
||||
result.push({ at, imageHash, index });
|
||||
}
|
||||
}
|
||||
});
|
||||
id.startsWith(DEMOCRACY_ID) && result.push({ at, imageHash: scheduled.call.args[0] as Hash, index: api.registry.createType('(u64, ReferendumIndex)', id)[1] });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return result.length
|
||||
? combineLatest([
|
||||
of(result),
|
||||
api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
|
||||
])
|
||||
: of([[], []]);
|
||||
return combineLatest([
|
||||
of(result),
|
||||
result.length
|
||||
? api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
|
||||
: of([])
|
||||
]);
|
||||
}),
|
||||
map(([infos, images]): DeriveDispatch[] =>
|
||||
infos.map((info, index) => ({ ...info, image: images[index] }))
|
||||
|
||||
@@ -25,7 +25,11 @@ function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: Referendu
|
||||
return [
|
||||
end,
|
||||
(approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)
|
||||
? end.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[vote.conviction.index]))
|
||||
? end.add(
|
||||
(
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
).muln(LOCKUPS[vote.conviction.index]))
|
||||
: BN_ZERO
|
||||
];
|
||||
}
|
||||
@@ -50,7 +54,11 @@ function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: Vo
|
||||
referendumId,
|
||||
unlockAt: unlockAt.isZero()
|
||||
? unlockAt
|
||||
: referendumEnd.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[conviction.index])),
|
||||
: referendumEnd.add(
|
||||
(
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
).muln(LOCKUPS[conviction.index])),
|
||||
vote: api.registry.createType('Vote', { aye: vote.isAye, conviction })
|
||||
}))
|
||||
)
|
||||
|
||||
@@ -20,7 +20,6 @@ type Depositors = DepositorsNew | DepositorsOld;
|
||||
type Proposals = ITuple<[PropIndex, Hash, AccountId]>[];
|
||||
type Result = [Proposals, (DeriveProposalImage | undefined)[], Depositors[]];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function isNewDepositors (depositors: ITuple<[Vec<AccountId>, Balance]> | ITuple<[Balance, Vec<AccountId>]>): depositors is ITuple<[Vec<AccountId>, Balance]> {
|
||||
// Detect balance...
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
|
||||
@@ -6,6 +6,10 @@ import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, Refere
|
||||
import type { PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
export interface AtBlock {
|
||||
at: BlockNumber;
|
||||
}
|
||||
|
||||
export interface DeriveDemocracyLock {
|
||||
balance: Balance;
|
||||
isDelegated: boolean;
|
||||
@@ -16,15 +20,13 @@ export interface DeriveDemocracyLock {
|
||||
vote: Vote;
|
||||
}
|
||||
|
||||
export interface DeriveProposalImage {
|
||||
at: BlockNumber;
|
||||
export interface DeriveProposalImage extends AtBlock {
|
||||
balance: Balance;
|
||||
proposal?: Proposal;
|
||||
proposer: AccountId;
|
||||
}
|
||||
|
||||
export interface DeriveDispatch {
|
||||
at: BlockNumber;
|
||||
export interface DeriveDispatch extends AtBlock {
|
||||
index: ReferendumIndex;
|
||||
imageHash: Hash;
|
||||
image?: DeriveProposalImage;
|
||||
|
||||
@@ -42,7 +42,20 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
|
||||
return balanceB.cmp(balanceA);
|
||||
}
|
||||
|
||||
function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
function getConstants (api: ApiInterfaceRx, elections: string | null): Partial<DeriveElectionsInfo> {
|
||||
return elections
|
||||
? {
|
||||
candidacyBond: api.consts[elections].candidacyBond as Balance,
|
||||
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[elections].desiredMembers as u32,
|
||||
termDuration: api.consts[elections].termDuration as BlockNumber,
|
||||
votingBond: api.consts[elections].votingBond as Balance
|
||||
}
|
||||
: {};
|
||||
}
|
||||
|
||||
function getModules (api: ApiInterfaceRx): [string, string | null] {
|
||||
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
|
||||
const elections = api.query.phragmenElection
|
||||
? 'phragmenElection'
|
||||
: api.query.electionsPhragmen
|
||||
@@ -50,43 +63,8 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
: api.query.elections
|
||||
? 'elections'
|
||||
: null;
|
||||
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
|
||||
|
||||
return (
|
||||
elections
|
||||
? api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
|
||||
api.query[council].members,
|
||||
api.query[elections].candidates,
|
||||
api.query[elections].members,
|
||||
api.query[elections].runnersUp
|
||||
])
|
||||
: combineLatest([
|
||||
api.query[council].members<Vec<AccountId>>(),
|
||||
of<Candidate[]>([]),
|
||||
of<Member[]>([]),
|
||||
of<Member[]>([])
|
||||
])
|
||||
).pipe(
|
||||
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
|
||||
...(
|
||||
elections
|
||||
? {
|
||||
candidacyBond: api.consts[elections].candidacyBond as Balance,
|
||||
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[elections].desiredMembers as u32,
|
||||
termDuration: api.consts[elections].termDuration as BlockNumber,
|
||||
votingBond: api.consts[elections].votingBond as Balance
|
||||
}
|
||||
: {}
|
||||
),
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidates: candidates.map(getCandidate),
|
||||
members: members.length
|
||||
? members.map(getAccountTuple).sort(sortAccounts)
|
||||
: councilMembers.map((accountId): [AccountId, Balance] => [accountId, api.registry.createType('Balance')]),
|
||||
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts)
|
||||
}))
|
||||
);
|
||||
return [council, elections];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,5 +81,33 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveElectionsInfo> {
|
||||
return memo(instanceId, (): Observable<DeriveElectionsInfo> => queryElections(api));
|
||||
return memo(instanceId, (): Observable<DeriveElectionsInfo> => {
|
||||
const [council, elections] = getModules(api);
|
||||
|
||||
return (
|
||||
elections
|
||||
? api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
|
||||
api.query[council].members,
|
||||
api.query[elections].candidates,
|
||||
api.query[elections].members,
|
||||
api.query[elections].runnersUp
|
||||
])
|
||||
: combineLatest([
|
||||
api.query[council].members<Vec<AccountId>>(),
|
||||
of<Candidate[]>([]),
|
||||
of<Member[]>([]),
|
||||
of<Member[]>([])
|
||||
])
|
||||
).pipe(
|
||||
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
|
||||
...getConstants(api, elections),
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidates: candidates.map(getCandidate),
|
||||
members: members.length
|
||||
? members.map(getAccountTuple).sort(sortAccounts)
|
||||
: councilMembers.map((a): [AccountId, Balance] => [a, api.registry.createType('Balance')]),
|
||||
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts)
|
||||
}))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './members';
|
||||
export * from './prime';
|
||||
export * from './proposals';
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
|
||||
|
||||
export const members = collectiveMembers('membership');
|
||||
|
||||
export const hasProposals = collectiveHasProposals('membership');
|
||||
export const proposal = collectiveProposal('membership');
|
||||
export const proposalCount = collectiveProposalCount('membership');
|
||||
export const proposalHashes = collectiveProposalHashes('membership');
|
||||
export const proposals = collectiveProposals('membership');
|
||||
|
||||
export const prime = collectivePrime('membership');
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { members as collectiveMembers } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, collectiveMembers(instanceId, api, 'membership'));
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { prime as collectivePrime } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
|
||||
return memo(instanceId, collectivePrime(instanceId, api, 'membership'));
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { u32 } from '@polkadot/types';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { DeriveCollectiveProposal } from '../types';
|
||||
|
||||
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
|
||||
return memo(instanceId, collectiveHasProposals(instanceId, api, 'membership'));
|
||||
}
|
||||
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
return memo(instanceId, collectiveProposal(instanceId, api, 'membership'));
|
||||
}
|
||||
|
||||
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
|
||||
return memo(instanceId, collectiveProposalCount(instanceId, api, 'membership'));
|
||||
}
|
||||
|
||||
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
|
||||
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'membership'));
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, collectiveProposals(instanceId, api, 'membership'));
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-derive', version: '6.4.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-derive', version: '6.12.1' };
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function eraLength (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.session.info().pipe(
|
||||
map((info) => info.eraLength)
|
||||
));
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function eraProgress (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.session.progress().pipe(
|
||||
map((info) => info.eraProgress)
|
||||
));
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './eraLength';
|
||||
export * from './eraProgress';
|
||||
export * from './indexes';
|
||||
export * from './info';
|
||||
export * from './progress';
|
||||
export * from './sessionProgress';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option, u64 } from '@polkadot/types';
|
||||
import type { SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { BlockNumber, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
@@ -15,6 +15,15 @@ type ResultSlotsNoSession = [u64, u64, u64];
|
||||
type ResultSlots = [u64, u64, u64, Option<SessionIndex>];
|
||||
type ResultSlotsFlat = [u64, u64, u64, SessionIndex];
|
||||
|
||||
function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.session.progress().pipe(
|
||||
map((info) => info[field])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress {
|
||||
const epochStartSlot = epochIndex.mul(info.sessionLength).iadd(epochOrGenesisStartSlot);
|
||||
const sessionProgress = currentSlot.sub(epochStartSlot);
|
||||
@@ -77,3 +86,7 @@ export function progress (instanceId: string, api: ApiInterfaceRx): () => Observ
|
||||
: queryAura(api)
|
||||
);
|
||||
}
|
||||
|
||||
export const eraLength = withProgressField('eraLength');
|
||||
export const eraProgress = withProgressField('eraProgress');
|
||||
export const sessionProgress = withProgressField('sessionProgress');
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function sessionProgress (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.session.progress().pipe(
|
||||
map((info) => info.sessionProgress)
|
||||
));
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import { combineLatest, map, switchMap } from 'rxjs';
|
||||
|
||||
import { BN, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
const QUERY_OPTS = {
|
||||
withDestination: true,
|
||||
@@ -73,7 +73,9 @@ export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds:
|
||||
api.derive.staking.keysMulti(accountIds),
|
||||
api.derive.staking.queryMulti(accountIds, QUERY_OPTS)
|
||||
]).pipe(
|
||||
map(([keys, queries]) => queries.map((query, index) => parseResult(api, sessionInfo, keys[index], query)))
|
||||
map(([keys, queries]) =>
|
||||
queries.map((q, index) => parseResult(api, sessionInfo, keys[index], q))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -83,10 +85,7 @@ export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds:
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||
*/
|
||||
export function account (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
|
||||
api.derive.staking.accounts([accountId]).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const account = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string) =>
|
||||
api.derive.staking.accounts([accountId])
|
||||
);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { deriveCache } from '../util';
|
||||
|
||||
export function getEraCache <T> (CACHE_KEY: string, era: EraIndex, withActive?: boolean): [string, T | undefined] {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}`;
|
||||
|
||||
return [
|
||||
cacheKey,
|
||||
withActive
|
||||
? undefined
|
||||
: deriveCache.get<T>(cacheKey)
|
||||
];
|
||||
}
|
||||
|
||||
export function getEraMultiCache <T> (CACHE_KEY: string, eras: EraIndex[], withActive?: boolean): T[] {
|
||||
const cached: T[] = withActive
|
||||
? []
|
||||
: eras
|
||||
.map((e) => deriveCache.get<T>(`${CACHE_KEY}-${e.toString()}`))
|
||||
.filter((v): v is T => !!v);
|
||||
|
||||
return cached;
|
||||
}
|
||||
|
||||
export function setEraCache <T extends { era: EraIndex }> (cacheKey: string, withActive: boolean, value: T): T {
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function setEraMultiCache <T extends { era: EraIndex }> (CACHE_KEY: string, withActive: boolean, values: T[]): T[] {
|
||||
!withActive && values.forEach((v) => deriveCache.set(`${CACHE_KEY}-${v.era.toString()}`, v));
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
export function filterCachedEras <T extends { era: EraIndex }> (eras: EraIndex[], cached: T[], query: T[]): T[] {
|
||||
return eras.map((e) =>
|
||||
cached.find(({ era }) => e.eq(era)) ||
|
||||
query.find(({ era }) => e.eq(era)) as T
|
||||
);
|
||||
}
|
||||
@@ -8,9 +8,11 @@ import type { AccountId, EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletStakingExposure } from '@polkadot/types/lookup';
|
||||
import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { memo } from '../util';
|
||||
import { getEraCache, setEraCache } from './cache';
|
||||
import { combineEras, erasHistoricApply, singleEra } from './util';
|
||||
|
||||
type KeysAndExposures = [StorageKey<[EraIndex, AccountId]>, PalletStakingExposure][];
|
||||
|
||||
@@ -36,45 +38,18 @@ function mapStakers (era: EraIndex, stakers: KeysAndExposures): DeriveEraExposur
|
||||
return { era, nominators, validators };
|
||||
}
|
||||
|
||||
export function _eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraExposure> {
|
||||
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraExposure> => {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}`;
|
||||
const cached = withActive
|
||||
? undefined
|
||||
: deriveCache.get<DeriveEraExposure>(cacheKey);
|
||||
export function _eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive?: boolean) => Observable<DeriveEraExposure> {
|
||||
return memo(instanceId, (era: EraIndex, withActive = false): Observable<DeriveEraExposure> => {
|
||||
const [cacheKey, cached] = getEraCache<DeriveEraExposure>(CACHE_KEY, era, withActive);
|
||||
|
||||
return cached
|
||||
? of(cached)
|
||||
: api.query.staking.erasStakersClipped.entries(era).pipe(
|
||||
map((stakers): DeriveEraExposure => {
|
||||
const value = mapStakers(era, stakers);
|
||||
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
})
|
||||
map((r) => setEraCache(cacheKey, withActive, mapStakers(era, r)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraExposure> {
|
||||
return memo(instanceId, (era: EraIndex): Observable<DeriveEraExposure> =>
|
||||
api.derive.staking._eraExposure(era, true)
|
||||
);
|
||||
}
|
||||
|
||||
export function _erasExposure (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraExposure[]> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraExposure[]> =>
|
||||
eras.length
|
||||
? combineLatest(eras.map((era) => api.derive.staking._eraExposure(era, withActive)))
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
export function erasExposure (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraExposure[]> {
|
||||
return memo(instanceId, (withActive = false): Observable<DeriveEraExposure[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._erasExposure(eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const eraExposure = singleEra('_eraExposure');
|
||||
export const _erasExposure = combineEras('_eraExposure');
|
||||
export const erasExposure = erasHistoricApply('_erasExposure');
|
||||
|
||||
@@ -13,8 +13,8 @@ import { BN_ONE, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive: boolean) => Observable<EraIndex[]> {
|
||||
return memo(instanceId, (withActive: boolean): Observable<EraIndex[]> =>
|
||||
export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<EraIndex[]> {
|
||||
return memo(instanceId, (withActive?: boolean): Observable<EraIndex[]> =>
|
||||
api.queryMulti<[Option<ActiveEraInfo>, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.historyDepth
|
||||
|
||||
@@ -7,12 +7,13 @@ import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup';
|
||||
import type { DeriveEraPoints, DeriveEraValPoints } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { filterEras } from './util';
|
||||
import { memo } from '../util';
|
||||
import { filterCachedEras, getEraMultiCache, setEraMultiCache } from './cache';
|
||||
import { erasHistoricApply, filterEras } from './util';
|
||||
|
||||
const CACHE_KEY = 'eraPoints';
|
||||
|
||||
@@ -40,34 +41,15 @@ export function _erasPoints (instanceId: string, api: ApiInterfaceRx): (eras: Er
|
||||
return of([]);
|
||||
}
|
||||
|
||||
const cached: DeriveEraPoints[] = withActive
|
||||
? []
|
||||
: eras
|
||||
.map((era) => deriveCache.get<DeriveEraPoints>(`${CACHE_KEY}-${era.toString()}`))
|
||||
.filter((value): value is DeriveEraPoints => !!value);
|
||||
const cached = getEraMultiCache<DeriveEraPoints>(CACHE_KEY, eras, withActive);
|
||||
const remaining = filterEras(eras, cached);
|
||||
|
||||
return !remaining.length
|
||||
? of(cached)
|
||||
: api.query.staking.erasRewardPoints.multi(remaining).pipe(
|
||||
map((points): DeriveEraPoints[] => {
|
||||
const query = mapPoints(remaining, points);
|
||||
|
||||
!withActive && query.forEach((q) => deriveCache.set(`${CACHE_KEY}-${q.era.toString()}`, q));
|
||||
|
||||
return eras.map((era): DeriveEraPoints =>
|
||||
cached.find((cached) => era.eq(cached.era)) ||
|
||||
query.find((query) => era.eq(query.era)) as DeriveEraPoints
|
||||
);
|
||||
})
|
||||
map((p) => filterCachedEras(eras, cached, setEraMultiCache(CACHE_KEY, withActive, mapPoints(remaining, p))))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function erasPoints (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraPoints[]> {
|
||||
return memo(instanceId, (withActive = false): Observable<DeriveEraPoints[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._erasPoints(eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const erasPoints = erasHistoricApply('_erasPoints');
|
||||
|
||||
@@ -8,9 +8,11 @@ import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletStakingValidatorPrefs } from '@polkadot/types/lookup';
|
||||
import type { DeriveEraPrefs, DeriveEraValPrefs } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { memo } from '../util';
|
||||
import { getEraCache, setEraCache } from './cache';
|
||||
import { combineEras, erasHistoricApply, singleEra } from './util';
|
||||
|
||||
const CACHE_KEY = 'eraPrefs';
|
||||
|
||||
@@ -26,43 +28,16 @@ function mapPrefs (era: EraIndex, all: [StorageKey, PalletStakingValidatorPrefs]
|
||||
|
||||
export function _eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraPrefs> {
|
||||
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraPrefs> => {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}`;
|
||||
const cached = withActive
|
||||
? undefined
|
||||
: deriveCache.get<DeriveEraPrefs>(cacheKey);
|
||||
const [cacheKey, cached] = getEraCache<DeriveEraPrefs>(CACHE_KEY, era, withActive);
|
||||
|
||||
return cached
|
||||
? of(cached)
|
||||
: api.query.staking.erasValidatorPrefs.entries(era).pipe(
|
||||
map((prefs): DeriveEraPrefs => {
|
||||
const value = mapPrefs(era, prefs);
|
||||
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
})
|
||||
map((r) => setEraCache(cacheKey, withActive, mapPrefs(era, r)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraPrefs> {
|
||||
return memo(instanceId, (era: EraIndex): Observable<DeriveEraPrefs> =>
|
||||
api.derive.staking._eraPrefs(era, true)
|
||||
);
|
||||
}
|
||||
|
||||
export function _erasPrefs (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraPrefs[]> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraPrefs[]> =>
|
||||
eras.length
|
||||
? combineLatest(eras.map((era) => api.derive.staking._eraPrefs(era, withActive)))
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
export function erasPrefs (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraPrefs[]> {
|
||||
return memo(instanceId, (withActive = false): Observable<DeriveEraPrefs[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._erasPrefs(eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const eraPrefs = singleEra('_eraPrefs');
|
||||
export const _erasPrefs = combineEras('_eraPrefs');
|
||||
export const erasPrefs = erasHistoricApply('_erasPrefs');
|
||||
|
||||
@@ -7,10 +7,11 @@ import type { Option } from '@polkadot/types';
|
||||
import type { Balance, EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveEraRewards } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { filterEras } from './util';
|
||||
import { memo } from '../util';
|
||||
import { filterCachedEras, getEraMultiCache, setEraMultiCache } from './cache';
|
||||
import { erasHistoricApply, filterEras } from './util';
|
||||
|
||||
const CACHE_KEY = 'eraRewards';
|
||||
|
||||
@@ -27,11 +28,7 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E
|
||||
return of([]);
|
||||
}
|
||||
|
||||
const cached: DeriveEraRewards[] = withActive
|
||||
? []
|
||||
: eras
|
||||
.map((era) => deriveCache.get<DeriveEraRewards>(`${CACHE_KEY}-${era.toString()}`))
|
||||
.filter((value): value is DeriveEraRewards => !!value);
|
||||
const cached = getEraMultiCache<DeriveEraRewards>(CACHE_KEY, eras, withActive);
|
||||
const remaining = filterEras(eras, cached);
|
||||
|
||||
if (!remaining.length) {
|
||||
@@ -39,24 +36,9 @@ export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: E
|
||||
}
|
||||
|
||||
return api.query.staking.erasValidatorReward.multi(remaining).pipe(
|
||||
map((optRewards) => {
|
||||
const query = mapRewards(remaining, optRewards);
|
||||
|
||||
!withActive && query.forEach((q) => deriveCache.set(`${CACHE_KEY}-${q.era.toString()}`, q));
|
||||
|
||||
return eras.map((era): DeriveEraRewards =>
|
||||
cached.find((cached) => era.eq(cached.era)) ||
|
||||
query.find((query) => era.eq(query.era)) as DeriveEraRewards
|
||||
);
|
||||
})
|
||||
map((r) => filterCachedEras(eras, cached, setEraMultiCache(CACHE_KEY, withActive, mapRewards(remaining, r))))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function erasRewards (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraRewards[]> {
|
||||
return memo(instanceId, (withActive = false): Observable<DeriveEraRewards[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._erasRewards(eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const erasRewards = erasHistoricApply('_erasRewards');
|
||||
|
||||
@@ -8,9 +8,11 @@ import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { DeriveEraSlashes, DeriveEraValSlash } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { memo } from '../util';
|
||||
import { getEraCache, setEraCache } from './cache';
|
||||
import { combineEras, erasHistoricApply, singleEra } from './util';
|
||||
|
||||
const CACHE_KEY = 'eraSlashes';
|
||||
|
||||
@@ -31,10 +33,7 @@ function mapSlashes (era: EraIndex, noms: [StorageKey, Option<BalanceOf>][], val
|
||||
|
||||
export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable<DeriveEraSlashes> {
|
||||
return memo(instanceId, (era: EraIndex, withActive: boolean): Observable<DeriveEraSlashes> => {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}`;
|
||||
const cached = withActive
|
||||
? undefined
|
||||
: deriveCache.get<DeriveEraSlashes>(cacheKey);
|
||||
const [cacheKey, cached] = getEraCache<DeriveEraSlashes>(CACHE_KEY, era, withActive);
|
||||
|
||||
return cached
|
||||
? of(cached)
|
||||
@@ -42,37 +41,11 @@ export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: Era
|
||||
api.query.staking.nominatorSlashInEra.entries(era),
|
||||
api.query.staking.validatorSlashInEra.entries(era)
|
||||
]).pipe(
|
||||
map(([noms, vals]): DeriveEraSlashes => {
|
||||
const value = mapSlashes(era, noms, vals);
|
||||
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
})
|
||||
map(([n, v]) => setEraCache(cacheKey, withActive, mapSlashes(era, n, v)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraSlashes> {
|
||||
return memo(instanceId, (era: EraIndex): Observable<DeriveEraSlashes> =>
|
||||
api.derive.staking._eraSlashes(era, true)
|
||||
);
|
||||
}
|
||||
|
||||
export function _erasSlashes (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<DeriveEraSlashes[]> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<DeriveEraSlashes[]> =>
|
||||
eras.length
|
||||
? combineLatest(
|
||||
eras.map((era) => api.derive.staking._eraSlashes(era, withActive))
|
||||
)
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
export function erasSlashes (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable<DeriveEraSlashes[]> {
|
||||
return memo(instanceId, (withActive = false): Observable<DeriveEraSlashes[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._erasSlashes(eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const eraSlashes = singleEra('_eraSlashes');
|
||||
export const _erasSlashes = combineEras('_eraSlashes');
|
||||
export const erasSlashes = erasHistoricApply('_erasSlashes');
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { DeriveStakingKeys } from './types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, NodeRuntimeSessionKeys | AccountId[]][], nextKeys: Option<NodeRuntimeSessionKeys>): DeriveStakingKeys {
|
||||
const sessionIds = (queuedKeys.find(([currentId]) => currentId.eq(stashId)) || [undefined, [] as AccountId[]])[1];
|
||||
@@ -27,13 +27,10 @@ function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Node
|
||||
};
|
||||
}
|
||||
|
||||
export function keys (instanceId: string, api: ApiInterfaceRx): (stashId: Uint8Array | string) => Observable<DeriveStakingKeys> {
|
||||
return memo(instanceId, (stashId: Uint8Array | string): Observable<DeriveStakingKeys> =>
|
||||
api.derive.staking.keysMulti([stashId]).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const keys = firstMemo(
|
||||
(api: ApiInterfaceRx, stashId: Uint8Array | string) =>
|
||||
api.derive.staking.keysMulti([stashId])
|
||||
);
|
||||
|
||||
export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable<DeriveStakingKeys[]> {
|
||||
return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable<DeriveStakingKeys[]> =>
|
||||
|
||||
@@ -7,17 +7,18 @@ import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletStakingExposure } from '@polkadot/types/lookup';
|
||||
import type { DeriveOwnExposure } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
import { erasHistoricApplyAccount } from './util';
|
||||
|
||||
export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveOwnExposure[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveOwnExposure[]> =>
|
||||
eras.length
|
||||
? api.queryMulti<PalletStakingExposure[]>([
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakersClipped, [era, accountId]]),
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakers, [era, accountId]])
|
||||
...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakersClipped, [e, accountId]]),
|
||||
...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakers, [e, accountId]])
|
||||
]).pipe(
|
||||
map((all): DeriveOwnExposure[] =>
|
||||
eras.map((era, index) => ({ clipped: all[index], era, exposure: all[eras.length + index] }))
|
||||
@@ -27,20 +28,9 @@ export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accoun
|
||||
);
|
||||
}
|
||||
|
||||
export function ownExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex) => Observable<DeriveOwnExposure> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex): Observable<DeriveOwnExposure> =>
|
||||
api.derive.staking._ownExposures(accountId, [era], true).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const ownExposure = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) =>
|
||||
api.derive.staking._ownExposures(accountId, [era], true)
|
||||
);
|
||||
|
||||
export function ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveOwnExposure[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveOwnExposure[]> => {
|
||||
return api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) =>
|
||||
api.derive.staking._ownExposures(accountId, eras, withActive)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
export const ownExposures = erasHistoricApplyAccount('_ownExposures');
|
||||
|
||||
@@ -8,17 +8,18 @@ import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { DeriveStakerSlashes } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
import { erasHistoricApplyAccount } from './util';
|
||||
|
||||
export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerSlashes[]> =>
|
||||
eras.length
|
||||
? api.queryMulti<(Option<ITuple<[Perbill, BalanceOf]>> | Option<BalanceOf>)[]>([
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.validatorSlashInEra, [era, accountId]]),
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.nominatorSlashInEra, [era, accountId]])
|
||||
...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.validatorSlashInEra, [e, accountId]]),
|
||||
...eras.map((e): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.nominatorSlashInEra, [e, accountId]])
|
||||
]).pipe(
|
||||
map((values): DeriveStakerSlashes[] =>
|
||||
eras.map((era, index) => ({
|
||||
@@ -33,20 +34,9 @@ export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountI
|
||||
);
|
||||
}
|
||||
|
||||
export function ownSlash (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex) => Observable<DeriveStakerSlashes> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex): Observable<DeriveStakerSlashes> =>
|
||||
api.derive.staking._ownSlashes(accountId, [era], true).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const ownSlash = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) =>
|
||||
api.derive.staking._ownSlashes(accountId, [era], true)
|
||||
);
|
||||
|
||||
export function ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerSlashes[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerSlashes[]> => {
|
||||
return api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) =>
|
||||
api.derive.staking._ownSlashes(accountId, eras, withActive)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
export const ownSlashes = erasHistoricApplyAccount('_ownSlashes');
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { DeriveStakingQuery, StakingQueryFlags } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestination: PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
|
||||
return {
|
||||
@@ -29,8 +29,8 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> |
|
||||
|
||||
function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[], { withLedger = false }: StakingQueryFlags): Observable<Option<PalletStakingStakingLedger>[]> {
|
||||
const ids = optIds
|
||||
.filter((opt): opt is Option<AccountId> => withLedger && !!opt && opt.isSome)
|
||||
.map((opt) => opt.unwrap());
|
||||
.filter((o): o is Option<AccountId> => withLedger && !!o && o.isSome)
|
||||
.map((o) => o.unwrap());
|
||||
const emptyLed = api.registry.createType<Option<PalletStakingStakingLedger>>('Option<StakingLedger>');
|
||||
|
||||
return (
|
||||
@@ -93,13 +93,10 @@ function getBatch (api: ApiInterfaceRx, activeEra: EraIndex, stashIds: AccountId
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and all relevant details
|
||||
*/
|
||||
export function query (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, flags: StakingQueryFlags) => Observable<DeriveStakingQuery> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, flags: StakingQueryFlags): Observable<DeriveStakingQuery> =>
|
||||
api.derive.staking.queryMulti([accountId], flags).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const query = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string, flags: StakingQueryFlags) =>
|
||||
api.derive.staking.queryMulti([accountId], flags)
|
||||
);
|
||||
|
||||
export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable<DeriveStakingQuery[]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags): Observable<DeriveStakingQuery[]> =>
|
||||
|
||||
@@ -8,10 +8,10 @@ import type { DeriveEraValidatorExposure, DeriveStakerExposure } from '../types'
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerExposure[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean): Observable<DeriveStakerExposure[][]> => {
|
||||
export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerExposure[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerExposure[][]> => {
|
||||
const stakerIds = accountIds.map((a) => api.registry.createType('AccountId', a).toString());
|
||||
|
||||
return api.derive.staking._erasExposure(eras, withActive).pipe(
|
||||
@@ -46,10 +46,7 @@ export function stakerExposures (instanceId: string, api: ApiInterfaceRx): (acco
|
||||
);
|
||||
}
|
||||
|
||||
export function stakerExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerExposure[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerExposure[]> =>
|
||||
api.derive.staking.stakerExposures([accountId], withActive).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
export const stakerExposure = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) =>
|
||||
api.derive.staking.stakerExposures([accountId], withActive)
|
||||
);
|
||||
|
||||
@@ -6,9 +6,10 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveStakerPoints } from '../types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { erasHistoricApplyAccount } from './util';
|
||||
|
||||
export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPoints[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerPoints[]> => {
|
||||
@@ -26,10 +27,4 @@ export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accoun
|
||||
});
|
||||
}
|
||||
|
||||
export function stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerPoints[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerPoints[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerPoints(accountId, eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const stakerPoints = erasHistoricApplyAccount('_stakerPoints');
|
||||
|
||||
@@ -6,14 +6,15 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveStakerPrefs } from '../types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { erasHistoricApplyAccount } from './util';
|
||||
|
||||
export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerPrefs[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable<DeriveStakerPrefs[]> =>
|
||||
api.query.staking.erasValidatorPrefs.multi(eras.map((era) => [era, accountId])).pipe(
|
||||
api.query.staking.erasValidatorPrefs.multi(eras.map((e) => [e, accountId])).pipe(
|
||||
map((all): DeriveStakerPrefs[] =>
|
||||
all.map((validatorPrefs, index): DeriveStakerPrefs => ({
|
||||
era: eras[index],
|
||||
@@ -24,10 +25,4 @@ export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (account
|
||||
);
|
||||
}
|
||||
|
||||
export function stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerPrefs[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerPrefs[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerPrefs(accountId, eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const stakerPrefs = erasHistoricApplyAccount('_stakerPrefs');
|
||||
|
||||
@@ -13,7 +13,7 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { BN_BILLION, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { firstMemo, memo } from '../util';
|
||||
|
||||
type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
|
||||
|
||||
@@ -98,7 +98,7 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
|
||||
if (index !== -1) {
|
||||
const valLedger = queryValidators[index].stakingLedger;
|
||||
|
||||
if (valLedger?.claimedRewards.some((era) => reward.era.eq(era))) {
|
||||
if (valLedger?.claimedRewards.some((e) => reward.era.eq(e))) {
|
||||
rm.push(validatorId);
|
||||
}
|
||||
}
|
||||
@@ -110,14 +110,14 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
|
||||
}
|
||||
|
||||
function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][], { rewards, stakingLedger }: { rewards: DeriveStakerReward[]; stakingLedger: PalletStakingStakingLedger }): DeriveStakerReward[] {
|
||||
const filter = eras.filter((era) => !stakingLedger.claimedRewards.some((e) => e.eq(era)));
|
||||
const filter = eras.filter((e) => !stakingLedger.claimedRewards.some((s) => s.eq(e)));
|
||||
const validators = valInfo.map(([v]) => v);
|
||||
const queryValidators = valInfo.map(([, q]) => q);
|
||||
|
||||
return rewards
|
||||
.filter(({ isEmpty }) => !isEmpty)
|
||||
.filter((reward): boolean => {
|
||||
if (!filter.some((filter) => reward.era.eq(filter))) {
|
||||
if (!filter.some((e) => reward.era.eq(e))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][
|
||||
}));
|
||||
}
|
||||
|
||||
export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<ErasResult> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<ErasResult> =>
|
||||
export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive?: boolean) => Observable<ErasResult> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive = false): Observable<ErasResult> =>
|
||||
combineLatest([
|
||||
api.derive.staking._erasPoints(eras, withActive),
|
||||
api.derive.staking._erasPrefs(eras, withActive),
|
||||
@@ -142,8 +142,8 @@ export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (e
|
||||
);
|
||||
}
|
||||
|
||||
export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive: boolean): Observable<DeriveStakerReward[][]> =>
|
||||
export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> =>
|
||||
combineLatest([
|
||||
api.derive.staking.queryMulti(accountIds, { withLedger: true }),
|
||||
api.derive.staking._stakerExposures(accountIds, eras, withActive),
|
||||
@@ -184,14 +184,12 @@ export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accou
|
||||
);
|
||||
}
|
||||
|
||||
export function stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerReward[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerReward[]> =>
|
||||
export const stakerRewards = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive)),
|
||||
map(([first]) => first)
|
||||
switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> =>
|
||||
|
||||
@@ -6,9 +6,10 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveStakerSlashes } from '../types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { erasHistoricApplyAccount } from './util';
|
||||
|
||||
export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerSlashes[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerSlashes[]> => {
|
||||
@@ -25,10 +26,4 @@ export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accou
|
||||
});
|
||||
}
|
||||
|
||||
export function stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerSlashes[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerSlashes[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerSlashes(accountId, eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
export const stakerSlashes = erasHistoricApplyAccount('_stakerSlashes');
|
||||
|
||||
@@ -1,8 +1,60 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx, ObsInnerType } from '@polkadot/api/types';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces';
|
||||
import type { ExactDerive } from '../bundle';
|
||||
|
||||
import { combineLatest, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type ApplyReturn<T extends keyof ExactDerive['staking']> = ReturnType<ExactDerive['staking'][T]>;
|
||||
|
||||
export function filterEras <T extends { era: EraIndex }> (eras: EraIndex[], list: T[]): EraIndex[] {
|
||||
return eras.filter((era) => !list.some((entry) => era.eq(entry.era)));
|
||||
return eras.filter((e) => !list.some(({ era }) => e.eq(era)));
|
||||
}
|
||||
|
||||
export function erasHistoricApply <F extends '_erasExposure' | '_erasPoints' | '_erasPrefs' | '_erasRewards' | '_erasSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (withActive?: boolean) => ApplyReturn<F> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
// Cannot quite get the typing right, but it is right in the code
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
memo(instanceId, (withActive = false) =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((e) => api.derive.staking[fn](e, withActive))
|
||||
)
|
||||
) as any;
|
||||
}
|
||||
|
||||
export function erasHistoricApplyAccount <F extends '_ownExposures' | '_ownSlashes' | '_stakerPoints' | '_stakerPrefs' | '_stakerSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (accountId: string | Uint8Array, withActive?: boolean) => ApplyReturn<F> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
// Cannot quite get the typing right, but it is right in the code
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
memo(instanceId, (accountId: string | Uint8Array, withActive = false) =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((e) => api.derive.staking[fn](accountId, e, withActive))
|
||||
)
|
||||
) as any;
|
||||
}
|
||||
|
||||
export function singleEra <F extends '_eraExposure' | '_eraPrefs' | '_eraSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (era: EraIndex) => ApplyReturn<F> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
// Cannot quite get the typing right, but it is right in the code
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
memo(instanceId, (era: EraIndex) =>
|
||||
api.derive.staking[fn](era, true)
|
||||
) as any;
|
||||
}
|
||||
|
||||
export function combineEras <F extends '_eraExposure' | '_eraPrefs' | '_eraSlashes'> (fn: F): (instanceId: string, api: ApiInterfaceRx) => (eras: EraIndex[], withActive: boolean) => Observable<ObsInnerType<ApplyReturn<F>>[]> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
// Cannot quite get the typing right, but it is right in the code
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
memo(instanceId, (eras: EraIndex[], withActive: boolean) =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
eras.length
|
||||
? combineLatest(eras.map((e) => api.derive.staking[fn](e, withActive)))
|
||||
: of([])
|
||||
) as any;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './members';
|
||||
export * from './prime';
|
||||
export * from './proposals';
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
|
||||
|
||||
export const members = collectiveMembers('technicalCommittee');
|
||||
|
||||
export const hasProposals = collectiveHasProposals('technicalCommittee');
|
||||
export const proposal = collectiveProposal('technicalCommittee');
|
||||
export const proposalCount = collectiveProposalCount('technicalCommittee');
|
||||
export const proposalHashes = collectiveProposalHashes('technicalCommittee');
|
||||
export const proposals = collectiveProposals('technicalCommittee');
|
||||
|
||||
export const prime = collectivePrime('technicalCommittee');
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { members as collectiveMembers } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, collectiveMembers(instanceId, api, 'technicalCommittee'));
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
import { prime as collectivePrime } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
|
||||
return memo(instanceId, collectivePrime(instanceId, api, 'technicalCommittee'));
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user