Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5c25d75ff | ||
|
|
780cc62942 | ||
|
|
165568c905 | ||
|
|
976a48d8f9 | ||
|
|
35cbbbe0ed | ||
|
|
772769c981 | ||
|
|
1ba2bd1766 | ||
|
|
4afa345a7d | ||
|
|
5c03359f32 | ||
|
|
04120505f0 | ||
|
|
7bd9dd65f8 | ||
|
|
5f57ecb2e1 | ||
|
|
9123f1d805 | ||
|
|
7050c4a554 | ||
|
|
62afb0b534 | ||
|
|
5157ca5608 | ||
|
|
315617c027 | ||
|
|
7d33b4dec6 | ||
|
|
2345f69c71 | ||
|
|
3cef2fb4d5 | ||
|
|
2bbf5513b2 | ||
|
|
c146f06178 | ||
|
|
5903704b61 | ||
|
|
90d8db651b | ||
|
|
557283a3d1 | ||
|
|
88b84dcf75 | ||
|
|
45d190eaca | ||
|
|
6d32328509 | ||
|
|
ba470e7417 | ||
|
|
4a16e46f88 | ||
|
|
ada0d99a84 | ||
|
|
e486fc4316 | ||
|
|
6e5c6f4e0b | ||
|
|
21ddcaf173 | ||
|
|
6085b994f6 | ||
|
|
7c3bf05868 | ||
|
|
8bce5b4a09 | ||
|
|
7a6077301f | ||
|
|
3f2767462f | ||
|
|
ecc37d11df | ||
|
|
0589d151da | ||
|
|
47cd6c6410 | ||
|
|
65688f9e0e | ||
|
|
5eb2a95ef2 | ||
|
|
282b39d27a | ||
|
|
f21e3d317a | ||
|
|
c2af7cf8f2 | ||
|
|
0958a4c693 | ||
|
|
c687181130 | ||
|
|
685f1ec0b6 | ||
|
|
e0069b6f7d | ||
|
|
cf48762ff2 | ||
|
|
31a7545a19 | ||
|
|
5cd8e8fb97 | ||
|
|
96e4090174 | ||
|
|
0bbebab90b | ||
|
|
57dac0ef47 | ||
|
|
6c3d24551b | ||
|
|
e7dc6d7a5a | ||
|
|
a63b7f611e | ||
|
|
82e15dc36d | ||
|
|
6f96037cb5 | ||
|
|
b6da84b8b2 | ||
|
|
41209f074c | ||
|
|
c47964c942 | ||
|
|
5f13a634e5 | ||
|
|
40af520fe7 | ||
|
|
1e506e0f8c | ||
|
|
96ea5803d4 | ||
|
|
7d99459f50 | ||
|
|
8fa090f435 | ||
|
|
d3c60d197c | ||
|
|
ad8550f7f5 | ||
|
|
a899aa439d | ||
|
|
e0e075b350 | ||
|
|
34ff14547e | ||
|
|
681a80d456 | ||
|
|
ed5f2673ce | ||
|
|
43e87603e2 | ||
|
|
d056416b47 | ||
|
|
1bcf94131d | ||
|
|
17b607b6c3 | ||
|
|
5a16d1dd8b | ||
|
|
144b74306a | ||
|
|
16b9fa956d | ||
|
|
b6af4b9877 | ||
|
|
3f368e721d | ||
|
|
22b4257636 | ||
|
|
ca7a631032 | ||
|
|
da5bbd17af | ||
|
|
b58f3f5c3e | ||
|
|
8c30194f59 | ||
|
|
dc9ec37490 | ||
|
|
5175e77eec | ||
|
|
9553c5467c | ||
|
|
a1f07e3274 | ||
|
|
58deb2eb14 | ||
|
|
83caad7f1b | ||
|
|
26c3cc9126 | ||
|
|
1a231dfb0d | ||
|
|
712d0425d0 | ||
|
|
eaa5db517f | ||
|
|
88c3850d1b | ||
|
|
943df72ae9 | ||
|
|
67ab11a036 | ||
|
|
c87ef7526b | ||
|
|
bccf2d52ad | ||
|
|
be6dbdd3e4 | ||
|
|
3c34ee9897 | ||
|
|
9ad97813e3 | ||
|
|
028f04e47f | ||
|
|
4974c9247f | ||
|
|
1ffe6a11bf | ||
|
|
19699ea445 | ||
|
|
d98ccfb12a | ||
|
|
41cb056b0f | ||
|
|
48bda0bdea | ||
|
|
1b393c7b67 | ||
|
|
f52e518b7b | ||
|
|
08970cff88 | ||
|
|
6d38ca6453 | ||
|
|
60db4bc66b | ||
|
|
0661237b28 | ||
|
|
6ccac712a8 | ||
|
|
3d4877940c | ||
|
|
70fc95ef27 | ||
|
|
463f65d25c | ||
|
|
09d176c82e | ||
|
|
fce96baf3d | ||
|
|
c6785c533f | ||
|
|
64de021149 | ||
|
|
de9e17a1a0 | ||
|
|
987bccea2e | ||
|
|
1434b86b8f | ||
|
|
a398b2201f | ||
|
|
f015837c38 | ||
|
|
5b51588995 | ||
|
|
7383e521e5 | ||
|
|
b10f05786c | ||
|
|
a212351528 | ||
|
|
55c01af260 | ||
|
|
1cf6ffad2b | ||
|
|
00d0ab9de1 | ||
|
|
b38e60a9a7 | ||
|
|
29f7e46439 | ||
|
|
fa0add8564 | ||
|
|
5bec38c404 | ||
|
|
43b66b6507 | ||
|
|
7e370b3a23 | ||
|
|
2b270a3c9f | ||
|
|
cf0d9a2d3f | ||
|
|
5d70622819 | ||
|
|
fcebdb6d6f | ||
|
|
3d020b5159 | ||
|
|
530d1bcd03 | ||
|
|
a4151c2941 | ||
|
|
a801d30fb6 | ||
|
|
1fe9b605dd | ||
|
|
ecfd822d94 | ||
|
|
a5e4d68993 | ||
|
|
ca5c002d37 | ||
|
|
6e28760da4 | ||
|
|
a253c4edb5 | ||
|
|
7c96525d35 | ||
|
|
3f0457efc2 | ||
|
|
bfb241d995 | ||
|
|
314ad8c3f2 | ||
|
|
aa85371f82 | ||
|
|
d0a08dadd9 | ||
|
|
eeff764345 | ||
|
|
4870ec4f40 | ||
|
|
1c3cfbfa0c | ||
|
|
3c9b7de6c7 | ||
|
|
22e5488f16 | ||
|
|
b37887993e | ||
|
|
75361cb0ff | ||
|
|
894992bc4c | ||
|
|
d955fab169 | ||
|
|
580d225387 | ||
|
|
d48f59e48d | ||
|
|
108b49ea03 | ||
|
|
9295349886 | ||
|
|
a51658ffac | ||
|
|
47f08e9e04 | ||
|
|
7906ae63dc | ||
|
|
0e76271dba | ||
|
|
e117619e34 | ||
|
|
67b416fe80 | ||
|
|
78dbfa46fa | ||
|
|
01db9261d5 | ||
|
|
674c38b384 | ||
|
|
0700e824eb | ||
|
|
0362eaf472 | ||
|
|
696b3964e6 | ||
|
|
5d0c2eed7b | ||
|
|
e4c3289ad8 | ||
|
|
4449bdae6f | ||
|
|
064957db81 | ||
|
|
ccd89ef0a6 | ||
|
|
47beb5f41f | ||
|
|
9f205392a3 | ||
|
|
adce7ccbee | ||
|
|
b83b3a9437 | ||
|
|
147dbcf24f | ||
|
|
2afff1b41f | ||
|
|
d1a1be49c5 | ||
|
|
4b6ad647a2 | ||
|
|
04f656cafa | ||
|
|
09bbd5f6c9 | ||
|
|
dbc3df6d09 | ||
|
|
26865f92e3 | ||
|
|
73045de73d | ||
|
|
6d3491b9f1 | ||
|
|
886f3a3c08 | ||
|
|
c72f976895 | ||
|
|
ab8b381d8b | ||
|
|
443e29a3be | ||
|
|
117bb5717a | ||
|
|
5fb76baa16 | ||
|
|
274b3498d4 | ||
|
|
fa9e1c53e1 | ||
|
|
3ebf7eb424 | ||
|
|
7d11e6f9a5 | ||
|
|
a0d6384b01 | ||
|
|
47afe2cfc6 | ||
|
|
c37a2fc756 | ||
|
|
e2545276bb | ||
|
|
4219409ef8 | ||
|
|
c9e64d2a32 | ||
|
|
41db3b2e35 | ||
|
|
ebe15dada6 | ||
|
|
c2cb5dc574 | ||
|
|
ba451348c0 | ||
|
|
ec76b11666 | ||
|
|
7603f9e6c1 | ||
|
|
b50eab11c0 | ||
|
|
66d05c1771 | ||
|
|
fd7c3d7e10 | ||
|
|
28d4c7d808 | ||
|
|
43d36fbcf6 | ||
|
|
e54eef2369 | ||
|
|
296842858f | ||
|
|
ba8849a3e9 | ||
|
|
e333c3d8d9 | ||
|
|
0fe6a21624 | ||
|
|
0abedb81c6 | ||
|
|
08eda72d4b | ||
|
|
70d4126c84 | ||
|
|
dcccab705c | ||
|
|
e45ff6d026 | ||
|
|
b49c2314e7 | ||
|
|
0ac085756a | ||
|
|
542a690c89 | ||
|
|
ff23ead797 | ||
|
|
ae55e4fbf7 | ||
|
|
b17412163d | ||
|
|
46dcbf9a42 | ||
|
|
193dfcc32f | ||
|
|
a81011cf94 | ||
|
|
d43a8b2e11 | ||
|
|
dff859ba68 | ||
|
|
5169b6ee69 | ||
|
|
f4405667fe | ||
|
|
49ff636305 | ||
|
|
d77d686c76 | ||
|
|
502c6a3451 | ||
|
|
b58c77683d |
+9
-3
@@ -1,4 +1,4 @@
|
||||
25
|
||||
29
|
||||
1.4.2
|
||||
1.6.2
|
||||
1.11.2
|
||||
@@ -8,11 +8,17 @@
|
||||
2.8.2
|
||||
3.2.2
|
||||
3.2.3
|
||||
|
||||
3.3.2
|
||||
3.6.2
|
||||
3.6.3
|
||||
3.6.4
|
||||
3.7.2
|
||||
3.7.3
|
||||
3.9.2
|
||||
3.9.2
|
||||
3.9.3
|
||||
3.10.2
|
||||
4.0.2
|
||||
4.0.3
|
||||
|
||||
4.6.2
|
||||
4.7.2
|
||||
@@ -24,8 +24,6 @@ module.exports = {
|
||||
...base.rules,
|
||||
// add override for any (a metric ton of them, initial conversion)
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
// these should be removed, there are 8 of them as errors
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
// this seems very broken atm, false positives
|
||||
'@typescript-eslint/unbound-method': 'off'
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -10,4 +10,4 @@ plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||
spec: "@yarnpkg/plugin-version"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-2.4.0.cjs
|
||||
yarnPath: .yarn/releases/yarn-2.4.1.cjs
|
||||
|
||||
+230
@@ -1,5 +1,235 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 4.7.2 Apr 26, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of 4.7.1 using nvm
|
||||
|
||||
Changes:
|
||||
|
||||
- Update `.nvmrc` to reflect engines changes
|
||||
- Update `EthBlock`/`EthHeader` types (as per Rust origin)
|
||||
- Updated Xcm `OriginKind` enum
|
||||
- Add derives for `membership`
|
||||
- Cleanups on encodedLength calculations
|
||||
|
||||
|
||||
## 4.7.1 Apr 25, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users following Substrate master.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust Struct decoding with better error messages on invalid input objects
|
||||
- Add support for new `BoundedVec` type
|
||||
- Expand `Data` type (as used in identity), with all is/as getters
|
||||
- Updated `Xcm` types (with Plularity)
|
||||
- Adjust `DispatchError` type as per current Substrate master
|
||||
- Adjusted Statemint `Proxy` type
|
||||
- Remove metadata generation dependency on well-known.json (dedupe)
|
||||
- Adjust WebSocket reconnection delay from 1s to 2.5s
|
||||
- Revert Beefy keys addition for Westend
|
||||
- Add explicit `engines` config to `package.json`
|
||||
- Support for `None` in `RewardDestination`
|
||||
- Align with latest substrate metadata
|
||||
|
||||
|
||||
## 4.6.2 Apr 19, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of Kusama/Polkadot.
|
||||
|
||||
Changes:
|
||||
|
||||
- Correct Kusama/Polkadot runtime 30 session key definitions
|
||||
|
||||
|
||||
## 4.6.1 Apr 19, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended if used in a Node.js 15.x environment.
|
||||
|
||||
Changes:
|
||||
|
||||
- Assert keypair validity in signing operations
|
||||
- Expose `internalError` on submittable results (e.g. event decoding errors)
|
||||
- Simplify session derives for old/new
|
||||
- Add Statemint to known types
|
||||
- Add support for `rpc.beefy.subscribeJustifications`
|
||||
- Update Xcm types
|
||||
- Explicitly handle `isReadyOrError` with `Api.create`
|
||||
- Add Kusama upgrade block for 2030
|
||||
|
||||
|
||||
## 4.5.1 Apr 12, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended with usage with the Rococo testnet.
|
||||
|
||||
Changes:
|
||||
|
||||
- Update parachain types as per latest Polkadot
|
||||
- Cater for `Keys` with `BEEFY` session keys
|
||||
- Update `Keys` injection to allow for on-chain type detection
|
||||
- Add `Westend` known upgrade block for runtime 50
|
||||
- Align types with latest Substrate master
|
||||
- Adjust keepalive `system_health` timer
|
||||
|
||||
|
||||
## 4.4.1 Apr 5, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended with usage with the Rococo testnet.
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `ServiceQuality` type for Cumulus
|
||||
- Adjust XCM MultiLocation type (X5 to X8 junctions)
|
||||
- Add Polkadot 29 upgrade block
|
||||
|
||||
|
||||
## 4.3.1 Mar 29, 2021
|
||||
|
||||
Upgrade priority: Low.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Fix documentation on ABI parameters (Thanks to https://github.com/vminkov)
|
||||
|
||||
Changes:
|
||||
|
||||
- Warn on usage of deprecated contract interfaces
|
||||
- Update `ParaInfo` type
|
||||
- Council should be optional in treasury derives
|
||||
- Allow extraction of session derives indexes with no staking
|
||||
|
||||
|
||||
## 4.2.1 Mar 22, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended when tracking the latest updates from Substrate.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Fix contract even decoding on Substrate 3 (Thanks to https://github.com/vminkov)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust `Extender{Header, SignedBlock}` types to ensure at-block `Header` types are used
|
||||
- Explicit definition for new Rococo triple refcount `AccountData` types
|
||||
- Convert metadata private class fields to ES-private
|
||||
- Adjust `SignedBlock` type for new `justifications` field
|
||||
- Optimize society derive for multi accounts
|
||||
- Bump metadata to latest substrate version
|
||||
|
||||
|
||||
## 4.1.1 Mar 15, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended when tracking the latest updates from Substrate.
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix author extraction for last block in a session
|
||||
- Expand `SignerPayload` to inject/expose custom signed extensions
|
||||
- `ConsensusEngineId` formats non-Ascii engines correctly
|
||||
- Allow `getBlock/Header` derives to use as-at registry (instead of latest)
|
||||
- Cleanup `RpcCore` augmentation (removing TS warnings on typegen chains)
|
||||
- Add upgrade block for Kusama 2029
|
||||
- Ensure that type alias overrides also apply to map keys
|
||||
- Check type generation against fallbacks (build-time only sanity check)
|
||||
- Add `mmr_generateProof` RPC
|
||||
- Align types with latest substrate master
|
||||
- Apply latest Polkadot auctions/crowdloan/parachains/slots types
|
||||
|
||||
|
||||
## 4.0.3 Mar 8, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended if you use the API to sync the full chain, most notably Polkadot.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Re-add unused historical `SudoBalances` to `ProxyType` (Thanks to https://github.com/emostov)
|
||||
|
||||
|
||||
## 4.0.2 Mar 8, 2021
|
||||
|
||||
Upgrade priority: High. Required if you are using 4.0.1 in a Node.js environment.
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix import from `@polkadot/x-rxjs` in Node environments (From common)
|
||||
- Add correct types for `Phase` is new validator elections module
|
||||
|
||||
|
||||
## 4.0.1 Mar 7, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users wanting to keep updated with chain changes.
|
||||
|
||||
**Important** In the 4.0 version the default package type has been changed to ESM modules by default. This should not affect usage, however since the output formats changed, a new major version is required.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Expose `unknownTypes` on the registry interface (Thanks to https://github.com/ii-ii-ii)
|
||||
|
||||
Changes:
|
||||
|
||||
- Build to ESM by default (with cjs versions via export map)
|
||||
- Enum `.toSON()` now encodes all keys as `camelCase` (aligning with the output from Substrate)
|
||||
- Add `createdAtHash?: Hash` to `Codec` interface (filled-in by storage retrievals)
|
||||
- Expose the source hash as `wamHash` on Abi parsed instances
|
||||
- Use `parentHash` when creating mortal era (handles frequent forks better)
|
||||
- Add `AccountInfoWithTripleRefCount` to cater for latest Substrate
|
||||
- Add upgrade block for Westend 49
|
||||
|
||||
|
||||
## 3.11.1 Feb 28, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users wanting to keep updated with chain changes.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Clean Websocket states on disconnects (Thanks to https://github.com/ianhe8x)
|
||||
- Support for C-like indexed enums (Thanks to https://github.com/xlc)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust council derives to cater for current-generation candidate mapping
|
||||
- Allow for override of codec hasher (& output type)
|
||||
- Adjust submittables to submit hex-encoded addresses to queries
|
||||
- Adjust initialization to always retrieve tx version from Metadata only
|
||||
- Update election types as per latest Substrate
|
||||
- Add types for the new gilt module
|
||||
- Upgrade to the latest Substrate metadata
|
||||
- Adjust package detection to check for local monorepo dependencies
|
||||
- Ensure that metadata `.toJSON()` does apply type aliasses
|
||||
|
||||
|
||||
## 3.10.2 Feb 23, 2021
|
||||
|
||||
Upgrade priority: Medium. Recommended for users of chains where `MultiAddress` is in-use and blocks are decoded.
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix decoding for `MultiAddress` enum where non-`AccountId` variable-lengths are provided as part of a stream
|
||||
- Added known Polkadot 28 upgrade block
|
||||
- Update for latest Substrate contracts `Schedule` types
|
||||
|
||||
|
||||
## 3.10.1 Feb 22, 2021
|
||||
|
||||
Upgrade priority: Low.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust ConsumedWeight types to align with Rust module code
|
||||
- Check for connection status in subscription unsubscribe
|
||||
- Adjust staking reward derives ordering for better performance
|
||||
- Adapt detection imports to remove `.json` dependencies (Better behavior using Node.js with ESM)
|
||||
|
||||
|
||||
## 3.9.3 Feb 16, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for parachain builders since it contains the updated parachain types.
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjusted parachain `PersistedValidationData` structure
|
||||
|
||||
|
||||
## 3.9.2 Feb 15, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for parachain builders since it contains the latest parachain types.
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
const config = require('@polkadot/dev/config/jest.cjs');
|
||||
|
||||
module.exports = Object.assign({}, config, {
|
||||
module.exports = {
|
||||
...config,
|
||||
moduleNameMapper: {
|
||||
'@polkadot/api-(contract|derive)(.*)$': '<rootDir>/packages/api-$1/src/$2',
|
||||
// eslint-disable-next-line sort-keys
|
||||
@@ -26,5 +27,5 @@ module.exports = Object.assign({}, config, {
|
||||
'<rootDir>/packages/types/build',
|
||||
'<rootDir>/packages/types-known/build'
|
||||
],
|
||||
resolver: '@polkadot/dev/config/jest-resolver.cjs'
|
||||
});
|
||||
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
|
||||
};
|
||||
+8
-8
@@ -8,7 +8,7 @@
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build:interfaces && polkadot-dev-build-ts",
|
||||
@@ -25,14 +25,14 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.13",
|
||||
"@babel/register": "^7.12.13",
|
||||
"@babel/runtime": "^7.12.13",
|
||||
"@polkadot/dev": "^0.61.25",
|
||||
"@polkadot/ts": "^0.3.59",
|
||||
"@babel/core": "^7.13.16",
|
||||
"@babel/register": "^7.13.16",
|
||||
"@babel/runtime": "^7.13.17",
|
||||
"@polkadot/dev": "^0.62.10",
|
||||
"@polkadot/ts": "^0.3.63",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/jest": "^26.0.22",
|
||||
"copyfiles": "^2.4.1"
|
||||
},
|
||||
"version": "3.9.2"
|
||||
"version": "4.7.2"
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Abi } from '@polkadot/api-contract';
|
||||
|
||||
const wsProvider = new WsProvider(<...Node Url...>);
|
||||
const api = await ApiPromise.create({ provider: wsProvider });
|
||||
const abi = new Abi(api.registry, <...JSON ABI...>);
|
||||
const abi = new Abi(<...JSON ABI...>, api.registry.getChainProperties());
|
||||
|
||||
api.tx.contracts
|
||||
.call(<contract addr>, <value>, <max gas>, abi.messages.<method name>(<...params...>))
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "3.9.2",
|
||||
"version": "4.7.2",
|
||||
"type": "module",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
@@ -12,11 +19,11 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.13",
|
||||
"@polkadot/api": "3.9.2",
|
||||
"@polkadot/types": "3.9.2",
|
||||
"@polkadot/util": "^5.6.2",
|
||||
"@polkadot/x-rxjs": "^5.6.2",
|
||||
"@babel/runtime": "^7.13.17",
|
||||
"@polkadot/api": "4.7.2",
|
||||
"@polkadot/types": "4.7.2",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { blake2AsHex } from '@polkadot/util-crypto';
|
||||
|
||||
import abis from '../test/contracts';
|
||||
import { Abi } from '.';
|
||||
|
||||
interface JSONAbi {
|
||||
source: {
|
||||
compiler: string,
|
||||
hash: string,
|
||||
language: string,
|
||||
wasm: string
|
||||
},
|
||||
spec: {
|
||||
messages: {
|
||||
name: string[] | string
|
||||
@@ -27,4 +35,18 @@ describe('Abi', (): void => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('has the correct hash for the source', (): void => {
|
||||
const bundle = abis.ink_flipperBundle as JSONAbi;
|
||||
const abi = new Abi(bundle as any);
|
||||
|
||||
// manual
|
||||
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
|
||||
|
||||
// the Codec hash
|
||||
expect(bundle.source.hash).toEqual(abi.project.source.wasm.hash.toHex());
|
||||
|
||||
// the hash as per the actual Abi
|
||||
expect(bundle.source.hash).toEqual(abi.project.source.wasmHash.toHex());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { ChainProperties, ContractConstructorSpec, ContractEventSpec, Contr
|
||||
import type { AnyJson, Codec, CodecArg } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from './types';
|
||||
|
||||
import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { assert, assertReturn, compactAddLength, compactStripLength, isNumber, isObject, isString, logger, stringCamelCase, stringify, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { MetaRegistry } from './MetaRegistry';
|
||||
|
||||
@@ -21,7 +21,7 @@ function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string
|
||||
? list.find(({ identifier }) => [identifier, stringCamelCase(identifier)].includes(messageOrId.toString()))
|
||||
: messageOrId;
|
||||
|
||||
return assertReturn(message, `Attempted to call an invalid contract interface, ${JSON.stringify(messageOrId)}`);
|
||||
return assertReturn(message, `Attempted to call an invalid contract interface, ${stringify(messageOrId)}`);
|
||||
}
|
||||
|
||||
export class Abi {
|
||||
@@ -81,7 +81,7 @@ export class Abi {
|
||||
const index = data[0];
|
||||
const event = this.#events[index];
|
||||
|
||||
assert(event, `Unable to find event with index ${index}`);
|
||||
assert(event, () => `Unable to find event with index ${index}`);
|
||||
|
||||
return event.fromU8a(data.subarray(1));
|
||||
}
|
||||
@@ -118,7 +118,7 @@ export class Abi {
|
||||
type: this.registry.getMetaTypeDef(arg.type)
|
||||
};
|
||||
} catch (error) {
|
||||
l.error(`Error expanding argument ${index} in ${JSON.stringify(spec)}`);
|
||||
l.error(`Error expanding argument ${index} in ${stringify(spec)}`);
|
||||
|
||||
throw error;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ export class Abi {
|
||||
}
|
||||
|
||||
#encodeArgs = ({ name, selector }: ContractMessageSpec | ContractConstructorSpec, args: AbiParam[], data: CodecArg[], additional = EMPTY_U8A): Uint8Array => {
|
||||
assert(data.length === args.length, `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`);
|
||||
assert(data.length === args.length, () => `Expected ${args.length} arguments to contract message '${name.toString()}', found ${data.length}`);
|
||||
|
||||
return compactAddLength(
|
||||
u8aConcat(
|
||||
|
||||
@@ -80,7 +80,7 @@ export class MetaRegistry extends TypeRegistry {
|
||||
#getMetaType = (id: SiLookupTypeId): SiType => {
|
||||
const type = this.#siTypes[getRegistryOffset(id)];
|
||||
|
||||
assert(!isUndefined(type), `getMetaType:: Unable to find ${id.toNumber()} in type values`);
|
||||
assert(!isUndefined(type), () => `getMetaType:: Unable to find ${id.toNumber()} in type values`);
|
||||
|
||||
return this.createType('SiType', type);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ export class MetaRegistry extends TypeRegistry {
|
||||
}
|
||||
|
||||
#extractSequence = ({ type }: SiTypeDefSequence, id: SiLookupTypeId): Omit<TypeDef, 'type'> => {
|
||||
assert(!!type, `ContractRegistry: Invalid sequence type found at id ${id.toString()}`);
|
||||
assert(!!type, () => `ContractRegistry: Invalid sequence type found at id ${id.toString()}`);
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Vec,
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import type { EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import type { EventRecord } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, CodecArg, ISubmittableResult } from '@polkadot/types/types';
|
||||
import type { AbiConstructor, BlueprintOptions } from '../types';
|
||||
import type { MapConstructorExec } from './types';
|
||||
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { ApiBase } from '@polkadot/api/base';
|
||||
import { assert, compactAddLength, isFunction, isUndefined, isWasm, stringCamelCase, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, compactAddLength, isFunction, isUndefined, isWasm, logger, stringCamelCase, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { Abi } from '../Abi';
|
||||
@@ -20,6 +20,8 @@ import { Blueprint } from './Blueprint';
|
||||
import { Contract } from './Contract';
|
||||
import { createBluePrintTx, EMPTY_SALT, encodeSalt } from './util';
|
||||
|
||||
const l = logger('Code');
|
||||
|
||||
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
public readonly blueprint?: Blueprint<ApiType>;
|
||||
public readonly contract?: Contract<ApiType>;
|
||||
@@ -55,18 +57,8 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Deploy the code bundle, creating a Blueprint.
|
||||
* @deprecated Use the `code.tx.<constructor>(...) format to put code and deploy
|
||||
*/
|
||||
public createBlueprint (): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> {
|
||||
return this.api.tx.contracts
|
||||
.putCode(compactAddLength(this.code))
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
new CodeSubmittableResult(result, applyOnEvent(result, ['CodeStored'], ([record]: EventRecord[]) =>
|
||||
new Blueprint<ApiType>(this.api, this.abi, record.event.data[0] as Hash, this._decorateMethod)
|
||||
))
|
||||
);
|
||||
public get tx (): MapConstructorExec<ApiType> {
|
||||
return this.#tx;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,26 +66,26 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
* @deprecated Use the `code.tx.<constructor>(...) format to put code and deploy
|
||||
*/
|
||||
public createContract (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> {
|
||||
return this.#instantiate(constructorOrId, options, params);
|
||||
}
|
||||
l.warn('.createContract is deprecated, use code.tx.<constructorName>(...) instead (where code refers to this instance)');
|
||||
|
||||
public get tx (): MapConstructorExec<ApiType> {
|
||||
return this.#tx;
|
||||
return this.#instantiate(constructorOrId, options, params);
|
||||
}
|
||||
|
||||
#instantiate = (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
return isFunction(this.api.tx.contracts.instantiateWithCode)
|
||||
? this.#instantiateSingle(constructorOrId, options, params)
|
||||
: this.#instantiateBatch(constructorOrId, options, params);
|
||||
? this.#instantiateCurrent(constructorOrId, options, params)
|
||||
: this.#instantiatePrev(constructorOrId, options, params);
|
||||
}
|
||||
|
||||
#instantiateSingle = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
#instantiateCurrent = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
return this.api.tx.contracts
|
||||
.instantiateWithCode(value, gasLimit, compactAddLength(this.code), this.abi.findConstructor(constructorOrId).toU8a(params), encodeSalt(salt))
|
||||
.withResultTransform(this.#transformEvents);
|
||||
}
|
||||
|
||||
#instantiateBatch = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
#instantiatePrev = (constructorOrId: AbiConstructor | string | number, { gasLimit = 0, salt, value = 0 }: BlueprintOptions, params: CodecArg[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
||||
assert(isFunction(this.api.tx.utility?.batch), 'Your chain does not include the utility pallet, for contracts v2 deployment, this is required');
|
||||
|
||||
const encodedSalt = encodeSalt(salt);
|
||||
const withSalt = this.api.tx.contracts.instantiate.meta.args.length === 5;
|
||||
const encoded = this.abi.findConstructor(constructorOrId).toU8a(params, withSalt ? EMPTY_SALT : encodedSalt);
|
||||
|
||||
@@ -23,6 +23,7 @@ import { Base } from './Base';
|
||||
// As per Rust, 5 * GAS_PER_SEC
|
||||
const MAX_CALL_GAS = new BN(5_000_000_000_000).subn(1);
|
||||
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
|
||||
|
||||
const l = logger('Contract');
|
||||
|
||||
function createQuery <ApiType extends ApiTypes> (fn: (origin: string | AccountId | Uint8Array, options: ContractOptions, params: CodecArg[]) => ContractCallResult<ApiType, ContractCallOutcome>): ContractQuery<ApiType> {
|
||||
@@ -39,11 +40,14 @@ function createTx <ApiType extends ApiTypes> (fn: (options: ContractOptions, par
|
||||
: fn(...extractOptions(options, params));
|
||||
}
|
||||
|
||||
function createWithId <T> (fn: (messageOrId: AbiMessage | string | number, options: ContractOptions, params: CodecArg[]) => T): ContractGeneric<ContractOptions, T> {
|
||||
return (messageOrId: AbiMessage | string | number, options: BigInt | string | number | BN | ContractOptions, ...params: CodecArg[]): T =>
|
||||
isOptions(options)
|
||||
function createWithId <T> (fn: (messageOrId: AbiMessage | string | number, options: ContractOptions, params: CodecArg[]) => T, warn?: string): ContractGeneric<ContractOptions, T> {
|
||||
return (messageOrId: AbiMessage | string | number, options: BigInt | string | number | BN | ContractOptions, ...params: CodecArg[]): T => {
|
||||
warn && l.warn(warn);
|
||||
|
||||
return isOptions(options)
|
||||
? fn(messageOrId, options, params)
|
||||
: fn(messageOrId, ...extractOptions(options, params));
|
||||
};
|
||||
}
|
||||
|
||||
export class ContractSubmittableResult extends SubmittableResult {
|
||||
@@ -109,8 +113,8 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.address = this.registry.createType('AccountId', address);
|
||||
this.exec = createWithId(this.#exec);
|
||||
this.read = createWithId(this.#read);
|
||||
this.exec = createWithId(this.#exec, '.exec is deprecated, use contract.tx.<messageName>(...) instead (where contract refers to this instance)');
|
||||
this.read = createWithId(this.#read, '.read is deprecated, use contract.query.<messageName>(...) instead (where contract refers to this instance)');
|
||||
|
||||
this.abi.messages.forEach((m): void => {
|
||||
const messageName = stringCamelCase(m.identifier);
|
||||
@@ -156,7 +160,8 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
return this.api.tx.contracts
|
||||
.call(this.address, value, this.#getGas(gasLimit), this.abi.findMessage(messageOrId).toU8a(params))
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
new ContractSubmittableResult(result, applyOnEvent(result, ['ContractExecution'], (records: EventRecord[]) =>
|
||||
// ContractEmitted is the current generation, ContractExecution is the previous generation
|
||||
new ContractSubmittableResult(result, applyOnEvent(result, ['ContractEmitted', 'ContractExecution'], (records: EventRecord[]) =>
|
||||
records
|
||||
.map(({ event: { data: [, data] } }): DecodedEvent | null => {
|
||||
try {
|
||||
|
||||
@@ -37,7 +37,9 @@ async function checkContract (api: ApiPromise, pairs: TestKeyringMap): Promise<v
|
||||
}
|
||||
|
||||
async function main (): Promise<void> {
|
||||
const api = await ApiPromise.create();
|
||||
const api = await ApiPromise.create({
|
||||
hasher: (data: Uint8Array): Uint8Array => data
|
||||
});
|
||||
const pairs = createTestPairs();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as apiInfo } from '@polkadot/api/packageInfo';
|
||||
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [apiInfo, typesInfo]);
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Abi } from './Abi';
|
||||
import './detectPackage';
|
||||
|
||||
export { Blueprint as BlueprintRx, Code as CodeRx, Contract as ContractRx } from './rx';
|
||||
export { Abi } from './Abi';
|
||||
export { packageInfo } from './packageInfo';
|
||||
export { Blueprint as BlueprintPromise, Code as CodePromise, Contract as ContractPromise } from './promise';
|
||||
export { Blueprint as BlueprintRx, Code as CodeRx, Contract as ContractRx } from './rx';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-contract', version: '4.7.2' };
|
||||
@@ -12,7 +12,7 @@ import BN from 'bn.js';
|
||||
import { createTypeUnsafe } from '@polkadot/types/create';
|
||||
import { isBigInt, isBn, isNumber, isString } from '@polkadot/util';
|
||||
|
||||
type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
|
||||
type ContractEvents = 'CodeStored' | 'ContractEmitted' | 'ContractExecution' | 'Instantiated';
|
||||
|
||||
type TOptions = BlueprintOptions | ContractOptions;
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"info": 6,
|
||||
"type": "bool"
|
||||
}
|
||||
]
|
||||
@@ -6,5 +6,6 @@ export { default as dns } from './dns.json';
|
||||
export { default as erc20 } from './erc20.json';
|
||||
export { default as erc721 } from './erc721.json';
|
||||
export { default as flipper } from './flipper.json';
|
||||
export { default as flipperBundle } from './flipper.contract.json';
|
||||
export { default as incrementer } from './incrementer.json';
|
||||
export { default as multisigPlain } from './multisig_plain.json';
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "3.9.2",
|
||||
"version": "4.7.2",
|
||||
"type": "module",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
@@ -12,17 +19,17 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.13",
|
||||
"@polkadot/api": "3.9.2",
|
||||
"@polkadot/rpc-core": "3.9.2",
|
||||
"@polkadot/types": "3.9.2",
|
||||
"@polkadot/util": "^5.6.2",
|
||||
"@polkadot/util-crypto": "^5.6.2",
|
||||
"@polkadot/x-rxjs": "^5.6.2",
|
||||
"@babel/runtime": "^7.13.17",
|
||||
"@polkadot/api": "4.7.2",
|
||||
"@polkadot/rpc-core": "4.7.2",
|
||||
"@polkadot/types": "4.7.2",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.6.2",
|
||||
"@polkadot/rpc-provider": "3.9.2"
|
||||
"@polkadot/keyring": "^6.3.1",
|
||||
"@polkadot/rpc-provider": "4.7.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ type BalanceResult = [Balance, Balance, Balance, Balance];
|
||||
|
||||
type Result = [Index, BalanceResult[]];
|
||||
|
||||
type DeriveCustomAccount = ApiInterfaceRx['derive'] & {
|
||||
[custom: string]: {
|
||||
customAccount?: ApiInterfaceRx['query']['balances']['account']
|
||||
}
|
||||
}
|
||||
|
||||
function getBalance (api: ApiInterfaceRx, [freeBalance, reservedBalance, frozenFee, frozenMisc]: BalanceResult): DeriveBalancesAccountData {
|
||||
return {
|
||||
freeBalance,
|
||||
@@ -55,7 +61,13 @@ function queryBalancesFree (api: ApiInterfaceRx, accountId: AccountId): Observab
|
||||
}
|
||||
|
||||
function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId, modules: string[] = ['balances']): Observable<Result> {
|
||||
const balances = modules.map((m): QueryableStorageMultiArg<'rxjs'> => [api.query[m].account, accountId]);
|
||||
const balances = modules.map(
|
||||
(m): QueryableStorageMultiArg<'rxjs'> => [
|
||||
(api.derive as DeriveCustomAccount)[m]?.customAccount || api.query[m].account,
|
||||
accountId
|
||||
]
|
||||
);
|
||||
|
||||
const extract = (data: AccountData[]) =>
|
||||
data.map(({ feeFrozen, free, miscFrozen, reserved }): BalanceResult => [free, reserved, feeFrozen, miscFrozen]);
|
||||
|
||||
@@ -75,9 +87,11 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
||||
const { feeFrozen, free, miscFrozen, reserved } = (infoOrTuple as AccountInfo).nonce
|
||||
? (infoOrTuple as AccountInfo).data
|
||||
: (infoOrTuple as [Index, AccountData])[1];
|
||||
const accountNonce = (infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0];
|
||||
|
||||
return [accountNonce, [[free, reserved, feeFrozen, miscFrozen]]];
|
||||
return [
|
||||
(infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0],
|
||||
[[free, reserved, feeFrozen, miscFrozen]]
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { DeriveBalancesAccount, DeriveBalancesAccountData, DeriveBalancesAl
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { bnMax } from '@polkadot/util';
|
||||
import { bnMax, isFunction } from '@polkadot/util';
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
@@ -27,6 +27,12 @@ interface AllLocked {
|
||||
vestingLocked: Balance
|
||||
}
|
||||
|
||||
type DeriveCustomLocks = ApiInterfaceRx['derive'] & {
|
||||
[custom: string]: {
|
||||
customLocks?: ApiInterfaceRx['query']['balances']['locks']
|
||||
}
|
||||
}
|
||||
|
||||
const VESTING_ID = '0x76657374696e6720';
|
||||
|
||||
function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (BalanceLock | BalanceLockTo212)[]): AllLocked {
|
||||
@@ -54,11 +60,10 @@ function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (Balan
|
||||
|
||||
function calcShared (api: ApiInterfaceRx, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (BalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
|
||||
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
|
||||
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data.freeBalance.sub(lockedBalance)));
|
||||
|
||||
return {
|
||||
...data,
|
||||
availableBalance,
|
||||
availableBalance: api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), data.freeBalance.sub(lockedBalance))),
|
||||
lockedBalance,
|
||||
lockedBreakdown,
|
||||
vestingLocked
|
||||
@@ -75,8 +80,6 @@ function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLock
|
||||
const vestedNow = isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : new BN(0);
|
||||
const vestedBalance = vestedNow.gt(vestingTotal) ? vestingTotal : api.registry.createType('Balance', vestedNow);
|
||||
const isVesting = isStarted && !shared.vestingLocked.isZero();
|
||||
const vestedClaimable = api.registry.createType('Balance', isVesting ? shared.vestingLocked.sub(vestingTotal.sub(vestedBalance)) : 0);
|
||||
const vestingEndBlock = api.registry.createType('BlockNumber', isVesting ? vestingTotal.div(perBlock).add(startingBlock) : 0);
|
||||
|
||||
return {
|
||||
...shared,
|
||||
@@ -85,8 +88,8 @@ function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLock
|
||||
additional: allLocks.filter((_, index) => index !== 0).map((l, index) => calcShared(api, bestNumber, data.additional[index], l)),
|
||||
isVesting,
|
||||
vestedBalance,
|
||||
vestedClaimable,
|
||||
vestingEndBlock,
|
||||
vestedClaimable: api.registry.createType('Balance', isVesting ? shared.vestingLocked.sub(vestingTotal.sub(vestedBalance)) : 0),
|
||||
vestingEndBlock: api.registry.createType('BlockNumber', isVesting ? vestingTotal.div(perBlock).add(startingBlock) : 0),
|
||||
vestingPerBlock: perBlock,
|
||||
vestingTotal
|
||||
};
|
||||
@@ -112,11 +115,17 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
|
||||
);
|
||||
}
|
||||
|
||||
const isNonNullable = <T>(nullable: T): nullable is NonNullable<T> => !!nullable;
|
||||
|
||||
// current (balances, vesting)
|
||||
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable<ResultBalance> {
|
||||
const lockCalls = balanceInstances.map((m) => api.query[m].locks);
|
||||
const lockCalls = balanceInstances.map(
|
||||
(m): ApiInterfaceRx['query']['balances']['locks'] | undefined =>
|
||||
(api.derive as DeriveCustomLocks)[m]?.customLocks || api.query[m as 'balances']?.locks
|
||||
);
|
||||
|
||||
const lockEmpty = lockCalls.map((c) => !c);
|
||||
const lockQueries = lockCalls.filter((c) => c).map((c): QueryableStorageMultiArg<'rxjs'> => [c, accountId]);
|
||||
const lockQueries = lockCalls.filter(isNonNullable).map((c): QueryableStorageMultiArg<'rxjs'> => [c, accountId]);
|
||||
|
||||
return (
|
||||
api.query.vesting?.vesting
|
||||
@@ -166,7 +175,7 @@ export function all (instanceId: string, api: ApiInterfaceRx): (address: Account
|
||||
? combineLatest([
|
||||
of(account),
|
||||
api.derive.chain.bestNumber(),
|
||||
api.query.system?.account || api.query.balances?.account
|
||||
isFunction(api.query.system?.account) || isFunction(api.query.balances?.account)
|
||||
? queryCurrent(api, account.accountId, balanceInstances)
|
||||
: queryOld(api, account.accountId)
|
||||
])
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('bounties derive', () => {
|
||||
let storageKey: (index: number) => StorageKey;
|
||||
let defaultBounty: () => Bounty;
|
||||
let emptyOption: <T extends Codec> (typeName: keyof InterfaceTypes) => Option<T>;
|
||||
let optionOf: <T extends Codec> (value: T)=> Option<T>;
|
||||
let optionOf: <T extends Codec> (value: T) => Option<T>;
|
||||
let bountyIndex: (index: number) => BountyIndex;
|
||||
let proposalIndex: (index: number) => ProposalIndex;
|
||||
let bytes: (value: string) => Bytes;
|
||||
|
||||
@@ -37,12 +37,16 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
|
||||
return memo(instanceId, (): Observable<DeriveBounties> =>
|
||||
combineLatest([
|
||||
bountyBase.bountyCount<BountyIndex>(),
|
||||
api.query.council ? api.query.council.proposalCount<ProposalIndex>() : of(0)
|
||||
api.query.council
|
||||
? api.query.council.proposalCount<ProposalIndex>()
|
||||
: of(0)
|
||||
]).pipe(
|
||||
switchMap(() =>
|
||||
combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
api.derive.council ? api.derive.council.proposals() : of([])
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
switchMap(([keys, proposals]): Observable<Result> => {
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { SignedBlockExtended } from '../type/types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { catchError, map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { SignedBlockExtended } from '../type';
|
||||
import { createSignedBlockExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([signedBlock, events, validators]): SignedBlockExtended =>
|
||||
new SignedBlockExtended(api.registry, signedBlock, events, validators)
|
||||
createSignedBlockExtended(api.registry, signedBlock, events, validators)
|
||||
),
|
||||
catchError((): Observable<undefined> =>
|
||||
// where rpc.chain.getHeader throws, we will land here - it can happen that
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { HeaderExtended } from '../type/types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { catchError, map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { createHeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
new HeaderExtended(api.registry, header, validators)
|
||||
createHeaderExtended(header.registry, header, validators)
|
||||
),
|
||||
catchError((): Observable<undefined> =>
|
||||
// where rpc.chain.getHeader throws, we will land here - it can happen that
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId, EventRecord, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import type { Vec } from '@polkadot/types';
|
||||
import type { EventRecord, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { HeaderExtended, SignedBlockExtended } from '../type/types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { SignedBlockExtended } from '../type';
|
||||
import { createSignedBlockExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
/**
|
||||
@@ -18,17 +20,17 @@ import { memo } from '../util';
|
||||
export function subscribeNewBlocks (instanceId: string, api: ApiInterfaceRx): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
api.derive.chain.subscribeNewHeads().pipe(
|
||||
switchMap((header): Observable<[SignedBlock, EventRecord[], AccountId[] | undefined]> => {
|
||||
const blockHash = header.hash;
|
||||
switchMap((header): Observable<[SignedBlock, Vec<EventRecord>, HeaderExtended]> => {
|
||||
const blockHash = header.createdAtHash || header.hash;
|
||||
|
||||
return combineLatest(
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
api.query.system.events.at(blockHash),
|
||||
of(header.validators)
|
||||
of(header)
|
||||
);
|
||||
}),
|
||||
map(([block, events, validators]) =>
|
||||
new SignedBlockExtended(api.registry, block, events, validators)
|
||||
map(([block, events, header]) =>
|
||||
createSignedBlockExtended(block.registry, block, events, header.validators)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { HeaderExtended } from '../type/types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { createHeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
/**
|
||||
@@ -29,10 +30,13 @@ export function subscribeNewHeads (instanceId: string, api: ApiInterfaceRx): ()
|
||||
api.rpc.chain.subscribeNewHeads(),
|
||||
api.query.session
|
||||
? api.query.session.validators()
|
||||
: of([])
|
||||
: of(undefined)
|
||||
]).pipe(
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
new HeaderExtended(api.registry, header, validators)
|
||||
)
|
||||
));
|
||||
map(([header, validators]): HeaderExtended => {
|
||||
header.createdAtHash = header.hash;
|
||||
|
||||
return createHeaderExtended(header.registry, header, validators);
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import { catchError, map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type Collective = 'council' | 'membership' | 'technicalCommittee';
|
||||
|
||||
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
|
||||
|
||||
function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
|
||||
@@ -29,7 +31,7 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive
|
||||
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
|
||||
}
|
||||
|
||||
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: 'council' | 'technicalCommittee' = 'council'): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> {
|
||||
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: Collective): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, (hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> =>
|
||||
(isFunction(api.query[section]?.proposals) && hashes.length
|
||||
? combineLatest<Result>([
|
||||
@@ -49,19 +51,19 @@ function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: 'coun
|
||||
);
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx, section: 'council' | 'technicalCommittee' = 'council'): () => Observable<DeriveCollectiveProposal[]> {
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx, section: Collective): () => Observable<DeriveCollectiveProposal[]> {
|
||||
const proposalsFrom = _proposalsFrom(instanceId, api, section);
|
||||
|
||||
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
|
||||
isFunction(api.query[section]?.proposals)
|
||||
? api.query[section].proposals().pipe(
|
||||
? api.query[section as 'council'].proposals().pipe(
|
||||
switchMap(proposalsFrom)
|
||||
)
|
||||
: of([] as DeriveCollectiveProposal[])
|
||||
);
|
||||
}
|
||||
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx, section: 'council' | 'technicalCommittee' = 'council'): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx, section: Collective): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
const proposalsFrom = _proposalsFrom(instanceId, api, section);
|
||||
|
||||
return memo(instanceId, (hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
|
||||
|
||||
@@ -10,9 +10,9 @@ import { proposal as collectiveProposal, proposals as collectiveProposals } from
|
||||
import { memo } from '../util';
|
||||
|
||||
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
return memo(instanceId, collectiveProposal(instanceId, api));
|
||||
return memo(instanceId, collectiveProposal(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, collectiveProposals(instanceId, api));
|
||||
return memo(instanceId, collectiveProposals(instanceId, api, 'council'));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||
return memo(instanceId, (): Observable<DeriveProposal[]> =>
|
||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||
isFunction(api.query.democracy?.publicProps) && isFunction(api.query.democracy?.preimages)
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
switchMap((proposals) =>
|
||||
combineLatest([
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as apiInfo } from '@polkadot/api/packageInfo';
|
||||
import { packageInfo as coreInfo } from '@polkadot/rpc-core/packageInfo';
|
||||
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [apiInfo, coreInfo, typesInfo]);
|
||||
@@ -15,16 +15,28 @@ import { memo } from '../util';
|
||||
// SeatHolder is current tuple is 2.x-era Substrate
|
||||
type Member = SeatHolder | ITuple<[AccountId, Balance]>;
|
||||
|
||||
type Candidate = AccountId | ITuple<[AccountId, Balance]>;
|
||||
|
||||
function isSeatHolder (value: Member): value is SeatHolder {
|
||||
return !Array.isArray(value);
|
||||
}
|
||||
|
||||
function isCandidateTuple (value: Candidate): value is ITuple<[AccountId, Balance]> {
|
||||
return Array.isArray(value);
|
||||
}
|
||||
|
||||
function getAccountTuple (value: Member): [AccountId, Balance] {
|
||||
return isSeatHolder(value)
|
||||
? [value.who, value.stake]
|
||||
: value;
|
||||
}
|
||||
|
||||
function getCandidate (value: Candidate): AccountId {
|
||||
return isCandidateTuple(value)
|
||||
? value[0]
|
||||
: value;
|
||||
}
|
||||
|
||||
function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [AccountId, Balance]): number {
|
||||
return balanceB.cmp(balanceA);
|
||||
}
|
||||
@@ -32,7 +44,7 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
|
||||
function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
||||
|
||||
return api.queryMulti<[Vec<AccountId>, Vec<AccountId>, Vec<Member>, Vec<Member>]>([
|
||||
return api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
|
||||
api.query.council.members,
|
||||
api.query[section].candidates,
|
||||
api.query[section].members,
|
||||
@@ -41,7 +53,7 @@ function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
|
||||
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
|
||||
candidacyBond: api.consts[section].candidacyBond as Balance,
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidates,
|
||||
candidates: candidates.map(getCandidate),
|
||||
desiredRunnersUp: api.consts[section].desiredRunnersUp as u32,
|
||||
desiredSeats: api.consts[section].desiredMembers as u32,
|
||||
members: members.length
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AnyFunction } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
@@ -14,6 +16,7 @@ import * as council from './council';
|
||||
import * as democracy from './democracy';
|
||||
import * as elections from './elections';
|
||||
import * as imOnline from './imOnline';
|
||||
import * as membership from './membership';
|
||||
import * as parachains from './parachains';
|
||||
import * as session from './session';
|
||||
import * as society from './society';
|
||||
@@ -22,9 +25,10 @@ import * as technicalCommittee from './technicalCommittee';
|
||||
import * as treasury from './treasury';
|
||||
import * as tx from './tx';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
export * from './type';
|
||||
|
||||
export const derive = { accounts, balances, bounties, chain, contracts, council, democracy, elections, imOnline, parachains, session, society, staking, technicalCommittee, treasury, tx };
|
||||
export const derive = { accounts, balances, bounties, chain, contracts, council, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
|
||||
|
||||
type DeriveSection<Section> = {
|
||||
[Method in keyof Section]: Section[Method] extends AnyFunction
|
||||
@@ -46,6 +50,7 @@ const deriveAvail: Record<string, string[]> = {
|
||||
democracy: ['democracy'],
|
||||
elections: ['electionsPhragmen', 'elections'],
|
||||
imOnline: ['imOnline'],
|
||||
membership: ['membership'],
|
||||
parachains: ['parachains', 'registrar'],
|
||||
session: ['session'],
|
||||
society: ['society'],
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './proposals';
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveCollectiveProposal } from '../types';
|
||||
|
||||
import { proposals as collectiveProposals } from '../collective';
|
||||
import { memo } from '../util';
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
|
||||
return memo(instanceId, collectiveProposals(instanceId, api, 'membership'));
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-derive', version: '4.7.2' };
|
||||
@@ -13,7 +13,7 @@ import { map } from '@polkadot/x-rxjs/operators';
|
||||
import { memo } from '../util';
|
||||
|
||||
// parse into Indexes
|
||||
function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorCount]: [EraIndex, Option<Moment>, EraIndex, SessionIndex, u32]): DeriveSessionIndexes {
|
||||
function parse ([currentIndex, activeEra, activeEraStart, currentEra, validatorCount]: [SessionIndex, EraIndex, Option<Moment>, EraIndex, u32]): DeriveSessionIndexes {
|
||||
return {
|
||||
activeEra,
|
||||
activeEraStart,
|
||||
@@ -24,42 +24,57 @@ function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorC
|
||||
}
|
||||
|
||||
// query based on latest
|
||||
function query (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return api.queryMulti<[Option<ActiveEraInfo>, Option<EraIndex>, SessionIndex, u32]>([
|
||||
function queryStaking (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return api.queryMulti<[SessionIndex, Option<ActiveEraInfo>, Option<EraIndex>, u32]>([
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.currentEra,
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.validatorCount
|
||||
]).pipe(
|
||||
map(([activeOpt, currentEra, currentIndex, validatorCount]): DeriveSessionIndexes => {
|
||||
map(([currentIndex, activeOpt, currentEra, validatorCount]): DeriveSessionIndexes => {
|
||||
const { index, start } = activeOpt.unwrapOrDefault();
|
||||
|
||||
return parse([
|
||||
currentIndex,
|
||||
index,
|
||||
start,
|
||||
currentEra.unwrapOrDefault(),
|
||||
currentIndex,
|
||||
validatorCount
|
||||
]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// query based on latest
|
||||
function querySession (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return api.query.session.currentIndex().pipe(
|
||||
map((currentIndex): DeriveSessionIndexes => parse([
|
||||
currentIndex,
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('Option<Moment>'),
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('u32')
|
||||
]))
|
||||
);
|
||||
}
|
||||
|
||||
// empty set when none is available
|
||||
function empty (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return of(parse([
|
||||
api.registry.createType('SessionIndex', 1),
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('Option<Moment>'),
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('SessionIndex', 1),
|
||||
api.registry.createType('u32')
|
||||
]));
|
||||
}
|
||||
|
||||
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionIndexes> =>
|
||||
api.query.session && api.query.staking
|
||||
? query(api)
|
||||
api.query.session
|
||||
? api.query.staking
|
||||
? queryStaking(api)
|
||||
: querySession(api)
|
||||
: empty(api)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,71 +2,31 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { u64 } from '@polkadot/types';
|
||||
import type { SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveSessionIndexes, DeriveSessionInfo } from '../types';
|
||||
import type { DeriveSessionInfo } from '../types';
|
||||
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type ResultType = [boolean, u64, SessionIndex];
|
||||
type Result = [ResultType, DeriveSessionIndexes];
|
||||
|
||||
function createDerive (api: ApiInterfaceRx, [[hasBabe, epochDuration, sessionsPerEra], { activeEra, activeEraStart, currentEra, currentIndex, validatorCount }]: Result): DeriveSessionInfo {
|
||||
return {
|
||||
activeEra,
|
||||
activeEraStart,
|
||||
currentEra,
|
||||
currentIndex,
|
||||
eraLength: api.registry.createType('BlockNumber', sessionsPerEra.mul(epochDuration)),
|
||||
isEpoch: hasBabe,
|
||||
sessionLength: epochDuration,
|
||||
sessionsPerEra,
|
||||
validatorCount
|
||||
};
|
||||
}
|
||||
|
||||
function queryAura (api: ApiInterfaceRx): Observable<DeriveSessionInfo> {
|
||||
return api.derive.session.indexes().pipe(
|
||||
map((indexes): DeriveSessionInfo =>
|
||||
createDerive(api, [
|
||||
[
|
||||
false,
|
||||
api.registry.createType('u64', 1),
|
||||
// we may have aura without staking (permissioned)
|
||||
api.consts.staking?.sessionsPerEra || api.registry.createType('SessionIndex', 1)
|
||||
],
|
||||
indexes
|
||||
])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function queryBabe (api: ApiInterfaceRx): Observable<DeriveSessionInfo> {
|
||||
return api.derive.session.indexes().pipe(
|
||||
map((indexes) =>
|
||||
createDerive(api, [
|
||||
[
|
||||
true,
|
||||
api.consts.babe.epochDuration,
|
||||
// we may have babe without staking (permissioned)
|
||||
api.consts.staking?.sessionsPerEra || api.registry.createType('SessionIndex', 1)
|
||||
],
|
||||
indexes
|
||||
])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionInfo> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionInfo> =>
|
||||
api.consts.babe
|
||||
? queryBabe(api)
|
||||
: queryAura(api)
|
||||
api.derive.session.indexes().pipe(
|
||||
map((indexes) => {
|
||||
const sessionLength = api.consts?.babe?.epochDuration || api.registry.createType('u64', 1);
|
||||
const sessionsPerEra = api.consts?.staking?.sessionsPerEra || api.registry.createType('SessionIndex', 1);
|
||||
|
||||
return {
|
||||
...indexes,
|
||||
eraLength: api.registry.createType('BlockNumber', sessionsPerEra.mul(sessionLength)),
|
||||
isEpoch: !!api.query.babe,
|
||||
sessionLength,
|
||||
sessionsPerEra
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultS
|
||||
combineLatest([
|
||||
of(info),
|
||||
// we may have no staking, but have babe (permissioned)
|
||||
api.query.staking
|
||||
api.query.staking?.erasStartSessionIndex
|
||||
? api.queryMulti<ResultSlots>([
|
||||
api.query.babe.currentSlot,
|
||||
api.query.babe.epochIndex,
|
||||
@@ -69,7 +69,7 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultS
|
||||
*/
|
||||
export function progress (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionProgress> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionProgress> =>
|
||||
api.consts.babe
|
||||
api.query.babe
|
||||
? queryBabe(api).pipe(
|
||||
map(([info, slots]: [DeriveSessionInfo, ResultSlotsFlat]): DeriveSessionProgress =>
|
||||
createDerive(api, info, slots)
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { bool, Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, Balance, BlockNumber, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveSocietyMember } from '../types';
|
||||
|
||||
@@ -12,28 +10,13 @@ import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type Result = [Vec<ITuple<[BlockNumber, Balance]>>, StrikeCount, Option<SocietyVote>, bool, Option<VouchingStatus>];
|
||||
|
||||
/**
|
||||
* @description Get the member info for a society
|
||||
*/
|
||||
export function member (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
||||
return memo(instanceId, (accountId: AccountId): Observable<DeriveSocietyMember> =>
|
||||
api.queryMulti<Result>([
|
||||
[api.query.society.payouts, accountId],
|
||||
[api.query.society.strikes, accountId],
|
||||
[api.query.society.defenderVotes, accountId],
|
||||
[api.query.society.suspendedMembers, accountId],
|
||||
[api.query.society.vouching, accountId]
|
||||
]).pipe(
|
||||
map(([payouts, strikes, defenderVotes, suspended, vouching]: Result): DeriveSocietyMember => ({
|
||||
accountId,
|
||||
isSuspended: suspended.isTrue,
|
||||
payouts,
|
||||
strikes,
|
||||
vote: defenderVotes.unwrapOr(undefined),
|
||||
vouching: vouching.unwrapOr(undefined)
|
||||
}))
|
||||
api.derive.society._members([accountId]).pipe(
|
||||
map(([result]) => result)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,28 +2,51 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { bool, Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, Balance, BlockNumber, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveSocietyMember } from '../types';
|
||||
|
||||
import { combineLatest } from '@polkadot/x-rxjs';
|
||||
import { switchMap } from '@polkadot/x-rxjs/operators';
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type Result = [AccountId[], Vec<ITuple<[BlockNumber, Balance]>>[], StrikeCount[], Option<SocietyVote>[], bool[], Option<VouchingStatus>[]];
|
||||
|
||||
export function _members (instanceId: string, api: ApiInterfaceRx): (accountIds: AccountId[]) => Observable<DeriveSocietyMember[]> {
|
||||
return memo(instanceId, (accountIds: AccountId[]): Observable<DeriveSocietyMember[]> =>
|
||||
combineLatest<Result>([
|
||||
of(accountIds),
|
||||
api.query.society.payouts.multi(accountIds),
|
||||
api.query.society.strikes.multi(accountIds),
|
||||
api.query.society.defenderVotes.multi(accountIds),
|
||||
api.query.society.suspendedMembers.multi(accountIds),
|
||||
api.query.society.vouching.multi(accountIds)
|
||||
]).pipe(
|
||||
map(([accountIds, payouts, strikes, defenderVotes, suspended, vouching]) =>
|
||||
accountIds.map((accountId, index) => ({
|
||||
accountId,
|
||||
isDefenderVoter: defenderVotes[index].isSome,
|
||||
isSuspended: suspended[index].isTrue,
|
||||
payouts: payouts[index],
|
||||
strikes: strikes[index],
|
||||
vote: defenderVotes[index].unwrapOr(undefined),
|
||||
vouching: vouching[index].unwrapOr(undefined)
|
||||
}))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the member info for a society
|
||||
*/
|
||||
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSocietyMember[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyMember[]> =>
|
||||
api.query.society.members<AccountId[]>().pipe(
|
||||
switchMap((members): Observable<DeriveSocietyMember[]> =>
|
||||
combineLatest(
|
||||
members.map((accountId): Observable<DeriveSocietyMember> =>
|
||||
api.derive.society.member(accountId)
|
||||
)
|
||||
)
|
||||
)
|
||||
switchMap((members) => api.derive.society._members(members))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { StorageKey } from '@polkadot/types';
|
||||
import type { EraIndex, Exposure } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, EraIndex, Exposure } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
@@ -12,7 +12,7 @@ import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
|
||||
type KeysAndExposures = [StorageKey, Exposure][];
|
||||
type KeysAndExposures = [StorageKey<[EraIndex, AccountId]>, Exposure][];
|
||||
|
||||
const CACHE_KEY = 'eraExposure';
|
||||
|
||||
|
||||
@@ -1,55 +1,37 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '@polkadot/api/types';
|
||||
import type { EraIndex, Exposure } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveOwnExposure } from '../types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { memo } from '../util';
|
||||
|
||||
const CACHE_KEY = 'ownExposure';
|
||||
|
||||
export function _ownExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex, withActive: boolean) => Observable<DeriveOwnExposure> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex, withActive: boolean): Observable<DeriveOwnExposure> => {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}-${accountId.toString()}`;
|
||||
const cached = withActive
|
||||
? undefined
|
||||
: deriveCache.get<DeriveOwnExposure>(cacheKey);
|
||||
|
||||
return cached
|
||||
? of(cached)
|
||||
: api.queryMulti<[Exposure, Exposure]>([
|
||||
[api.query.staking.erasStakersClipped, [era, accountId]],
|
||||
[api.query.staking.erasStakers, [era, accountId]]
|
||||
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<Exposure[]>([
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakersClipped, [era, accountId]]),
|
||||
...eras.map((era): QueryableStorageMultiArg<'rxjs'> => [api.query.staking.erasStakers, [era, accountId]])
|
||||
]).pipe(
|
||||
map(([clipped, exposure]): DeriveOwnExposure => {
|
||||
const value = { clipped, era, exposure };
|
||||
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
})
|
||||
);
|
||||
});
|
||||
map((all): DeriveOwnExposure[] =>
|
||||
eras.map((era, index) => ({ clipped: all[index], era, exposure: all[eras.length + index] }))
|
||||
)
|
||||
)
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
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._ownExposure(accountId, era, true)
|
||||
);
|
||||
}
|
||||
|
||||
export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveOwnExposure[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveOwnExposure[]> =>
|
||||
eras.length
|
||||
? combineLatest(
|
||||
eras.map((era) => api.derive.staking._ownExposure(accountId, era, withActive))
|
||||
)
|
||||
: of([])
|
||||
api.derive.staking._ownExposures(accountId, [era], true).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,62 +1,44 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '@polkadot/api/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveStakerSlashes } from '../types';
|
||||
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { deriveCache, memo } from '../util';
|
||||
import { memo } from '../util';
|
||||
|
||||
const CACHE_KEY = 'ownSlash';
|
||||
|
||||
export function _ownSlash (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, era: EraIndex, withActive: boolean) => Observable<DeriveStakerSlashes> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, era: EraIndex, withActive: boolean): Observable<DeriveStakerSlashes> => {
|
||||
const cacheKey = `${CACHE_KEY}-${era.toString()}-${accountId.toString()}`;
|
||||
const cached = withActive
|
||||
? undefined
|
||||
: deriveCache.get<DeriveStakerSlashes>(cacheKey);
|
||||
|
||||
return cached
|
||||
? of(cached)
|
||||
: api.queryMulti<[Option<BalanceOf>, Option<ITuple<[Perbill, BalanceOf]>>]>([
|
||||
[api.query.staking.nominatorSlashInEra, [era, accountId]],
|
||||
[api.query.staking.validatorSlashInEra, [era, accountId]]
|
||||
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]])
|
||||
]).pipe(
|
||||
map(([optNom, optVal]): DeriveStakerSlashes => {
|
||||
const value = {
|
||||
map((values): DeriveStakerSlashes[] =>
|
||||
eras.map((era, index) => ({
|
||||
era,
|
||||
total: optVal.isSome
|
||||
? optVal.unwrap()[1]
|
||||
: optNom.unwrapOrDefault()
|
||||
};
|
||||
|
||||
!withActive && deriveCache.set(cacheKey, value);
|
||||
|
||||
return value;
|
||||
})
|
||||
);
|
||||
});
|
||||
total: values[index].isSome
|
||||
? (values[index].unwrap() as ITuple<[Perbill, BalanceOf]>)[1]
|
||||
: (values[index + eras.length].unwrapOrDefault() as BalanceOf)
|
||||
}))
|
||||
)
|
||||
)
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
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._ownSlash(accountId, era, true)
|
||||
);
|
||||
}
|
||||
|
||||
export function _ownSlashes (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[]> =>
|
||||
eras.length
|
||||
? combineLatest(
|
||||
eras.map((era) => api.derive.staking._ownSlash(accountId, era, withActive))
|
||||
)
|
||||
: of([])
|
||||
api.derive.staking._ownSlashes(accountId, [era], true).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,36 +10,46 @@ import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function _stakerExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerExposure[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable<DeriveStakerExposure[]> => {
|
||||
const stakerId = api.registry.createType('AccountId', accountId).toString();
|
||||
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[][]> => {
|
||||
const stakerIds = accountIds.map((a) => api.registry.createType('AccountId', a).toString());
|
||||
|
||||
return api.derive.staking._erasExposure(eras, withActive).pipe(
|
||||
map((exposures): DeriveStakerExposure[] =>
|
||||
exposures.map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerExposure => {
|
||||
const isValidator = !!allValidators[stakerId];
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
const nominating = allNominators[stakerId] || [];
|
||||
map((exposures): DeriveStakerExposure[][] =>
|
||||
stakerIds.map((stakerId) =>
|
||||
exposures.map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerExposure => {
|
||||
const isValidator = !!allValidators[stakerId];
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
const nominating = allNominators[stakerId] || [];
|
||||
|
||||
if (isValidator) {
|
||||
validators[stakerId] = allValidators[stakerId];
|
||||
} else if (nominating) {
|
||||
nominating.forEach(({ validatorId }): void => {
|
||||
validators[validatorId] = allValidators[validatorId];
|
||||
});
|
||||
}
|
||||
if (isValidator) {
|
||||
validators[stakerId] = allValidators[stakerId];
|
||||
} else if (nominating) {
|
||||
nominating.forEach(({ validatorId }): void => {
|
||||
validators[validatorId] = allValidators[validatorId];
|
||||
});
|
||||
}
|
||||
|
||||
return { era, isEmpty: !Object.keys(validators).length, isValidator, nominating, validators };
|
||||
})
|
||||
return { era, isEmpty: !Object.keys(validators).length, isValidator, nominating, validators };
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function stakerExposure (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean) => Observable<DeriveStakerExposure[]> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, withActive = false): Observable<DeriveStakerExposure[]> =>
|
||||
export function stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable<DeriveStakerExposure[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], withActive = false): Observable<DeriveStakerExposure[][]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerExposure(accountId, eras, withActive))
|
||||
switchMap((eras) => api.derive.staking._stakerExposures(accountIds, eras, withActive))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,25 +2,22 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId, EraIndex, StakingLedger, StakingLedgerTo240 } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, EraIndex, StakingLedger } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveEraPoints, DeriveEraPrefs, DeriveEraRewards, DeriveEraValPrefs, DeriveStakerExposure, DeriveStakerReward, DeriveStakerRewardValidator } from '../types';
|
||||
import type { DeriveStakingQuery } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { BN_BILLION, BN_ZERO, isFunction } from '@polkadot/util';
|
||||
import { BN_BILLION, BN_ZERO } from '@polkadot/util';
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type ErasResult = [{ unwrapOr: (value: BN) => BN }, DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
|
||||
type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
|
||||
|
||||
const MIN_ONE = new BN(-1);
|
||||
|
||||
function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
|
||||
function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
|
||||
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
|
||||
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} };
|
||||
const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') };
|
||||
@@ -71,32 +68,25 @@ function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, e
|
||||
});
|
||||
}
|
||||
|
||||
function uniqValidators (rewards: DeriveStakerReward[]): string[] {
|
||||
const uniq: string[] = [];
|
||||
function allUniqValidators (rewards: DeriveStakerReward[][]): [string[], string[][]] {
|
||||
return rewards.reduce(([all, perStash]: [string[], string[][]], rewards) => {
|
||||
const uniq: string[] = [];
|
||||
|
||||
rewards.forEach(({ validators }): void => {
|
||||
Object.keys(validators).forEach((validatorId): void => {
|
||||
if (!uniq.includes(validatorId)) {
|
||||
uniq.push(validatorId);
|
||||
}
|
||||
});
|
||||
});
|
||||
perStash.push(uniq);
|
||||
rewards.forEach(({ validators }) =>
|
||||
Object.keys(validators).forEach((validatorId): void => {
|
||||
if (!uniq.includes(validatorId)) {
|
||||
uniq.push(validatorId);
|
||||
|
||||
return uniq;
|
||||
}
|
||||
if (!all.includes(validatorId)) {
|
||||
all.push(validatorId);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
function isOldLedger (ledger?: StakingLedger | StakingLedgerTo240): ledger is StakingLedgerTo240 {
|
||||
return !!(ledger as StakingLedgerTo240)?.lastReward;
|
||||
}
|
||||
|
||||
function filterEra (era: EraIndex, stakingLedger: StakingLedger): boolean {
|
||||
return isOldLedger(stakingLedger)
|
||||
? era.gt(stakingLedger.lastReward.unwrapOr(MIN_ONE))
|
||||
: !stakingLedger.claimedRewards.some((e) => e.eq(era));
|
||||
}
|
||||
|
||||
function filterEras (eras: EraIndex[], stakingLedger: StakingLedger): EraIndex[] {
|
||||
return eras.filter((era) => filterEra(era, stakingLedger));
|
||||
return [all, perStash];
|
||||
}, [[], []]);
|
||||
}
|
||||
|
||||
function removeClaimed (validators: string[], queryValidators: DeriveStakingQuery[], reward: DeriveStakerReward): void {
|
||||
@@ -119,43 +109,34 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
|
||||
});
|
||||
}
|
||||
|
||||
function filterRewards (api: ApiInterfaceRx, eras: EraIndex[], { migrateEra, rewards, stakingLedger }: { migrateEra: BN, rewards: DeriveStakerReward[]; stakingLedger: StakingLedger }): Observable<DeriveStakerReward[]> {
|
||||
const validators = uniqValidators(rewards);
|
||||
const filter = filterEras(eras, stakingLedger);
|
||||
function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][], { rewards, stakingLedger }: { rewards: DeriveStakerReward[]; stakingLedger: StakingLedger }): DeriveStakerReward[] {
|
||||
const filter = eras.filter((era) => !stakingLedger.claimedRewards.some((e) => e.eq(era)));
|
||||
const validators = valInfo.map(([v]) => v);
|
||||
const queryValidators = valInfo.map(([, q]) => q);
|
||||
|
||||
return api.derive.staking.queryMulti(validators, { withLedger: true }).pipe(
|
||||
map((queryValidators): DeriveStakerReward[] =>
|
||||
rewards
|
||||
.filter(({ isEmpty }) => !isEmpty)
|
||||
.filter((reward): boolean => {
|
||||
if (!filter.some((filter) => reward.era.eq(filter))) {
|
||||
return false;
|
||||
} else if (reward.era.lt(migrateEra)) {
|
||||
// we filter again here, the actual ledger may have changed, e.g. something has been claimed
|
||||
return filterEra(reward.era, stakingLedger);
|
||||
}
|
||||
return rewards
|
||||
.filter(({ isEmpty }) => !isEmpty)
|
||||
.filter((reward): boolean => {
|
||||
if (!filter.some((filter) => reward.era.eq(filter))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
reward.isStakerPayout = true;
|
||||
reward.isStakerPayout = true;
|
||||
|
||||
removeClaimed(validators, queryValidators, reward);
|
||||
removeClaimed(validators, queryValidators, reward);
|
||||
|
||||
return true;
|
||||
})
|
||||
.filter(({ validators }) => Object.keys(validators).length !== 0)
|
||||
.map((reward) => ({
|
||||
...reward,
|
||||
nominators: reward.nominating.filter((n) => reward.validators[n.validatorId])
|
||||
}))
|
||||
)
|
||||
);
|
||||
return true;
|
||||
})
|
||||
.filter(({ validators }) => Object.keys(validators).length !== 0)
|
||||
.map((reward) => ({
|
||||
...reward,
|
||||
nominators: reward.nominating.filter((n) => reward.validators[n.validatorId])
|
||||
}));
|
||||
}
|
||||
|
||||
export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable<ErasResult> {
|
||||
return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable<ErasResult> =>
|
||||
combineLatest([
|
||||
isFunction(api.query.staking.migrateEra)
|
||||
? api.query.staking.migrateEra<Option<EraIndex>>()
|
||||
: of(api.registry.createType('Option<EraIndex>')),
|
||||
api.derive.staking._erasPoints(eras, withActive),
|
||||
api.derive.staking._erasPrefs(eras, withActive),
|
||||
api.derive.staking._erasRewards(eras, withActive)
|
||||
@@ -163,23 +144,39 @@ export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (e
|
||||
);
|
||||
}
|
||||
|
||||
export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable<DeriveStakerReward[]> {
|
||||
return memo(instanceId, (accountId: 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: boolean): Observable<DeriveStakerReward[][]> =>
|
||||
combineLatest([
|
||||
api.derive.staking.query(accountId, { withLedger: true }),
|
||||
api.derive.staking._stakerExposure(accountId, eras, withActive),
|
||||
api.derive.staking.queryMulti(accountIds, { withLedger: true }),
|
||||
api.derive.staking._stakerExposures(accountIds, eras, withActive),
|
||||
api.derive.staking._stakerRewardsEras(eras, withActive)
|
||||
]).pipe(
|
||||
switchMap(([{ stakingLedger, stashId }, exposures, erasResult]): Observable<DeriveStakerReward[]> => {
|
||||
if (!stashId || !stakingLedger) {
|
||||
return of([]);
|
||||
switchMap(([queries, exposures, erasResult]): Observable<DeriveStakerReward[][]> => {
|
||||
const allRewards = queries.map(({ stakingLedger, stashId }, index): DeriveStakerReward[] =>
|
||||
(!stashId || !stakingLedger)
|
||||
? []
|
||||
: parseRewards(api, stashId, erasResult, exposures[index])
|
||||
);
|
||||
|
||||
if (withActive) {
|
||||
return of(allRewards);
|
||||
}
|
||||
|
||||
const rewards = parseRewards(api, stashId, erasResult, exposures);
|
||||
const [allValidators, stashValidators] = allUniqValidators(allRewards);
|
||||
|
||||
return withActive
|
||||
? of(rewards)
|
||||
: filterRewards(api, eras, { migrateEra: erasResult[0].unwrapOr(BN_ZERO), rewards, stakingLedger });
|
||||
return api.derive.staking.queryMulti(allValidators, { withLedger: true }).pipe(
|
||||
map((queriedVals): DeriveStakerReward[][] => {
|
||||
return queries.map(({ stakingLedger }, index): DeriveStakerReward[] => {
|
||||
const rewards = allRewards[index];
|
||||
const ownValidators = stashValidators[index].map((validatorId): [string, DeriveStakingQuery] => [
|
||||
validatorId,
|
||||
queriedVals.find((q) => q.accountId.eq(validatorId)) as DeriveStakingQuery
|
||||
]);
|
||||
|
||||
return filterRewards(eras, ownValidators, { rewards, stakingLedger });
|
||||
});
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
@@ -188,7 +185,8 @@ 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[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking._stakerRewards(accountId, eras, withActive))
|
||||
switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive)),
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -196,7 +194,7 @@ export function stakerRewards (instanceId: string, api: ApiInterfaceRx): (accoun
|
||||
export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> =>
|
||||
accountIds.length && eras.length
|
||||
? combineLatest(accountIds.map((acc) => api.derive.staking._stakerRewards(acc, eras, false)))
|
||||
? api.derive.staking._stakerRewards(accountIds, eras, false)
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,16 +5,41 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
import { map, startWith, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
function onBondedEvent (api: ApiInterfaceRx): Observable<number> {
|
||||
let current = Date.now();
|
||||
|
||||
return api.query.system.events().pipe(
|
||||
map((events): number => {
|
||||
current = events.filter(({ event, phase }): boolean => {
|
||||
try {
|
||||
return phase.isApplyExtrinsic &&
|
||||
event.section === 'staking' &&
|
||||
event.method === 'Bonded';
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
? Date.now()
|
||||
: current;
|
||||
|
||||
return current;
|
||||
}),
|
||||
startWith(current),
|
||||
drr({ skipTimeout: true })
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve the list of all validator stashes
|
||||
*/
|
||||
export function stashes (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, (): Observable<AccountId[]> =>
|
||||
api.query.staking.validators.keys().pipe(
|
||||
onBondedEvent(api).pipe(
|
||||
switchMap(() => api.query.staking.validators.keys()),
|
||||
map((keys) => keys.map(({ args: [validatorId] }) => validatorId).filter((a) => a))
|
||||
)
|
||||
);
|
||||
|
||||
@@ -61,7 +61,9 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a
|
||||
|
||||
return combineLatest([
|
||||
api.query.treasury.proposals.multi<Option<TreasuryProposal>>(allIds),
|
||||
api.derive.council.proposals()
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([] as DeriveCollectiveProposal[])
|
||||
]).pipe(
|
||||
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DeriveCollectiveProposal[]]): DeriveTreasuryProposals =>
|
||||
parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount })
|
||||
|
||||
@@ -33,10 +33,19 @@ function nextNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
|
||||
function signingHeader (api: ApiInterfaceRx): Observable<Header> {
|
||||
return combineLatest([
|
||||
api.rpc.chain.getHeader(),
|
||||
api.rpc.chain.getFinalizedHead().pipe(
|
||||
switchMap((hash) => api.rpc.chain.getHeader(hash))
|
||||
)
|
||||
api.rpc.chain.getFinalizedHead()
|
||||
]).pipe(
|
||||
switchMap(([bestHeader, finHash]) =>
|
||||
// retrieve the headers - in the case of the current block, we use the parent
|
||||
// to minimize (not completely remove) the impact that forks do have on the system
|
||||
// (when at genesis, just return the current header as the last known)
|
||||
bestHeader.parentHash.isEmpty
|
||||
? of([bestHeader, bestHeader])
|
||||
: combineLatest([
|
||||
api.rpc.chain.getHeader(bestHeader.parentHash),
|
||||
api.rpc.chain.getHeader(finHash)
|
||||
])
|
||||
),
|
||||
map(([current, finalized]) =>
|
||||
// determine the hash to use, current when lag > max, else finalized
|
||||
current.number.unwrap().sub(finalized.number.unwrap()).gt(MAX_FINALITY_LAG)
|
||||
|
||||
@@ -2,43 +2,41 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId, Header } from '@polkadot/types/interfaces';
|
||||
import type { Constructor, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { Struct } from '@polkadot/types';
|
||||
import runtimeTypes from '@polkadot/types/interfaces/runtime/definitions';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { HeaderExtended } from './types';
|
||||
|
||||
import { extractAuthor } from './util';
|
||||
|
||||
// We can ignore the properties, added via Struct.with
|
||||
const _Header = Struct.with(runtimeTypes.types.Header as any) as Constructor<Header>;
|
||||
export function createHeaderExtended (registry: Registry, header?: Header, validators?: AccountId[]): HeaderExtended {
|
||||
// an instance of the base extrinsic for us to extend
|
||||
const HeaderBase = registry.createClass('Header');
|
||||
|
||||
/**
|
||||
* @name HeaderExtended
|
||||
* @description
|
||||
* A [[Block]] header with an additional `author` field that indicates the block author
|
||||
*/
|
||||
export class HeaderExtended extends _Header {
|
||||
readonly #author?: AccountId;
|
||||
readonly #validators?: AccountId[];
|
||||
class Implementation extends HeaderBase implements HeaderExtended {
|
||||
readonly #author?: AccountId;
|
||||
readonly #validators?: AccountId[];
|
||||
|
||||
constructor (registry: Registry, header?: Header, validators?: AccountId[]) {
|
||||
super(registry, header);
|
||||
constructor (registry: Registry, header?: Header, validators?: AccountId[]) {
|
||||
super(registry, header);
|
||||
|
||||
this.#author = extractAuthor(this.digest, validators);
|
||||
this.#validators = validators;
|
||||
this.#author = extractAuthor(this.digest, validators);
|
||||
this.#validators = validators;
|
||||
this.createdAtHash = header?.createdAtHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the author for the block
|
||||
*/
|
||||
public get author (): AccountId | undefined {
|
||||
return this.#author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the validators for the block
|
||||
*/
|
||||
public get validators (): AccountId[] | undefined {
|
||||
return this.#validators;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the author for the block
|
||||
*/
|
||||
public get author (): AccountId | undefined {
|
||||
return this.#author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the validators for the block
|
||||
*/
|
||||
public get validators (): AccountId[] | undefined {
|
||||
return this.#validators;
|
||||
}
|
||||
return new Implementation(registry, header, validators);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId, DispatchError, DispatchInfo, Event, EventRecord, Extrinsic, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import type { Constructor, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { Struct } from '@polkadot/types';
|
||||
import runtimeTypes from '@polkadot/types/interfaces/runtime/definitions';
|
||||
import type { AccountId, DispatchError, DispatchInfo, EventRecord, Extrinsic, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { SignedBlockExtended, TxWithEvent } from './types';
|
||||
|
||||
import { extractAuthor } from './util';
|
||||
|
||||
// We can ignore the properties, added via Struct.with
|
||||
const _SignedBlock = Struct.with(runtimeTypes.types.SignedBlock as any) as Constructor<SignedBlock>;
|
||||
|
||||
interface TxWithEvent {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
events: Event[];
|
||||
extrinsic: Extrinsic;
|
||||
}
|
||||
|
||||
function mapExtrinsics (extrinsics: Extrinsic[], records: EventRecord[]): TxWithEvent[] {
|
||||
return extrinsics.map((extrinsic, index): TxWithEvent => {
|
||||
let dispatchError: DispatchError | undefined;
|
||||
@@ -43,42 +31,45 @@ function mapExtrinsics (extrinsics: Extrinsic[], records: EventRecord[]): TxWith
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name SignedBlockExtended
|
||||
* @description
|
||||
* A [[Block]] header with an additional `author` field that indicates the block author
|
||||
*/
|
||||
export class SignedBlockExtended extends _SignedBlock {
|
||||
readonly #author?: AccountId;
|
||||
readonly #events: EventRecord[];
|
||||
readonly #extrinsics: TxWithEvent[];
|
||||
export function createSignedBlockExtended (registry: Registry, block?: SignedBlock, events?: EventRecord[], validators?: AccountId[]): SignedBlockExtended {
|
||||
// an instance of the base extrinsic for us to extend
|
||||
const SignedBlockBase = registry.createClass('SignedBlock');
|
||||
|
||||
constructor (registry: Registry, block?: SignedBlock, events?: EventRecord[], sessionValidators?: AccountId[]) {
|
||||
super(registry, block);
|
||||
class Implementation extends SignedBlockBase implements SignedBlockExtended {
|
||||
readonly #author?: AccountId;
|
||||
readonly #events: EventRecord[];
|
||||
readonly #extrinsics: TxWithEvent[];
|
||||
|
||||
this.#author = extractAuthor(this.block.header.digest, sessionValidators);
|
||||
this.#events = events || ([] as EventRecord[]);
|
||||
this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events);
|
||||
constructor (registry: Registry, block?: SignedBlock, events?: EventRecord[], validators?: AccountId[]) {
|
||||
super(registry, block);
|
||||
|
||||
this.#author = extractAuthor(this.block.header.digest, validators);
|
||||
this.#events = events || ([] as EventRecord[]);
|
||||
this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events);
|
||||
this.createdAtHash = block?.createdAtHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the author for the block
|
||||
*/
|
||||
public get author (): AccountId | undefined {
|
||||
return this.#author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the events associated with the block
|
||||
*/
|
||||
public get events (): EventRecord[] {
|
||||
return this.#events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the extrinsics and their events, mapped
|
||||
*/
|
||||
public get extrinsics (): TxWithEvent[] {
|
||||
return this.#extrinsics;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the author for the block
|
||||
*/
|
||||
public get author (): AccountId | undefined {
|
||||
return this.#author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convenience method, returns the events associated with the block
|
||||
*/
|
||||
public get events (): EventRecord[] {
|
||||
return this.#events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the extrinsics and their events, mapped
|
||||
*/
|
||||
public get extrinsics (): TxWithEvent[] {
|
||||
return this.#extrinsics;
|
||||
}
|
||||
return new Implementation(registry, block, events, validators);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { HeaderExtended } from './HeaderExtended';
|
||||
export { SignedBlockExtended } from './SignedBlockExtended';
|
||||
export { createHeaderExtended } from './HeaderExtended';
|
||||
export { createSignedBlockExtended } from './SignedBlockExtended';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AccountId, DispatchError, DispatchInfo, Event, EventRecord, Extrinsic, Header, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
export interface HeaderExtended extends Header {
|
||||
readonly author: AccountId | undefined;
|
||||
readonly validators: AccountId[] | undefined;
|
||||
}
|
||||
|
||||
export interface SignedBlockExtended extends SignedBlock {
|
||||
readonly author: AccountId | undefined;
|
||||
readonly events: EventRecord[];
|
||||
readonly extrinsics: TxWithEvent[];
|
||||
}
|
||||
|
||||
export interface TxWithEvent {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
events: Event[];
|
||||
extrinsic: Extrinsic;
|
||||
}
|
||||
@@ -5,20 +5,43 @@ import type { AccountId, Digest } from '@polkadot/types/interfaces';
|
||||
|
||||
export function extractAuthor (digest: Digest, sessionValidators: AccountId[] = []): AccountId | undefined {
|
||||
const [citem] = digest.logs.filter(({ type }) => type === 'Consensus');
|
||||
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
|
||||
const [sitem] = digest.logs.filter(({ type }) => type === 'Seal');
|
||||
|
||||
if (citem) {
|
||||
const [engine, data] = citem.asConsensus;
|
||||
let accountId: AccountId | undefined;
|
||||
|
||||
return engine.extractAuthor(data, sessionValidators);
|
||||
} else {
|
||||
const [pitem] = digest.logs.filter(({ type }) => type === 'PreRuntime');
|
||||
|
||||
if (pitem) {
|
||||
// This is critical to be first for BABE (before Consensus)
|
||||
// If not first, we end up dropping the author at session-end
|
||||
if (pitem) {
|
||||
try {
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
return engine.extractAuthor(data, sessionValidators);
|
||||
accountId = engine.extractAuthor(data, sessionValidators);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
if (!accountId && citem) {
|
||||
try {
|
||||
const [engine, data] = citem.asConsensus;
|
||||
|
||||
accountId = engine.extractAuthor(data, sessionValidators);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// SEAL, still used in e.g. Kulupu for pow
|
||||
if (!accountId && sitem) {
|
||||
try {
|
||||
const [engine, data] = sitem.asSeal;
|
||||
|
||||
accountId = engine.extractAuthor(data, sessionValidators);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
return accountId;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export * from './elections/types';
|
||||
export * from './parachains/types';
|
||||
export * from './session/types';
|
||||
export * from './staking/types';
|
||||
export * from './type/types';
|
||||
|
||||
export interface DeriveBalancesAccountData {
|
||||
freeBalance: Balance;
|
||||
@@ -107,6 +108,7 @@ export interface DeriveSocietyCandidate {
|
||||
|
||||
export interface DeriveSocietyMember {
|
||||
accountId: AccountId;
|
||||
isDefenderVoter: boolean;
|
||||
isSuspended: boolean;
|
||||
payouts: [BlockNumber, Balance][];
|
||||
strikes: StrikeCount;
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { DeriveCache } from './types';
|
||||
|
||||
const mapCache = new Map<string, any>();
|
||||
|
||||
const deriveMapCache: DeriveCache = {
|
||||
export const deriveMapCache: DeriveCache = {
|
||||
del: (key: string): void => {
|
||||
mapCache.delete(key);
|
||||
},
|
||||
@@ -24,11 +24,9 @@ const deriveMapCache: DeriveCache = {
|
||||
}
|
||||
};
|
||||
|
||||
const deriveNoopCache: DeriveCache = {
|
||||
export const deriveNoopCache: DeriveCache = {
|
||||
del: (): void => undefined,
|
||||
forEach: () => undefined,
|
||||
get: (): undefined => undefined,
|
||||
set: (_: string, value: unknown): unknown => value
|
||||
};
|
||||
|
||||
export { deriveMapCache, deriveNoopCache };
|
||||
|
||||
+17
-13
@@ -1,12 +1,16 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "3.9.2",
|
||||
"version": "4.7.2",
|
||||
"type": "module",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
@@ -15,17 +19,17 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.13",
|
||||
"@polkadot/api-derive": "3.9.2",
|
||||
"@polkadot/keyring": "^5.6.2",
|
||||
"@polkadot/metadata": "3.9.2",
|
||||
"@polkadot/rpc-core": "3.9.2",
|
||||
"@polkadot/rpc-provider": "3.9.2",
|
||||
"@polkadot/types": "3.9.2",
|
||||
"@polkadot/types-known": "3.9.2",
|
||||
"@polkadot/util": "^5.6.2",
|
||||
"@polkadot/util-crypto": "^5.6.2",
|
||||
"@polkadot/x-rxjs": "^5.6.2",
|
||||
"@babel/runtime": "^7.13.17",
|
||||
"@polkadot/api-derive": "4.7.2",
|
||||
"@polkadot/keyring": "^6.3.1",
|
||||
"@polkadot/metadata": "4.7.2",
|
||||
"@polkadot/rpc-core": "4.7.2",
|
||||
"@polkadot/rpc-provider": "4.7.2",
|
||||
"@polkadot/types": "4.7.2",
|
||||
"@polkadot/types-known": "4.7.2",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"@polkadot/x-rxjs": "^6.3.1",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Vec, u16, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { Codec } from '@polkadot/types/types';
|
||||
import type { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Perbill, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import type { Balance, BalanceOf, BlockNumber, LockIdentifier, Moment, PalletId, Perbill, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import type { SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import type { EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
import type { RuntimeVersion } from '@polkadot/types/interfaces/state';
|
||||
@@ -16,11 +16,9 @@ declare module '@polkadot/api/types/consts' {
|
||||
babe: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* The number of **slots** that an epoch takes. We couple sessions to
|
||||
* epochs, i.e. we start a new session once the new epoch begins.
|
||||
* NOTE: Currently it is not possible to change the epoch duration
|
||||
* after the chain has started. Attempting to do so will brick block
|
||||
* production.
|
||||
* The amount of time, in slots, that each epoch should last.
|
||||
* NOTE: Currently it is not possible to change the epoch duration after
|
||||
* the chain has started. Attempting to do so will brick block production.
|
||||
**/
|
||||
epochDuration: u64 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
@@ -107,12 +105,17 @@ declare module '@polkadot/api/types/consts' {
|
||||
**/
|
||||
depositPerStorageItem: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The maximum nesting level of a call/instantiate stack. A reasonable default
|
||||
* value is 100.
|
||||
* The maximum length of a contract code in bytes. This limit applies to the instrumented
|
||||
* version of the code. Therefore `instantiate_with_code` can fail even when supplying
|
||||
* a wasm binary below this maximum size.
|
||||
**/
|
||||
maxCodeSize: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The maximum nesting level of a call/instantiate stack.
|
||||
**/
|
||||
maxDepth: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The maximum size of a storage value in bytes. A reasonable default is 16 KiB.
|
||||
* The maximum size of a storage value and event payload in bytes.
|
||||
**/
|
||||
maxValueSize: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
@@ -179,16 +182,104 @@ declare module '@polkadot/api/types/consts' {
|
||||
**/
|
||||
votingPeriod: BlockNumber & AugmentedConst<ApiType>;
|
||||
};
|
||||
electionProviderMultiPhase: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* Duration of the signed phase.
|
||||
**/
|
||||
signedPhase: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The minimum amount of improvement to the solution score that defines a solution as
|
||||
* "better" (in any phase).
|
||||
**/
|
||||
solutionImprovementThreshold: Perbill & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Duration of the unsigned phase.
|
||||
**/
|
||||
unsignedPhase: BlockNumber & AugmentedConst<ApiType>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* How much should be locked up in order to submit one's candidacy.
|
||||
**/
|
||||
candidacyBond: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Number of members to elect.
|
||||
**/
|
||||
desiredMembers: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Number of runners_up to keep.
|
||||
**/
|
||||
desiredRunnersUp: u32 & AugmentedConst<ApiType>;
|
||||
moduleId: LockIdentifier & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Identifier for the elections-phragmen pallet's lock
|
||||
**/
|
||||
palletId: LockIdentifier & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* How long each seat is kept. This defines the next block number at which an election
|
||||
* round will happen. If set to zero, no elections are ever triggered and the module will
|
||||
* be in passive mode.
|
||||
**/
|
||||
termDuration: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Base deposit associated with voting.
|
||||
*
|
||||
* This should be sensibly high to economically ensure the pallet cannot be attacked by
|
||||
* creating a gigantic number of votes.
|
||||
**/
|
||||
votingBondBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount of bond that need to be locked for each vote (32 bytes).
|
||||
**/
|
||||
votingBondFactor: BalanceOf & AugmentedConst<ApiType>;
|
||||
};
|
||||
gilt: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* Portion of the queue which is free from ordering and just a FIFO.
|
||||
*
|
||||
* Must be no greater than `MaxQueueLen`.
|
||||
**/
|
||||
fifoQueueLen: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The number of blocks between consecutive attempts to issue more gilts in an effort to
|
||||
* get to the target amount to be frozen.
|
||||
*
|
||||
* A larger value results in fewer storage hits each block, but a slower period to get to
|
||||
* the target.
|
||||
**/
|
||||
intakePeriod: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The maximum amount of bids that can be turned into issued gilts each block. A larger
|
||||
* value here means less of the block available for transactions should there be a glut of
|
||||
* bids to make into gilts to reach the target.
|
||||
**/
|
||||
maxIntakeBids: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum number of items that may be in each duration queue.
|
||||
**/
|
||||
maxQueueLen: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The minimum amount of funds that may be offered to freeze for a gilt. Note that this
|
||||
* does not actually limit the amount which may be frozen in a gilt since gilts may be
|
||||
* split up in order to satisfy the desired amount of funds under gilts.
|
||||
*
|
||||
* It should be at least big enough to ensure that there is no possible storage spam attack
|
||||
* or queue-filling attack.
|
||||
**/
|
||||
minFreeze: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The base period for the duration queues. This is the common multiple across all
|
||||
* supported freezing durations that can be bid upon.
|
||||
**/
|
||||
period: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Number of duration queues in total. This sets the maximum duration supported, which is
|
||||
* this value multiplied by `Period`.
|
||||
**/
|
||||
queueCount: u32 & AugmentedConst<ApiType>;
|
||||
};
|
||||
identity: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
@@ -230,7 +321,7 @@ declare module '@polkadot/api/types/consts' {
|
||||
lottery: {
|
||||
[key: string]: Codec;
|
||||
maxCalls: u32 & AugmentedConst<ApiType>;
|
||||
moduleId: ModuleId & AugmentedConst<ApiType>;
|
||||
palletId: PalletId & AugmentedConst<ApiType>;
|
||||
};
|
||||
multisig: {
|
||||
[key: string]: Codec;
|
||||
@@ -251,15 +342,20 @@ declare module '@polkadot/api/types/consts' {
|
||||
proxy: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* `AnnouncementDepositBase` metadata shadow.
|
||||
* The base amount of currency needed to reserve for creating an announcement.
|
||||
*
|
||||
* This is held when a new storage item holding a `Balance` is created (typically 16 bytes).
|
||||
**/
|
||||
announcementDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* `AnnouncementDepositFactor` metadata shadow.
|
||||
* The amount of currency needed per announcement made.
|
||||
*
|
||||
* This is held for adding an `AccountId`, `Hash` and `BlockNumber` (typically 68 bytes)
|
||||
* into a pre-existing storage value.
|
||||
**/
|
||||
announcementDepositFactor: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* `MaxPending` metadata shadow.
|
||||
* The maximum amount of time-delayed announcements that are allowed to be pending.
|
||||
**/
|
||||
maxPending: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
@@ -268,10 +364,17 @@ declare module '@polkadot/api/types/consts' {
|
||||
maxProxies: u16 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The base amount of currency needed to reserve for creating a proxy.
|
||||
*
|
||||
* This is held for an additional storage item whose value size is
|
||||
* `sizeof(Balance)` bytes and whose key size is `sizeof(AccountId)` bytes.
|
||||
**/
|
||||
proxyDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount of currency needed per proxy added.
|
||||
*
|
||||
* This is held for adding 32 bytes plus an instance of `ProxyType` more into a pre-existing
|
||||
* storage value. Thus, when configuring `ProxyDepositFactor` one should take into account
|
||||
* `32 + proxy_type.encode().len()` bytes of data.
|
||||
**/
|
||||
proxyDepositFactor: BalanceOf & AugmentedConst<ApiType>;
|
||||
};
|
||||
@@ -304,6 +407,10 @@ declare module '@polkadot/api/types/consts' {
|
||||
* The number of blocks between membership challenges.
|
||||
**/
|
||||
challengePeriod: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum candidate intake per round.
|
||||
**/
|
||||
maxCandidateIntake: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The number of times a member may vote the wrong way (or not at all, when they are a skeptic)
|
||||
* before they become suspended.
|
||||
@@ -312,7 +419,7 @@ declare module '@polkadot/api/types/consts' {
|
||||
/**
|
||||
* The societies's module id
|
||||
**/
|
||||
moduleId: ModuleId & AugmentedConst<ApiType>;
|
||||
palletId: PalletId & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount of incentive paid within each period. Doesn't include VoterTip.
|
||||
**/
|
||||
@@ -334,21 +441,9 @@ declare module '@polkadot/api/types/consts' {
|
||||
**/
|
||||
bondingDuration: EraIndex & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The number of blocks before the end of the era from which election submissions are allowed.
|
||||
*
|
||||
* Setting this to zero will disable the offchain compute and only on-chain seq-phragmen will
|
||||
* be used.
|
||||
*
|
||||
* This is bounded by being within the last session. Hence, setting it to a value more than the
|
||||
* length of a session will be pointless.
|
||||
* Maximum number of nominations per nominator.
|
||||
**/
|
||||
electionLookahead: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum number of balancing iterations to run in the offchain submission.
|
||||
*
|
||||
* If set to 0, balance_solution will not be executed at all.
|
||||
**/
|
||||
maxIterations: u32 & AugmentedConst<ApiType>;
|
||||
maxNominations: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The maximum number of nominators rewarded for each validator.
|
||||
*
|
||||
@@ -356,10 +451,6 @@ declare module '@polkadot/api/types/consts' {
|
||||
* their reward. This used to limit the i/o cost for the nominator payout.
|
||||
**/
|
||||
maxNominatorRewardedPerValidator: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The threshold of improvement that should be provided for a new solution to be accepted.
|
||||
**/
|
||||
minSolutionScoreBump: Perbill & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Number of sessions per era.
|
||||
**/
|
||||
@@ -457,7 +548,7 @@ declare module '@polkadot/api/types/consts' {
|
||||
/**
|
||||
* The treasury's module id, used for deriving its sovereign account ID.
|
||||
**/
|
||||
moduleId: ModuleId & AugmentedConst<ApiType>;
|
||||
palletId: PalletId & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Fraction of a proposal's value that should be bonded in order to place the proposal.
|
||||
* An accepted proposal gets these back. A rejected proposal does not.
|
||||
@@ -475,7 +566,7 @@ declare module '@polkadot/api/types/consts' {
|
||||
vesting: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* The minimum amount to be transferred to create a new vesting schedule.
|
||||
* The minimum amount transferred to call `vested_transfer`.
|
||||
**/
|
||||
minVestedTransfer: BalanceOf & AugmentedConst<ApiType>;
|
||||
};
|
||||
|
||||
@@ -7,18 +7,10 @@ declare module '@polkadot/api/types/errors' {
|
||||
export interface AugmentedErrors<ApiType> {
|
||||
assets: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Transfer amount should be non-zero.
|
||||
**/
|
||||
AmountZero: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Invalid metadata given.
|
||||
**/
|
||||
BadMetadata: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Some internal state is broken.
|
||||
**/
|
||||
BadState: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Invalid witness data given.
|
||||
**/
|
||||
@@ -47,22 +39,26 @@ declare module '@polkadot/api/types/errors' {
|
||||
* The signing account has no permission to do the operation.
|
||||
**/
|
||||
NoPermission: AugmentedError<ApiType>;
|
||||
/**
|
||||
* No provider reference exists to allow a non-zero balance of a non-self-sufficient asset.
|
||||
**/
|
||||
NoProvider: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A mint operation lead to an overflow.
|
||||
**/
|
||||
Overflow: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Attempt to destroy an asset class when non-zombie, reference-bearing accounts exist.
|
||||
* No approval exists that would allow the transfer.
|
||||
**/
|
||||
RefsLeft: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Too many zombie accounts in use.
|
||||
**/
|
||||
TooManyZombies: AugmentedError<ApiType>;
|
||||
Unapproved: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The given asset ID is unknown.
|
||||
**/
|
||||
Unknown: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The source account would not survive the transfer and it needs to stay alive.
|
||||
**/
|
||||
WouldDie: AugmentedError<ApiType>;
|
||||
};
|
||||
authorship: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
@@ -95,6 +91,21 @@ declare module '@polkadot/api/types/errors' {
|
||||
**/
|
||||
UnclesAlreadySet: AugmentedError<ApiType>;
|
||||
};
|
||||
babe: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A given equivocation report is valid but already previously reported.
|
||||
**/
|
||||
DuplicateOffenceReport: AugmentedError<ApiType>;
|
||||
/**
|
||||
* An equivocation proof provided as part of an equivocation report is invalid.
|
||||
**/
|
||||
InvalidEquivocationProof: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A key ownership proof provided as part of an equivocation report is invalid.
|
||||
**/
|
||||
InvalidKeyOwnershipProof: AugmentedError<ApiType>;
|
||||
};
|
||||
balances: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
@@ -191,7 +202,7 @@ declare module '@polkadot/api/types/errors' {
|
||||
/**
|
||||
* A contract could not be evicted because it has enough balance to pay rent.
|
||||
*
|
||||
* This can be returned from [`Module::claim_surcharge`] because the target
|
||||
* This can be returned from [`Pallet::claim_surcharge`] because the target
|
||||
* contract has enough balance to pay for its rent.
|
||||
**/
|
||||
ContractNotEvictable: AugmentedError<ApiType>;
|
||||
@@ -206,7 +217,7 @@ declare module '@polkadot/api/types/errors' {
|
||||
/**
|
||||
* Removal of a contract failed because the deletion queue is full.
|
||||
*
|
||||
* This can happen when either calling [`Module::claim_surcharge`] or `seal_terminate`.
|
||||
* This can happen when either calling [`Pallet::claim_surcharge`] or `seal_terminate`.
|
||||
* The queue is filled by deleting contracts and emptied by a fixed amount each block.
|
||||
* Trying again during another block is the only way to resolve this issue.
|
||||
**/
|
||||
@@ -499,6 +510,21 @@ declare module '@polkadot/api/types/errors' {
|
||||
**/
|
||||
WrongUpperBound: AugmentedError<ApiType>;
|
||||
};
|
||||
electionProviderMultiPhase: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Submission was too early.
|
||||
**/
|
||||
PreDispatchEarlySubmission: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Submission was too weak, score-wise.
|
||||
**/
|
||||
PreDispatchWeakSubmission: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Wrong number of winners presented.
|
||||
**/
|
||||
PreDispatchWrongWinnerCount: AugmentedError<ApiType>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
@@ -570,6 +596,42 @@ declare module '@polkadot/api/types/errors' {
|
||||
**/
|
||||
UnableToVote: AugmentedError<ApiType>;
|
||||
};
|
||||
gilt: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The amount of the bid is less than the minimum allowed.
|
||||
**/
|
||||
AmountTooSmall: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The queue for the bid's duration is full and the amount bid is too low to get in through
|
||||
* replacing an existing bid.
|
||||
**/
|
||||
BidTooLow: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The duration is the bid is greater than the number of queues.
|
||||
**/
|
||||
DurationTooBig: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The duration of the bid is less than one.
|
||||
**/
|
||||
DurationTooSmall: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Gilt not yet at expiry date.
|
||||
**/
|
||||
NotExpired: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The given bid for retraction is not found.
|
||||
**/
|
||||
NotFound: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Not the owner of the gilt.
|
||||
**/
|
||||
NotOwner: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Gilt index is unknown.
|
||||
**/
|
||||
Unknown: AugmentedError<ApiType>;
|
||||
};
|
||||
grandpa: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
@@ -681,6 +743,64 @@ declare module '@polkadot/api/types/errors' {
|
||||
**/
|
||||
InvalidKey: AugmentedError<ApiType>;
|
||||
};
|
||||
indices: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The index was not available.
|
||||
**/
|
||||
InUse: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The index was not already assigned.
|
||||
**/
|
||||
NotAssigned: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The index is assigned to another account.
|
||||
**/
|
||||
NotOwner: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The source and destination accounts are identical.
|
||||
**/
|
||||
NotTransfer: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The index is permanent and may not be freed/changed.
|
||||
**/
|
||||
Permanent: AugmentedError<ApiType>;
|
||||
};
|
||||
lottery: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A lottery has already ended.
|
||||
**/
|
||||
AlreadyEnded: AugmentedError<ApiType>;
|
||||
/**
|
||||
* You are already participating in the lottery with this call.
|
||||
**/
|
||||
AlreadyParticipating: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Failed to encode calls
|
||||
**/
|
||||
EncodingFailed: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A lottery is already in progress.
|
||||
**/
|
||||
InProgress: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The call is not valid for an open lottery.
|
||||
**/
|
||||
InvalidCall: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A lottery has not been configured.
|
||||
**/
|
||||
NotConfigured: AugmentedError<ApiType>;
|
||||
/**
|
||||
* An overflow has occurred.
|
||||
**/
|
||||
Overflow: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Too many calls for a single lottery.
|
||||
**/
|
||||
TooManyCalls: AugmentedError<ApiType>;
|
||||
};
|
||||
multisig: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
@@ -691,6 +811,10 @@ declare module '@polkadot/api/types/errors' {
|
||||
* The data to be stored is already stored.
|
||||
**/
|
||||
AlreadyStored: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The maximum weight information provided was too low.
|
||||
**/
|
||||
MaxWeightTooLow: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Threshold must be 2 or greater.
|
||||
**/
|
||||
@@ -731,10 +855,6 @@ declare module '@polkadot/api/types/errors' {
|
||||
* A timepoint was given, yet no multisig operation is underway.
|
||||
**/
|
||||
UnexpectedTimepoint: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The maximum weight information provided was too low.
|
||||
**/
|
||||
WeightTooLow: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A different timepoint was given to the multisig operation that is underway.
|
||||
**/
|
||||
@@ -985,10 +1105,6 @@ declare module '@polkadot/api/types/errors' {
|
||||
* A nomination target was supplied that was blocked or otherwise not a validator.
|
||||
**/
|
||||
BadTarget: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The call is not allowed at the given time due to restrictions of election period.
|
||||
**/
|
||||
CallNotAllowed: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Duplicate index.
|
||||
**/
|
||||
@@ -1045,61 +1161,6 @@ declare module '@polkadot/api/types/errors' {
|
||||
* Can not rebond without unlocking chunks.
|
||||
**/
|
||||
NoUnlockChunk: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Error while building the assignment type from the compact. This can happen if an index
|
||||
* is invalid, or if the weights _overflow_.
|
||||
**/
|
||||
OffchainElectionBogusCompact: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The submitted result has unknown edges that are not among the presented winners.
|
||||
**/
|
||||
OffchainElectionBogusEdge: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The election size is invalid.
|
||||
**/
|
||||
OffchainElectionBogusElectionSize: AugmentedError<ApiType>;
|
||||
/**
|
||||
* One of the submitted nominators has an edge to which they have not voted on chain.
|
||||
**/
|
||||
OffchainElectionBogusNomination: AugmentedError<ApiType>;
|
||||
/**
|
||||
* One of the submitted nominators is not an active nominator on chain.
|
||||
**/
|
||||
OffchainElectionBogusNominator: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The claimed score does not match with the one computed from the data.
|
||||
**/
|
||||
OffchainElectionBogusScore: AugmentedError<ApiType>;
|
||||
/**
|
||||
* A self vote must only be originated from a validator to ONLY themselves.
|
||||
**/
|
||||
OffchainElectionBogusSelfVote: AugmentedError<ApiType>;
|
||||
/**
|
||||
* One of the submitted winners is not an active candidate on chain (index is out of range
|
||||
* in snapshot).
|
||||
**/
|
||||
OffchainElectionBogusWinner: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Incorrect number of winners were presented.
|
||||
**/
|
||||
OffchainElectionBogusWinnerCount: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The submitted result is received out of the open window.
|
||||
**/
|
||||
OffchainElectionEarlySubmission: AugmentedError<ApiType>;
|
||||
/**
|
||||
* One of the submitted nominators has an edge which is submitted before the last non-zero
|
||||
* slash of the target.
|
||||
**/
|
||||
OffchainElectionSlashedNomination: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The submitted result is not as good as the one stored on chain.
|
||||
**/
|
||||
OffchainElectionWeakSubmission: AugmentedError<ApiType>;
|
||||
/**
|
||||
* The snapshot data of the current window is missing.
|
||||
**/
|
||||
SnapshotUnavailable: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Too many nomination targets supplied.
|
||||
**/
|
||||
@@ -1182,6 +1243,17 @@ declare module '@polkadot/api/types/errors' {
|
||||
**/
|
||||
WrongProposalWeight: AugmentedError<ApiType>;
|
||||
};
|
||||
technicalMembership: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Already a member.
|
||||
**/
|
||||
AlreadyMember: AugmentedError<ApiType>;
|
||||
/**
|
||||
* Not a member.
|
||||
**/
|
||||
NotMember: AugmentedError<ApiType>;
|
||||
};
|
||||
tips: {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
/**
|
||||
|
||||
@@ -9,12 +9,13 @@ import type { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/coll
|
||||
import type { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import type { PropIndex, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import type { VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import type { ActiveIndex } from '@polkadot/types/interfaces/gilt';
|
||||
import type { AuthorityList } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { RegistrarIndex } from '@polkadot/types/interfaces/identity';
|
||||
import type { CallIndex } from '@polkadot/types/interfaces/lottery';
|
||||
import type { Kind, OpaqueTimeSlot } from '@polkadot/types/interfaces/offences';
|
||||
import type { ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import type { AccountId, AccountIndex, AssetId, Balance, BlockNumber, CallHash, Hash, PhantomData } from '@polkadot/types/interfaces/runtime';
|
||||
import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber, CallHash, Hash, PhantomData } from '@polkadot/types/interfaces/runtime';
|
||||
import type { TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import type { IdentificationTuple, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import type { ElectionCompute, EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
@@ -27,10 +28,25 @@ declare module '@polkadot/api/types/events' {
|
||||
export interface AugmentedEvents<ApiType> {
|
||||
assets: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* An approval for account `delegate` was cancelled by `owner`.
|
||||
* \[id, owner, delegate\]
|
||||
**/
|
||||
ApprovalCancelled: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId]>;
|
||||
/**
|
||||
* (Additional) funds have been approved for transfer to a destination account.
|
||||
* \[asset_id, source, delegate, amount\]
|
||||
**/
|
||||
ApprovedTransfer: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, TAssetBalance]>;
|
||||
/**
|
||||
* Some asset `asset_id` was frozen. \[asset_id\]
|
||||
**/
|
||||
AssetFrozen: AugmentedEvent<ApiType, [AssetId]>;
|
||||
/**
|
||||
* An asset has had its attributes changed by the `Force` origin.
|
||||
* \[id\]
|
||||
**/
|
||||
AssetStatusChanged: AugmentedEvent<ApiType, [AssetId]>;
|
||||
/**
|
||||
* Some asset `asset_id` was thawed. \[asset_id\]
|
||||
**/
|
||||
@@ -51,10 +67,6 @@ declare module '@polkadot/api/types/events' {
|
||||
* Some asset class was force-created. \[asset_id, owner\]
|
||||
**/
|
||||
ForceCreated: AugmentedEvent<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* Some assets was transferred by an admin. \[asset_id, from, to, amount\]
|
||||
**/
|
||||
ForceTransferred: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, TAssetBalance]>;
|
||||
/**
|
||||
* Some account `who` was frozen. \[asset_id, who\]
|
||||
**/
|
||||
@@ -64,13 +76,13 @@ declare module '@polkadot/api/types/events' {
|
||||
**/
|
||||
Issued: AugmentedEvent<ApiType, [AssetId, AccountId, TAssetBalance]>;
|
||||
/**
|
||||
* The maximum amount of zombies allowed has changed. \[asset_id, max_zombies\]
|
||||
* Metadata has been cleared for an asset. \[asset_id\]
|
||||
**/
|
||||
MaxZombiesChanged: AugmentedEvent<ApiType, [AssetId, u32]>;
|
||||
MetadataCleared: AugmentedEvent<ApiType, [AssetId]>;
|
||||
/**
|
||||
* New metadata has been set for an asset. \[asset_id, name, symbol, decimals\]
|
||||
* New metadata has been set for an asset. \[asset_id, name, symbol, decimals, is_frozen\]
|
||||
**/
|
||||
MetadataSet: AugmentedEvent<ApiType, [AssetId, Bytes, Bytes, u8]>;
|
||||
MetadataSet: AugmentedEvent<ApiType, [AssetId, Bytes, Bytes, u8, bool]>;
|
||||
/**
|
||||
* The owner changed \[asset_id, owner\]
|
||||
**/
|
||||
@@ -87,6 +99,12 @@ declare module '@polkadot/api/types/events' {
|
||||
* Some assets were transferred. \[asset_id, from, to, amount\]
|
||||
**/
|
||||
Transferred: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, TAssetBalance]>;
|
||||
/**
|
||||
* An `amount` was transferred in its entirety from `owner` to `destination` by
|
||||
* the approved `delegate`.
|
||||
* \[id, owner, delegate, destination\]
|
||||
**/
|
||||
TransferredApproved: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, AccountId, TAssetBalance]>;
|
||||
};
|
||||
balances: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
@@ -345,6 +363,37 @@ declare module '@polkadot/api/types/events' {
|
||||
**/
|
||||
Vetoed: AugmentedEvent<ApiType, [AccountId, Hash, BlockNumber]>;
|
||||
};
|
||||
electionProviderMultiPhase: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* The election has been finalized, with `Some` of the given computation, or else if the
|
||||
* election failed, `None`.
|
||||
**/
|
||||
ElectionFinalized: AugmentedEvent<ApiType, [Option<ElectionCompute>]>;
|
||||
/**
|
||||
* An account has been rewarded for their signed submission being finalized.
|
||||
**/
|
||||
Rewarded: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* The signed phase of the given round has started.
|
||||
**/
|
||||
SignedPhaseStarted: AugmentedEvent<ApiType, [u32]>;
|
||||
/**
|
||||
* An account has been slashed for submitting an invalid signed submission.
|
||||
**/
|
||||
Slashed: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A solution was stored with the given compute.
|
||||
*
|
||||
* If the solution is signed, this means that it hasn't yet been processed. If the
|
||||
* solution is unsigned, this means that it has also been processed.
|
||||
**/
|
||||
SolutionStored: AugmentedEvent<ApiType, [ElectionCompute]>;
|
||||
/**
|
||||
* The unsigned phase of the given round has started.
|
||||
**/
|
||||
UnsignedPhaseStarted: AugmentedEvent<ApiType, [u32]>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
@@ -369,10 +418,11 @@ declare module '@polkadot/api/types/events' {
|
||||
**/
|
||||
MemberKicked: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A new term with \[new_members\]. This indicates that enough candidates existed to run the
|
||||
* election, not that enough have has been elected. The inner value must be examined for
|
||||
* this purpose. A `NewTerm(\[\])` indicates that some candidates got their bond slashed and
|
||||
* none were elected, whilst `EmptyTerm` means that no candidates existed to begin with.
|
||||
* A new term with \[new_members\]. This indicates that enough candidates existed to run
|
||||
* the election, not that enough have has been elected. The inner value must be examined
|
||||
* for this purpose. A `NewTerm(\[\])` indicates that some candidates got their bond
|
||||
* slashed and none were elected, whilst `EmptyTerm` means that no candidates existed to
|
||||
* begin with.
|
||||
**/
|
||||
NewTerm: AugmentedEvent<ApiType, [Vec<ITuple<[AccountId, Balance]>>]>;
|
||||
/**
|
||||
@@ -384,6 +434,29 @@ declare module '@polkadot/api/types/events' {
|
||||
**/
|
||||
SeatHolderSlashed: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
};
|
||||
gilt: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A bid was successfully placed.
|
||||
* \[ who, amount, duration \]
|
||||
**/
|
||||
BidPlaced: AugmentedEvent<ApiType, [AccountId, BalanceOf, u32]>;
|
||||
/**
|
||||
* A bid was successfully removed (before being accepted as a gilt).
|
||||
* \[ who, amount, duration \]
|
||||
**/
|
||||
BidRetracted: AugmentedEvent<ApiType, [AccountId, BalanceOf, u32]>;
|
||||
/**
|
||||
* A bid was accepted as a gilt. The balance may not be released until expiry.
|
||||
* \[ index, expiry, who, amount \]
|
||||
**/
|
||||
GiltIssued: AugmentedEvent<ApiType, [ActiveIndex, BlockNumber, AccountId, BalanceOf]>;
|
||||
/**
|
||||
* An expired gilt has been thawed.
|
||||
* \[ index, who, original_amount, additional_amount \]
|
||||
**/
|
||||
GiltThawed: AugmentedEvent<ApiType, [ActiveIndex, AccountId, BalanceOf, BalanceOf]>;
|
||||
};
|
||||
grandpa: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
@@ -697,13 +770,9 @@ declare module '@polkadot/api/types/events' {
|
||||
**/
|
||||
Slash: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A new solution for the upcoming election has been stored. \[compute\]
|
||||
* A new set of stakers was elected.
|
||||
**/
|
||||
SolutionStored: AugmentedEvent<ApiType, [ElectionCompute]>;
|
||||
/**
|
||||
* A new set of stakers was elected with the given \[compute\].
|
||||
**/
|
||||
StakingElection: AugmentedEvent<ApiType, [ElectionCompute]>;
|
||||
StakingElection: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* An account has unbonded this amount. \[stash, amount\]
|
||||
**/
|
||||
@@ -751,6 +820,10 @@ declare module '@polkadot/api/types/events' {
|
||||
* A new \[account\] was created.
|
||||
**/
|
||||
NewAccount: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* On on-chain remark happened. \[origin, remark_hash\]
|
||||
**/
|
||||
Remarked: AugmentedEvent<ApiType, [AccountId, Hash]>;
|
||||
};
|
||||
technicalCommittee: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
|
||||
@@ -3,15 +3,16 @@
|
||||
|
||||
import type { Bytes, Data, Option, U8aFixed, Vec, bool, u32, u64 } from '@polkadot/types';
|
||||
import type { AnyNumber, ITuple, Observable } from '@polkadot/types/types';
|
||||
import type { AssetBalance, AssetDetails, AssetMetadata } from '@polkadot/types/interfaces/assets';
|
||||
import type { AssetApproval, AssetApprovalKey, AssetBalance, AssetDetails, AssetMetadata } from '@polkadot/types/interfaces/assets';
|
||||
import type { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
|
||||
import type { BabeAuthorityWeight, MaybeRandomness, NextConfigDescriptor, Randomness } from '@polkadot/types/interfaces/babe';
|
||||
import type { BabeAuthorityWeight, BabeEpochConfiguration, MaybeRandomness, NextConfigDescriptor, Randomness } from '@polkadot/types/interfaces/babe';
|
||||
import type { AccountData, BalanceLock } from '@polkadot/types/interfaces/balances';
|
||||
import type { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
|
||||
import type { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import type { CodeHash, ContractInfo, DeletedContract, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import type { PreimageStatus, PropIndex, Proposal, ReferendumIndex, ReferendumInfo, Voting } from '@polkadot/types/interfaces/democracy';
|
||||
import type { VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import type { ActiveGilt, ActiveGiltsTotal, ActiveIndex, GiltBid } from '@polkadot/types/interfaces/gilt';
|
||||
import type { SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import type { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
@@ -23,7 +24,7 @@ import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber,
|
||||
import type { Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import type { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import type { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
import type { ActiveEraInfo, ElectionResult, ElectionScore, ElectionStatus, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, RewardDestination, SeatHolder, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs, Voter } from '@polkadot/types/interfaces/staking';
|
||||
import type { ActiveEraInfo, ElectionPhase, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, ReadySolution, RewardDestination, RoundSnapshot, SeatHolder, SlashingSpans, SolutionOrSnapshotSize, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs, Voter } from '@polkadot/types/interfaces/staking';
|
||||
import type { AccountInfo, ConsumedWeight, DigestOf, EventIndex, EventRecord, LastRuntimeUpgradeInfo, Phase } from '@polkadot/types/interfaces/system';
|
||||
import type { Bounty, BountyIndex, OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import type { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
@@ -39,6 +40,11 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The number of units of assets held by any given account.
|
||||
**/
|
||||
account: AugmentedQueryDoubleMap<ApiType, (key1: AssetId | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<AssetBalance>, [AssetId, AccountId]> & QueryableStorageEntry<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* Approved balance transfers. First balance is the amount approved for transfer. Second
|
||||
* is the amount of `T::Currency` reserved for storing this.
|
||||
**/
|
||||
approvals: AugmentedQueryDoubleMap<ApiType, (key1: AssetId | AnyNumber | Uint8Array, key2: AssetApprovalKey | { owner?: any; delegate?: any } | string | Uint8Array) => Observable<Option<AssetApproval>>, [AssetId, AssetApprovalKey]> & QueryableStorageEntry<ApiType, [AssetId, AssetApprovalKey]>;
|
||||
/**
|
||||
* Details of an asset.
|
||||
**/
|
||||
@@ -79,10 +85,22 @@ declare module '@polkadot/api/types/storage' {
|
||||
* Current slot number.
|
||||
**/
|
||||
currentSlot: AugmentedQuery<ApiType, () => Observable<Slot>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The configuration for the current epoch. Should never be `None` as it is initialized in genesis.
|
||||
**/
|
||||
epochConfig: AugmentedQuery<ApiType, () => Observable<Option<BabeEpochConfiguration>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Current epoch index.
|
||||
**/
|
||||
epochIndex: AugmentedQuery<ApiType, () => Observable<u64>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The block numbers when the last and current epoch have started, respectively `N-1` and
|
||||
* `N`.
|
||||
* NOTE: We track this is in order to annotate the block number when a given pool of
|
||||
* entropy was fixed (i.e. it was known to chain observers). Since epochs are defined in
|
||||
* slots, which may be skipped, the block numbers may not line up with the slot numbers.
|
||||
**/
|
||||
epochStart: AugmentedQuery<ApiType, () => Observable<ITuple<[BlockNumber, BlockNumber]>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The slot at which the first epoch actually started. This is 0
|
||||
* until the first block of the chain.
|
||||
@@ -106,13 +124,18 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
nextAuthorities: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AuthorityId, BabeAuthorityWeight]>>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Next epoch configuration, if changed.
|
||||
* The configuration for the next epoch, `None` if the config will not change
|
||||
* (you can fallback to `EpochConfig` instead in that case).
|
||||
**/
|
||||
nextEpochConfig: AugmentedQuery<ApiType, () => Observable<Option<NextConfigDescriptor>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
nextEpochConfig: AugmentedQuery<ApiType, () => Observable<Option<BabeEpochConfiguration>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Next epoch randomness.
|
||||
**/
|
||||
nextRandomness: AugmentedQuery<ApiType, () => Observable<Randomness>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Pending epoch configuration change that will be applied when the next epoch is enacted.
|
||||
**/
|
||||
pendingEpochConfigChange: AugmentedQuery<ApiType, () => Observable<Option<NextConfigDescriptor>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The epoch randomness for the *current* epoch.
|
||||
*
|
||||
@@ -323,6 +346,44 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
votingOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Voting>, [AccountId]> & QueryableStorageEntry<ApiType, [AccountId]>;
|
||||
};
|
||||
electionProviderMultiPhase: {
|
||||
[key: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Current phase.
|
||||
**/
|
||||
currentPhase: AugmentedQuery<ApiType, () => Observable<ElectionPhase>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Desired number of targets to elect for this round.
|
||||
*
|
||||
* Only exists when [`Snapshot`] is present.
|
||||
**/
|
||||
desiredTargets: AugmentedQuery<ApiType, () => Observable<Option<u32>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Current best solution, signed or unsigned, queued to be returned upon `elect`.
|
||||
**/
|
||||
queuedSolution: AugmentedQuery<ApiType, () => Observable<Option<ReadySolution>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Internal counter for the number of rounds.
|
||||
*
|
||||
* This is useful for de-duplication of transactions submitted to the pool, and general
|
||||
* diagnostics of the pallet.
|
||||
*
|
||||
* This is merely incremented once per every time that an upstream `elect` is called.
|
||||
**/
|
||||
round: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Snapshot data of the round.
|
||||
*
|
||||
* This is created at the beginning of the signed phase and cleared upon calling `elect`.
|
||||
**/
|
||||
snapshot: AugmentedQuery<ApiType, () => Observable<Option<RoundSnapshot>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The metadata of the [`RoundSnapshot`]
|
||||
*
|
||||
* Only exists when [`Snapshot`] is present.
|
||||
**/
|
||||
snapshotMetadata: AugmentedQuery<ApiType, () => Observable<Option<SolutionOrSnapshotSize>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
@@ -358,6 +419,29 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
voting: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Voter>, [AccountId]> & QueryableStorageEntry<ApiType, [AccountId]>;
|
||||
};
|
||||
gilt: {
|
||||
[key: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The currently active gilts, indexed according to the order of creation.
|
||||
**/
|
||||
active: AugmentedQuery<ApiType, (arg: ActiveIndex | AnyNumber | Uint8Array) => Observable<Option<ActiveGilt>>, [ActiveIndex]> & QueryableStorageEntry<ApiType, [ActiveIndex]>;
|
||||
/**
|
||||
* Information relating to the gilts currently active.
|
||||
**/
|
||||
activeTotal: AugmentedQuery<ApiType, () => Observable<ActiveGiltsTotal>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The queues of bids ready to become gilts. Indexed by duration (in `Period`s).
|
||||
**/
|
||||
queues: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Vec<GiltBid>>, [u32]> & QueryableStorageEntry<ApiType, [u32]>;
|
||||
/**
|
||||
* The totals of items and balances within each queue. Saves a lot of storage reads in the
|
||||
* case of sparsely packed queues.
|
||||
*
|
||||
* The vector is indexed by duration in `Period`s, offset by one, so information on the queue
|
||||
* whose duration is one `Period` would be storage `0`.
|
||||
**/
|
||||
queueTotals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[u32, BalanceOf]>>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
};
|
||||
grandpa: {
|
||||
[key: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
@@ -426,12 +510,17 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
authoredBlocks: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>, [SessionIndex, ValidatorId]> & QueryableStorageEntry<ApiType, [SessionIndex, ValidatorId]>;
|
||||
/**
|
||||
* The block number after which it's ok to send heartbeats in current session.
|
||||
* The block number after which it's ok to send heartbeats in the current
|
||||
* session.
|
||||
*
|
||||
* At the beginning of each session we set this to a value that should
|
||||
* fall roughly in the middle of the session duration.
|
||||
* The idea is to first wait for the validators to produce a block
|
||||
* in the current session, so that the heartbeat later on will not be necessary.
|
||||
* At the beginning of each session we set this to a value that should fall
|
||||
* roughly in the middle of the session duration. The idea is to first wait for
|
||||
* the validators to produce a block in the current session, so that the
|
||||
* heartbeat later on will not be necessary.
|
||||
*
|
||||
* This value will only be used as a fallback if we fail to get a proper session
|
||||
* progress estimate from `NextSessionRotation`, as those estimates should be
|
||||
* more accurate then the value we calculate for `HeartbeatAfter`.
|
||||
**/
|
||||
heartbeatAfter: AugmentedQuery<ApiType, () => Observable<BlockNumber>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
@@ -723,15 +812,16 @@ declare module '@polkadot/api/types/storage' {
|
||||
* set, it might be active or not.
|
||||
**/
|
||||
currentEra: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The last planned session scheduled by the session pallet.
|
||||
*
|
||||
* This is basically in sync with the call to [`SessionManager::new_session`].
|
||||
**/
|
||||
currentPlannedSession: AugmentedQuery<ApiType, () => Observable<SessionIndex>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The earliest era for which we have a pending, unapplied slash.
|
||||
**/
|
||||
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Flag to control the execution of the offchain election. When `Open(_)`, we accept
|
||||
* solutions to be submitted.
|
||||
**/
|
||||
eraElectionStatus: AugmentedQuery<ApiType, () => Observable<ElectionStatus>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Rewards for the last `HISTORY_DEPTH` eras.
|
||||
* If reward hasn't been set or has been removed then 0 reward is returned.
|
||||
@@ -806,11 +896,6 @@ declare module '@polkadot/api/types/storage' {
|
||||
* invulnerables) and restricted to testnets.
|
||||
**/
|
||||
invulnerables: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* True if the current **planned** session is final. Note that this does not take era
|
||||
* forcing into account.
|
||||
**/
|
||||
isCurrentSessionFinal: AugmentedQuery<ApiType, () => Observable<bool>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Map from all (unlocked) "controller" accounts to the info regarding the staking.
|
||||
**/
|
||||
@@ -831,16 +916,6 @@ declare module '@polkadot/api/types/storage' {
|
||||
* Where the reward payment should be made. Keyed by stash.
|
||||
**/
|
||||
payee: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<RewardDestination>, [AccountId]> & QueryableStorageEntry<ApiType, [AccountId]>;
|
||||
/**
|
||||
* The next validator set. At the end of an era, if this is available (potentially from the
|
||||
* result of an offchain worker), it is immediately used. Otherwise, the on-chain election
|
||||
* is executed.
|
||||
**/
|
||||
queuedElected: AugmentedQuery<ApiType, () => Observable<Option<ElectionResult>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* The score of the current [`QueuedElected`].
|
||||
**/
|
||||
queuedScore: AugmentedQuery<ApiType, () => Observable<Option<ElectionScore>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Slashing spans for stash accounts.
|
||||
**/
|
||||
@@ -851,16 +926,6 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The rest of the slashed value is handled by the `Slash`.
|
||||
**/
|
||||
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Snapshot of nominators at the beginning of the current election window. This should only
|
||||
* have a value when [`EraElectionStatus`] == `ElectionStatus::Open(_)`.
|
||||
**/
|
||||
snapshotNominators: AugmentedQuery<ApiType, () => Observable<Option<Vec<AccountId>>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Snapshot of validators at the beginning of the current election window. This should only
|
||||
* have a value when [`EraElectionStatus`] == `ElectionStatus::Open(_)`.
|
||||
**/
|
||||
snapshotValidators: AugmentedQuery<ApiType, () => Observable<Option<Vec<AccountId>>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Records information about the maximum slash of a stash within a slashing span,
|
||||
* as well as how much reward has been paid out.
|
||||
@@ -870,7 +935,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
* True if network has been upgraded to this version.
|
||||
* Storage version of the pallet.
|
||||
*
|
||||
* This is set to v5.0.0 for new networks.
|
||||
* This is set to v6.0.0 for new networks.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Releases>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
@@ -966,10 +1031,10 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
parentHash: AugmentedQuery<ApiType, () => Observable<Hash>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* True if we have upgraded so that AccountInfo contains two types of `RefCount`. False
|
||||
* True if we have upgraded so that AccountInfo contains three types of `RefCount`. False
|
||||
* (default) if not.
|
||||
**/
|
||||
upgradedToDualRefCount: AugmentedQuery<ApiType, () => Observable<bool>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
upgradedToTripleRefCount: AugmentedQuery<ApiType, () => Observable<bool>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* True if we have upgraded so that `type RefCount` is `u32`. False (default) if not.
|
||||
**/
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { Bytes, HashMap, Json, Null, Option, StorageKey, Text, U256, U64, V
|
||||
import type { AnyNumber, Codec, IExtrinsic, Observable } from '@polkadot/types/types';
|
||||
import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
|
||||
import type { EpochAuthorship } from '@polkadot/types/interfaces/babe';
|
||||
import type { BeefySignedCommitment } from '@polkadot/types/interfaces/beefy';
|
||||
import type { BlockHash } from '@polkadot/types/interfaces/chain';
|
||||
import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
|
||||
import type { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
@@ -14,6 +15,7 @@ import type { CreatedBlock } from '@polkadot/types/interfaces/engine';
|
||||
import type { EthAccount, EthCallRequest, EthFilter, EthFilterChanges, EthLog, EthReceipt, EthRichBlock, EthSubKind, EthSubParams, EthSyncStatus, EthTransaction, EthTransactionRequest, EthWork } from '@polkadot/types/interfaces/eth';
|
||||
import type { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { EncodedFinalityProofs, JustificationNotification, ReportedRoundStates } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { MmrLeafProof } from '@polkadot/types/interfaces/mmr';
|
||||
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import type { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
@@ -63,6 +65,12 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
**/
|
||||
epochAuthorship: AugmentedRpc<() => Observable<HashMap<AuthorityId, EpochAuthorship>>>;
|
||||
};
|
||||
beefy: {
|
||||
/**
|
||||
* Returns the block most recently finalized by BEEFY, alongside side its justification.
|
||||
**/
|
||||
subscribeJustifications: AugmentedRpc<() => Observable<BeefySignedCommitment>>;
|
||||
};
|
||||
chain: {
|
||||
/**
|
||||
* Get header and body of a relay chain block
|
||||
@@ -133,7 +141,7 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
/**
|
||||
* Instructs the manual-seal authorship task to finalize a block
|
||||
**/
|
||||
finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification | string | Uint8Array) => Observable<bool>>;
|
||||
finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification) => Observable<bool>>;
|
||||
};
|
||||
eth: {
|
||||
/**
|
||||
@@ -315,6 +323,12 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
**/
|
||||
subscribeJustifications: AugmentedRpc<() => Observable<JustificationNotification>>;
|
||||
};
|
||||
mmr: {
|
||||
/**
|
||||
* Generate MMR proof for given leaf index.
|
||||
**/
|
||||
generateProof: AugmentedRpc<(leafIndex: u64 | AnyNumber | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<MmrLeafProof>>;
|
||||
};
|
||||
net: {
|
||||
/**
|
||||
* Returns true if client is actively listening for network connections. Otherwise false.
|
||||
@@ -333,11 +347,11 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
/**
|
||||
* Get offchain local storage under given key and prefix
|
||||
**/
|
||||
localStorageGet: AugmentedRpc<(kind: StorageKind | '__UNUSED' | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
localStorageGet: AugmentedRpc<(kind: StorageKind | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
/**
|
||||
* Set offchain local storage under given key and prefix
|
||||
**/
|
||||
localStorageSet: AugmentedRpc<(kind: StorageKind | '__UNUSED' | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable<Null>>;
|
||||
localStorageSet: AugmentedRpc<(kind: StorageKind | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable<Null>>;
|
||||
};
|
||||
payment: {
|
||||
/**
|
||||
|
||||
+283
-128
@@ -3,22 +3,23 @@
|
||||
|
||||
import type { Bytes, Compact, Data, Option, U8aFixed, Vec, bool, u16, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { AnyNumber, ITuple } from '@polkadot/types/types';
|
||||
import type { TAssetBalance } from '@polkadot/types/interfaces/assets';
|
||||
import type { BabeEquivocationProof } from '@polkadot/types/interfaces/babe';
|
||||
import type { AssetDestroyWitness, TAssetBalance } from '@polkadot/types/interfaces/assets';
|
||||
import type { BabeEquivocationProof, NextConfigDescriptor } from '@polkadot/types/interfaces/babe';
|
||||
import type { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective';
|
||||
import type { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import type { CodeHash, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import type { AccountVote, Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import type { Renouncing } from '@polkadot/types/interfaces/elections';
|
||||
import type { Extrinsic, Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { ActiveIndex } from '@polkadot/types/interfaces/gilt';
|
||||
import type { GrandpaEquivocationProof, KeyOwnerProof } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { IdentityFields, IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity';
|
||||
import type { Heartbeat } from '@polkadot/types/interfaces/imOnline';
|
||||
import type { ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber, Call, CallHashOf, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber, Call, CallHashOf, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, Perquintill, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import type { Period, Priority } from '@polkadot/types/interfaces/scheduler';
|
||||
import type { Keys } from '@polkadot/types/interfaces/session';
|
||||
import type { SocietyJudgement } from '@polkadot/types/interfaces/society';
|
||||
import type { CompactAssignments, ElectionScore, ElectionSize, EraIndex, RewardDestination, ValidatorIndex, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import type { EraIndex, RawSolution, RewardDestination, SolutionOrSnapshotSize, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import type { Key } from '@polkadot/types/interfaces/system';
|
||||
import type { BountyIndex } from '@polkadot/types/interfaces/treasury';
|
||||
import type { Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
@@ -29,6 +30,29 @@ declare module '@polkadot/api/types/submittable' {
|
||||
export interface AugmentedSubmittables<ApiType> {
|
||||
assets: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Approve an amount of asset for transfer by a delegated third-party account.
|
||||
*
|
||||
* Origin must be Signed.
|
||||
*
|
||||
* Ensures that `ApprovalDeposit` worth of `Currency` is reserved from signing account
|
||||
* for the purpose of holding the approval. If some non-zero amount of assets is already
|
||||
* approved from signing account to `delegate`, then it is topped up or unreserved to
|
||||
* meet the right value.
|
||||
*
|
||||
* NOTE: The signing account does not need to own `amount` of assets at the point of
|
||||
* making this call.
|
||||
*
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `delegate`: The account to delegate permission to transfer asset.
|
||||
* - `amount`: The amount of asset that may be transferred by `delegate`. If there is
|
||||
* already an approval in place, then this acts additively.
|
||||
*
|
||||
* Emits `ApprovedTransfer` on success.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
approveTransfer: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, delegate: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Reduce the balance of `who` by as much as possible up to `amount` assets of `id`.
|
||||
*
|
||||
@@ -47,24 +71,50 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Modes: Post-existence of `who`; Pre & post Zombie-status of `who`.
|
||||
**/
|
||||
burn: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, who: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Cancel all of some asset approved for delegated transfer by a third-party account.
|
||||
*
|
||||
* Origin must be Signed and there must be an approval in place between signer and
|
||||
* `delegate`.
|
||||
*
|
||||
* Unreserves any deposit previously reserved by `approve_transfer` for the approval.
|
||||
*
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `delegate`: The account delegated permission to transfer asset.
|
||||
*
|
||||
* Emits `ApprovalCancelled` on success.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
cancelApproval: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, delegate: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource]>;
|
||||
/**
|
||||
* Clear the metadata for an asset.
|
||||
*
|
||||
* Origin must be Signed and the sender should be the Owner of the asset `id`.
|
||||
*
|
||||
* Any deposit is freed for the asset owner.
|
||||
*
|
||||
* - `id`: The identifier of the asset to clear.
|
||||
*
|
||||
* Emits `MetadataCleared`.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
clearMetadata: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>]>;
|
||||
/**
|
||||
* Issue a new class of fungible assets from a public origin.
|
||||
*
|
||||
* This new asset class has no assets initially.
|
||||
* This new asset class has no assets initially and its owner is the origin.
|
||||
*
|
||||
* The origin must be Signed and the sender must have sufficient funds free.
|
||||
*
|
||||
* Funds of sender are reserved according to the formula:
|
||||
* `AssetDepositBase + AssetDepositPerZombie * max_zombies`.
|
||||
* Funds of sender are reserved by `AssetDeposit`.
|
||||
*
|
||||
* Parameters:
|
||||
* - `id`: The identifier of the new asset. This must not be currently in use to identify
|
||||
* an existing asset.
|
||||
* - `owner`: The owner of this class of assets. The owner has full superuser permissions
|
||||
* over this asset, but may later change and configure the permissions using `transfer_ownership`
|
||||
* and `set_team`.
|
||||
* - `max_zombies`: The total number of accounts which may hold assets in this class yet
|
||||
* have no existential deposit.
|
||||
* - `admin`: The admin of this class of assets. The admin is the initial address of each
|
||||
* member of the asset class's admin team.
|
||||
* - `min_balance`: The minimum balance of this new asset that any single account must
|
||||
* have. If an account's balance is reduced below this, then it collapses to zero.
|
||||
*
|
||||
@@ -72,20 +122,79 @@ declare module '@polkadot/api/types/submittable' {
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
create: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, admin: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, maxZombies: u32 | AnyNumber | Uint8Array, minBalance: TAssetBalance | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, u32, TAssetBalance]>;
|
||||
create: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, admin: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, minBalance: TAssetBalance | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, TAssetBalance]>;
|
||||
/**
|
||||
* Destroy a class of fungible assets owned by the sender.
|
||||
* Destroy a class of fungible assets.
|
||||
*
|
||||
* The origin must be Signed and the sender must be the owner of the asset `id`.
|
||||
* The origin must conform to `ForceOrigin` or must be Signed and the sender must be the
|
||||
* owner of the asset `id`.
|
||||
*
|
||||
* - `id`: The identifier of the asset to be destroyed. This must identify an existing
|
||||
* asset.
|
||||
*
|
||||
* Emits `Destroyed` event when successful.
|
||||
*
|
||||
* Weight: `O(z)` where `z` is the number of zombie accounts.
|
||||
* Weight: `O(c + p + a)` where:
|
||||
* - `c = (witness.accounts - witness.sufficients)`
|
||||
* - `s = witness.sufficients`
|
||||
* - `a = witness.approvals`
|
||||
**/
|
||||
destroy: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, zombiesWitness: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, Compact<u32>]>;
|
||||
destroy: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, witness: AssetDestroyWitness | { accounts?: any; sufficients?: any; approvals?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, AssetDestroyWitness]>;
|
||||
/**
|
||||
* Alter the attributes of a given asset.
|
||||
*
|
||||
* Origin must be `ForceOrigin`.
|
||||
*
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `owner`: The new Owner of this asset.
|
||||
* - `issuer`: The new Issuer of this asset.
|
||||
* - `admin`: The new Admin of this asset.
|
||||
* - `freezer`: The new Freezer of this asset.
|
||||
* - `min_balance`: The minimum balance of this new asset that any single account must
|
||||
* have. If an account's balance is reduced below this, then it collapses to zero.
|
||||
* - `is_sufficient`: Whether a non-zero balance of this asset is deposit of sufficient
|
||||
* value to account for the state bloat associated with its balance storage. If set to
|
||||
* `true`, then non-zero balances may be stored without a `consumer` reference (and thus
|
||||
* an ED in the Balances pallet or whatever else is used to control user-account state
|
||||
* growth).
|
||||
* - `is_frozen`: Whether this asset class is frozen except for permissioned/admin
|
||||
* instructions.
|
||||
*
|
||||
* Emits `AssetStatusChanged` with the identity of the asset.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
forceAssetStatus: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, owner: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, issuer: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, admin: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, freezer: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, minBalance: Compact<TAssetBalance> | AnyNumber | Uint8Array, isSufficient: bool | boolean | Uint8Array, isFrozen: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, LookupSource, LookupSource, LookupSource, Compact<TAssetBalance>, bool, bool]>;
|
||||
/**
|
||||
* Cancel all of some asset approved for delegated transfer by a third-party account.
|
||||
*
|
||||
* Origin must be either ForceOrigin or Signed origin with the signer being the Admin
|
||||
* account of the asset `id`.
|
||||
*
|
||||
* Unreserves any deposit previously reserved by `approve_transfer` for the approval.
|
||||
*
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `delegate`: The account delegated permission to transfer asset.
|
||||
*
|
||||
* Emits `ApprovalCancelled` on success.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
forceCancelApproval: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, owner: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, delegate: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, LookupSource]>;
|
||||
/**
|
||||
* Clear the metadata for an asset.
|
||||
*
|
||||
* Origin must be ForceOrigin.
|
||||
*
|
||||
* Any deposit is returned.
|
||||
*
|
||||
* - `id`: The identifier of the asset to clear.
|
||||
*
|
||||
* Emits `MetadataCleared`.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
forceClearMetadata: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>]>;
|
||||
/**
|
||||
* Issue a new class of fungible assets from a privileged origin.
|
||||
*
|
||||
@@ -109,20 +218,24 @@ declare module '@polkadot/api/types/submittable' {
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
forceCreate: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, owner: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, maxZombies: Compact<u32> | AnyNumber | Uint8Array, minBalance: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<u32>, Compact<TAssetBalance>]>;
|
||||
forceCreate: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, owner: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, isSufficient: bool | boolean | Uint8Array, minBalance: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, bool, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Destroy a class of fungible assets.
|
||||
* Force the metadata for an asset to some value.
|
||||
*
|
||||
* The origin must conform to `ForceOrigin`.
|
||||
* Origin must be ForceOrigin.
|
||||
*
|
||||
* - `id`: The identifier of the asset to be destroyed. This must identify an existing
|
||||
* asset.
|
||||
* Any deposit is left alone.
|
||||
*
|
||||
* Emits `Destroyed` event when successful.
|
||||
* - `id`: The identifier of the asset to update.
|
||||
* - `name`: The user friendly name of this asset. Limited in length by `StringLimit`.
|
||||
* - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`.
|
||||
* - `decimals`: The number of decimals this asset uses to represent one unit.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
* Emits `MetadataSet`.
|
||||
*
|
||||
* Weight: `O(N + S)` where N and S are the length of the name and symbol respectively.
|
||||
**/
|
||||
forceDestroy: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, zombiesWitness: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, Compact<u32>]>;
|
||||
forceSetMetadata: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, name: Bytes | string | Uint8Array, symbol: Bytes | string | Uint8Array, decimals: u8 | AnyNumber | Uint8Array, isFrozen: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, Bytes, Bytes, u8, bool]>;
|
||||
/**
|
||||
* Move some assets from one account to another.
|
||||
*
|
||||
@@ -185,30 +298,9 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Modes: Pre-existing balance of `beneficiary`; Account pre-existence of `beneficiary`.
|
||||
**/
|
||||
mint: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, beneficiary: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Set the maximum number of zombie accounts for an asset.
|
||||
*
|
||||
* Origin must be Signed and the sender should be the Owner of the asset `id`.
|
||||
*
|
||||
* Funds of sender are reserved according to the formula:
|
||||
* `AssetDepositBase + AssetDepositPerZombie * max_zombies` taking into account
|
||||
* any already reserved funds.
|
||||
*
|
||||
* - `id`: The identifier of the asset to update zombie count.
|
||||
* - `max_zombies`: The new number of zombies allowed for this asset.
|
||||
*
|
||||
* Emits `MaxZombiesChanged`.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
setMaxZombies: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, maxZombies: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, Compact<u32>]>;
|
||||
/**
|
||||
* Set the metadata for an asset.
|
||||
*
|
||||
* NOTE: There is no `unset_metadata` call. Simply pass an empty name, symbol,
|
||||
* and 0 decimals to this function to remove the metadata of an asset and
|
||||
* return your deposit.
|
||||
*
|
||||
* Origin must be Signed and the sender should be the Owner of the asset `id`.
|
||||
*
|
||||
* Funds of sender are reserved according to the formula:
|
||||
@@ -220,7 +312,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`.
|
||||
* - `decimals`: The number of decimals this asset uses to represent one unit.
|
||||
*
|
||||
* Emits `MaxZombiesChanged`.
|
||||
* Emits `MetadataSet`.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
@@ -286,12 +378,54 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* of sender; Account pre-existence of `target`.
|
||||
**/
|
||||
transfer: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, target: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Transfer some asset balance from a previously delegated account to some third-party
|
||||
* account.
|
||||
*
|
||||
* Origin must be Signed and there must be an approval in place by the `owner` to the
|
||||
* signer.
|
||||
*
|
||||
* If the entire amount approved for transfer is transferred, then any deposit previously
|
||||
* reserved by `approve_transfer` is unreserved.
|
||||
*
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `owner`: The account which previously approved for a transfer of at least `amount` and
|
||||
* from which the asset balance will be withdrawn.
|
||||
* - `destination`: The account to which the asset balance of `amount` will be transferred.
|
||||
* - `amount`: The amount of assets to transfer.
|
||||
*
|
||||
* Emits `TransferredApproved` on success.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
**/
|
||||
transferApproved: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, owner: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, destination: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Move some assets from the sender account to another, keeping the sender account alive.
|
||||
*
|
||||
* Origin must be Signed.
|
||||
*
|
||||
* - `id`: The identifier of the asset to have some amount transferred.
|
||||
* - `target`: The account to be credited.
|
||||
* - `amount`: The amount by which the sender's balance of assets should be reduced and
|
||||
* `target`'s balance increased. The amount actually transferred may be slightly greater in
|
||||
* the case that the transfer would otherwise take the sender balance above zero but below
|
||||
* the minimum balance. Must be greater than zero.
|
||||
*
|
||||
* Emits `Transferred` with the actual amount transferred. If this takes the source balance
|
||||
* to below the minimum for the asset, then the amount transferred is increased to take it
|
||||
* to zero.
|
||||
*
|
||||
* Weight: `O(1)`
|
||||
* Modes: Pre-existence of `target`; Post-existence of sender; Prior & post zombie-status
|
||||
* of sender; Account pre-existence of `target`.
|
||||
**/
|
||||
transferKeepAlive: AugmentedSubmittable<(id: Compact<AssetId> | AnyNumber | Uint8Array, target: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, amount: Compact<TAssetBalance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<AssetId>, LookupSource, Compact<TAssetBalance>]>;
|
||||
/**
|
||||
* Change the Owner of an asset.
|
||||
*
|
||||
* Origin must be Signed and the sender should be the Owner of the asset `id`.
|
||||
*
|
||||
* - `id`: The identifier of the asset to be frozen.
|
||||
* - `id`: The identifier of the asset.
|
||||
* - `owner`: The new Owner of this asset.
|
||||
*
|
||||
* Emits `OwnerChanged`.
|
||||
@@ -309,6 +443,13 @@ declare module '@polkadot/api/types/submittable' {
|
||||
};
|
||||
babe: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Plan an epoch config change. The epoch config change is recorded and will be enacted on
|
||||
* the next call to `enact_epoch_change`. The config will be activated one epoch after.
|
||||
* Multiple calls to this method will replace any existing planned config change that had
|
||||
* not been enacted yet.
|
||||
**/
|
||||
planConfigChange: AugmentedSubmittable<(config: NextConfigDescriptor | { V0: any } | { V1: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [NextConfigDescriptor]>;
|
||||
/**
|
||||
* Report authority equivocation/misbehavior. This method will verify
|
||||
* the equivocation proof and validate the given key ownership proof
|
||||
@@ -538,7 +679,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* * If no account exists and the call value is not less than `existential_deposit`,
|
||||
* a regular account will be created and any value will be transferred.
|
||||
**/
|
||||
call: AugmentedSubmittable<(dest: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource, Compact<BalanceOf>, Compact<Gas>, Bytes]>;
|
||||
call: AugmentedSubmittable<(dest: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Weight> | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource, Compact<BalanceOf>, Compact<Weight>, Bytes]>;
|
||||
/**
|
||||
* Allows block producers to claim a small reward for evicting a contract. If a block
|
||||
* producer fails to do so, a regular users will be allowed to claim the reward.
|
||||
@@ -558,7 +699,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* code deployment step. Instead, the `code_hash` of an on-chain deployed wasm binary
|
||||
* must be supplied.
|
||||
**/
|
||||
instantiate: AugmentedSubmittable<(endowment: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, codeHash: CodeHash | string | Uint8Array, data: Bytes | string | Uint8Array, salt: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, Compact<Gas>, CodeHash, Bytes, Bytes]>;
|
||||
instantiate: AugmentedSubmittable<(endowment: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Weight> | AnyNumber | Uint8Array, codeHash: CodeHash | string | Uint8Array, data: Bytes | string | Uint8Array, salt: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, Compact<Weight>, CodeHash, Bytes, Bytes]>;
|
||||
/**
|
||||
* Instantiates a new contract from the supplied `code` optionally transferring
|
||||
* some balance.
|
||||
@@ -571,7 +712,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* * `gas_limit`: The gas limit enforced when executing the constructor.
|
||||
* * `code`: The contract code to deploy in raw bytes.
|
||||
* * `data`: The input data to pass to the contract constructor.
|
||||
* * `salt`: Used for the address derivation. See [`Self::contract_address`].
|
||||
* * `salt`: Used for the address derivation. See [`Pallet::contract_address`].
|
||||
*
|
||||
* Instantiation is executed as follows:
|
||||
*
|
||||
@@ -582,11 +723,14 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - The `endowment` is transferred to the new account.
|
||||
* - The `deploy` function is executed in the context of the newly-created account.
|
||||
**/
|
||||
instantiateWithCode: AugmentedSubmittable<(endowment: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, code: Bytes | string | Uint8Array, data: Bytes | string | Uint8Array, salt: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, Compact<Gas>, Bytes, Bytes, Bytes]>;
|
||||
instantiateWithCode: AugmentedSubmittable<(endowment: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Weight> | AnyNumber | Uint8Array, code: Bytes | string | Uint8Array, data: Bytes | string | Uint8Array, salt: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, Compact<Weight>, Bytes, Bytes, Bytes]>;
|
||||
/**
|
||||
* Updates the schedule for metering contracts.
|
||||
*
|
||||
* The schedule must have a greater version than the stored schedule.
|
||||
* The schedule's version cannot be less than the version of the stored schedule.
|
||||
* If a schedule does not change the instruction weights the version does not
|
||||
* need to be increased. Therefore we allow storing a schedule that has the same
|
||||
* version as the stored one.
|
||||
**/
|
||||
updateSchedule: AugmentedSubmittable<(schedule: Schedule | { version?: any; enablePrintln?: any; limits?: any; instructionWeights?: any; hostFnWeights?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Schedule]>;
|
||||
};
|
||||
@@ -1062,6 +1206,26 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
vote: AugmentedSubmittable<(refIndex: Compact<ReferendumIndex> | AnyNumber | Uint8Array, vote: AccountVote | { Standard: any } | { Split: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<ReferendumIndex>, AccountVote]>;
|
||||
};
|
||||
electionProviderMultiPhase: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Submit a solution for the unsigned phase.
|
||||
*
|
||||
* The dispatch origin fo this call must be __none__.
|
||||
*
|
||||
* This submission is checked on the fly. Moreover, this unsigned solution is only
|
||||
* validated when submitted to the pool from the **local** node. Effectively, this means
|
||||
* that only active validators can submit this transaction when authoring a block (similar
|
||||
* to an inherent).
|
||||
*
|
||||
* To prevent any incorrect solution (and thus wasted time/weight), this transaction will
|
||||
* panic if the solution submitted by the validator is invalid in any way, effectively
|
||||
* putting their authoring reward at risk.
|
||||
*
|
||||
* No deposit or reward is associated with this submission.
|
||||
**/
|
||||
submitUnsigned: AugmentedSubmittable<(solution: RawSolution | { compact?: any; score?: any; round?: any } | string | Uint8Array, witness: SolutionOrSnapshotSize | { voters?: any; targets?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [RawSolution, SolutionOrSnapshotSize]>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
@@ -1112,8 +1276,8 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* origin is removed as a runner-up.
|
||||
* - `origin` is a current member. In this case, the deposit is unreserved and origin is
|
||||
* removed as a member, consequently not being a candidate for the next round anymore.
|
||||
* Similar to [`remove_members`], if replacement runners exists, they are immediately used.
|
||||
* If the prime is renouncing, then no prime will exist until the next round.
|
||||
* Similar to [`remove_members`], if replacement runners exists, they are immediately
|
||||
* used. If the prime is renouncing, then no prime will exist until the next round.
|
||||
*
|
||||
* The dispatch origin of this call must be signed, and have one of the above roles.
|
||||
*
|
||||
@@ -1167,6 +1331,54 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
vote: AugmentedSubmittable<(votes: Vec<AccountId> | (AccountId | string | Uint8Array)[], value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Vec<AccountId>, Compact<BalanceOf>]>;
|
||||
};
|
||||
gilt: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Place a bid for a gilt to be issued.
|
||||
*
|
||||
* Origin must be Signed, and account must have at least `amount` in free balance.
|
||||
*
|
||||
* - `amount`: The amount of the bid; these funds will be reserved. If the bid is
|
||||
* successfully elevated into an issued gilt, then these funds will continue to be
|
||||
* reserved until the gilt expires. Must be at least `MinFreeze`.
|
||||
* - `duration`: The number of periods for which the funds will be locked if the gilt is
|
||||
* issued. It will expire only after this period has elapsed after the point of issuance.
|
||||
* Must be greater than 1 and no more than `QueueCount`.
|
||||
*
|
||||
* Complexities:
|
||||
* - `Queues[duration].len()` (just take max).
|
||||
**/
|
||||
placeBid: AugmentedSubmittable<(amount: Compact<BalanceOf> | AnyNumber | Uint8Array, duration: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, u32]>;
|
||||
/**
|
||||
* Retract a previously placed bid.
|
||||
*
|
||||
* Origin must be Signed, and the account should have previously issued a still-active bid
|
||||
* of `amount` for `duration`.
|
||||
*
|
||||
* - `amount`: The amount of the previous bid.
|
||||
* - `duration`: The duration of the previous bid.
|
||||
**/
|
||||
retractBid: AugmentedSubmittable<(amount: Compact<BalanceOf> | AnyNumber | Uint8Array, duration: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<BalanceOf>, u32]>;
|
||||
/**
|
||||
* Set target proportion of gilt-funds.
|
||||
*
|
||||
* Origin must be `AdminOrigin`.
|
||||
*
|
||||
* - `target`: The target proportion of effective issued funds that should be under gilts
|
||||
* at any one time.
|
||||
**/
|
||||
setTarget: AugmentedSubmittable<(target: Compact<Perquintill> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<Perquintill>]>;
|
||||
/**
|
||||
* Remove an active but expired gilt. Reserved funds under gilt are freed and balance is
|
||||
* adjusted to ensure that the funds grow or shrink to maintain the equivalent proportion
|
||||
* of effective total issued funds.
|
||||
*
|
||||
* Origin must be Signed and the account must be the owner of the gilt of the given index.
|
||||
*
|
||||
* - `index`: The index of the gilt to be thawed.
|
||||
**/
|
||||
thaw: AugmentedSubmittable<(index: Compact<ActiveIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<ActiveIndex>]>;
|
||||
};
|
||||
grandpa: {
|
||||
[key: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
@@ -1885,7 +2097,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
proxy: AugmentedSubmittable<(real: AccountId | string | Uint8Array, forceProxyType: Option<ProxyType> | null | object | string | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [AccountId, Option<ProxyType>, Call]>;
|
||||
/**
|
||||
* Dispatch the given `call` from an account that the sender is authorised for through
|
||||
* Dispatch the given `call` from an account that the sender is authorized for through
|
||||
* `add_proxy`.
|
||||
*
|
||||
* Removes any corresponding announcement(s).
|
||||
@@ -2624,7 +2836,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Bonded, Payee, [Origin Account], Locks, Ledger
|
||||
* # </weight>
|
||||
**/
|
||||
bond: AugmentedSubmittable<(controller: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource, Compact<BalanceOf>, RewardDestination]>;
|
||||
bond: AugmentedSubmittable<(controller: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | { None: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource, Compact<BalanceOf>, RewardDestination]>;
|
||||
/**
|
||||
* Add some extra amount that have appeared in the stash `free_balance` into the balance up
|
||||
* for staking.
|
||||
@@ -2930,7 +3142,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Payee
|
||||
* # </weight>
|
||||
**/
|
||||
setPayee: AugmentedSubmittable<(payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [RewardDestination]>;
|
||||
setPayee: AugmentedSubmittable<(payee: RewardDestination | { Staked: any } | { Stash: any } | { Controller: any } | { Account: any } | { None: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [RewardDestination]>;
|
||||
/**
|
||||
* Sets the ideal number of validators.
|
||||
*
|
||||
@@ -2942,70 +3154,6 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
setValidatorCount: AugmentedSubmittable<(updated: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>, [Compact<u32>]>;
|
||||
/**
|
||||
* Submit an election result to the chain. If the solution:
|
||||
*
|
||||
* 1. is valid.
|
||||
* 2. has a better score than a potentially existing solution on chain.
|
||||
*
|
||||
* then, it will be _put_ on chain.
|
||||
*
|
||||
* A solution consists of two pieces of data:
|
||||
*
|
||||
* 1. `winners`: a flat vector of all the winners of the round.
|
||||
* 2. `assignments`: the compact version of an assignment vector that encodes the edge
|
||||
* weights.
|
||||
*
|
||||
* Both of which may be computed using _phragmen_, or any other algorithm.
|
||||
*
|
||||
* Additionally, the submitter must provide:
|
||||
*
|
||||
* - The `score` that they claim their solution has.
|
||||
*
|
||||
* Both validators and nominators will be represented by indices in the solution. The
|
||||
* indices should respect the corresponding types ([`ValidatorIndex`] and
|
||||
* [`NominatorIndex`]). Moreover, they should be valid when used to index into
|
||||
* [`SnapshotValidators`] and [`SnapshotNominators`]. Any invalid index will cause the
|
||||
* solution to be rejected. These two storage items are set during the election window and
|
||||
* may be used to determine the indices.
|
||||
*
|
||||
* A solution is valid if:
|
||||
*
|
||||
* 0. It is submitted when [`EraElectionStatus`] is `Open`.
|
||||
* 1. Its claimed score is equal to the score computed on-chain.
|
||||
* 2. Presents the correct number of winners.
|
||||
* 3. All indexes must be value according to the snapshot vectors. All edge values must
|
||||
* also be correct and should not overflow the granularity of the ratio type (i.e. 256
|
||||
* or billion).
|
||||
* 4. For each edge, all targets are actually nominated by the voter.
|
||||
* 5. Has correct self-votes.
|
||||
*
|
||||
* A solutions score is consisted of 3 parameters:
|
||||
*
|
||||
* 1. `min { support.total }` for each support of a winner. This value should be maximized.
|
||||
* 2. `sum { support.total }` for each support of a winner. This value should be minimized.
|
||||
* 3. `sum { support.total^2 }` for each support of a winner. This value should be
|
||||
* minimized (to ensure less variance)
|
||||
*
|
||||
* # <weight>
|
||||
* The transaction is assumed to be the longest path, a better solution.
|
||||
* - Initial solution is almost the same.
|
||||
* - Worse solution is retraced in pre-dispatch-checks which sets its own weight.
|
||||
* # </weight>
|
||||
**/
|
||||
submitElectionSolution: AugmentedSubmittable<(winners: Vec<ValidatorIndex> | (ValidatorIndex | AnyNumber | Uint8Array)[], compact: CompactAssignments | { votes1?: any; votes2?: any; votes3?: any; votes4?: any; votes5?: any; votes6?: any; votes7?: any; votes8?: any; votes9?: any; votes10?: any; votes11?: any; votes12?: any; votes13?: any; votes14?: any; votes15?: any; votes16?: any } | string | Uint8Array, score: ElectionScore, era: EraIndex | AnyNumber | Uint8Array, size: ElectionSize | { validators?: any; nominators?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Vec<ValidatorIndex>, CompactAssignments, ElectionScore, EraIndex, ElectionSize]>;
|
||||
/**
|
||||
* Unsigned version of `submit_election_solution`.
|
||||
*
|
||||
* Note that this must pass the [`ValidateUnsigned`] check which only allows transactions
|
||||
* from the local node to be included. In other words, only the block author can include a
|
||||
* transaction in the block.
|
||||
*
|
||||
* # <weight>
|
||||
* See [`submit_election_solution`].
|
||||
* # </weight>
|
||||
**/
|
||||
submitElectionSolutionUnsigned: AugmentedSubmittable<(winners: Vec<ValidatorIndex> | (ValidatorIndex | AnyNumber | Uint8Array)[], compact: CompactAssignments | { votes1?: any; votes2?: any; votes3?: any; votes4?: any; votes5?: any; votes6?: any; votes7?: any; votes8?: any; votes9?: any; votes10?: any; votes11?: any; votes12?: any; votes13?: any; votes14?: any; votes15?: any; votes16?: any } | string | Uint8Array, score: ElectionScore, era: EraIndex | AnyNumber | Uint8Array, size: ElectionSize | { validators?: any; nominators?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Vec<ValidatorIndex>, CompactAssignments, ElectionScore, EraIndex, ElectionSize]>;
|
||||
/**
|
||||
* Schedule a portion of the stash to be unlocked ready for transfer out after the bond
|
||||
* period ends. If this leaves an amount actively bonded less than
|
||||
@@ -3060,7 +3208,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Nominators, Validators
|
||||
* # </weight>
|
||||
**/
|
||||
validate: AugmentedSubmittable<(prefs: ValidatorPrefs | { commission?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [ValidatorPrefs]>;
|
||||
validate: AugmentedSubmittable<(prefs: ValidatorPrefs | { commission?: any; blocked?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [ValidatorPrefs]>;
|
||||
/**
|
||||
* Remove any unlocked chunks from the `unlocking` queue from our management.
|
||||
*
|
||||
@@ -3187,11 +3335,18 @@ declare module '@polkadot/api/types/submittable' {
|
||||
*
|
||||
* # <weight>
|
||||
* - `O(1)`
|
||||
* - Base Weight: 0.665 µs, independent of remark length.
|
||||
* - No DB operations.
|
||||
* # </weight>
|
||||
**/
|
||||
remark: AugmentedSubmittable<(remark: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Bytes]>;
|
||||
/**
|
||||
* Make some on-chain remark and emit event.
|
||||
*
|
||||
* # <weight>
|
||||
* - `O(b)` where b is the length of the remark.
|
||||
* - 1 event.
|
||||
* # </weight>
|
||||
**/
|
||||
remarkWithEvent: AugmentedSubmittable<(remark: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [Bytes]>;
|
||||
/**
|
||||
* Set the new changes trie configuration.
|
||||
*
|
||||
@@ -3719,7 +3874,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Unlock any vested funds of the sender account.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have funds still
|
||||
* locked under this module.
|
||||
* locked under this pallet.
|
||||
*
|
||||
* Emits either `VestingCompleted` or `VestingUpdated`.
|
||||
*
|
||||
@@ -3737,7 +3892,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
* - `target`: The account whose vested funds should be unlocked. Must have funds still
|
||||
* locked under this module.
|
||||
* locked under this pallet.
|
||||
*
|
||||
* Emits either `VestingCompleted` or `VestingUpdated`.
|
||||
*
|
||||
|
||||
@@ -79,7 +79,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
protected _rpc?: DecoratedRpc<ApiType, RpcInterface>;
|
||||
|
||||
protected _rpcCore: RpcCore;
|
||||
protected _rpcCore: RpcCore & RpcInterface;
|
||||
|
||||
protected _runtimeChain?: Text;
|
||||
|
||||
@@ -136,6 +136,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
this.#instanceId = `${++instanceCounter}`;
|
||||
this.#registry = options.source?.registry || options.registry || new TypeRegistry();
|
||||
this._rx.registry = this.#registry;
|
||||
|
||||
const thisProvider = options.source
|
||||
? options.source._rpcCore.provider.clone()
|
||||
@@ -144,10 +145,11 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
this._decorateMethod = decorateMethod;
|
||||
this._options = options;
|
||||
this._type = type;
|
||||
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, thisProvider, this._options.rpc);
|
||||
|
||||
// The RPC interface decorates the known interfaces on init
|
||||
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, thisProvider, this._options.rpc) as (RpcCore & RpcInterface);
|
||||
this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected);
|
||||
this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
|
||||
this._rx.registry = this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,7 +283,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
});
|
||||
}
|
||||
|
||||
protected _decorateRpc<ApiType extends ApiTypes> (rpc: RpcCore, decorateMethod: DecorateMethod<ApiType>, input: Partial<DecoratedRpc<ApiType, RpcInterface>> = {}): DecoratedRpc<ApiType, RpcInterface> {
|
||||
protected _decorateRpc<ApiType extends ApiTypes> (rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod<ApiType>, input: Partial<DecoratedRpc<ApiType, RpcInterface>> = {}): DecoratedRpc<ApiType, RpcInterface> {
|
||||
return rpc.sections.reduce((out, _sectionName): DecoratedRpc<ApiType, RpcInterface> => {
|
||||
const sectionName = _sectionName as keyof DecoratedRpc<ApiType, RpcInterface>;
|
||||
|
||||
@@ -492,9 +494,11 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
)
|
||||
),
|
||||
tap((keys): void => {
|
||||
keys.length === PAGE_SIZE
|
||||
? startSubject.next(keys[PAGE_SIZE - 1].toHex())
|
||||
: startSubject.complete();
|
||||
setTimeout((): void => {
|
||||
keys.length === PAGE_SIZE
|
||||
? startSubject.next(keys[PAGE_SIZE - 1].toHex())
|
||||
: startSubject.complete();
|
||||
}, 0);
|
||||
}),
|
||||
toArray(), // toArray since we want to startSubject to be completed
|
||||
map((keysArr: StorageKey[][]) => arrayFlatten(keysArr))
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { ApiInterfaceRx, ApiTypes, DecoratedErrors, DecoratedEvents, Decora
|
||||
|
||||
import { assertReturn } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from '../detectPackage';
|
||||
import { packageInfo } from '../packageInfo';
|
||||
import { Init } from './Init';
|
||||
|
||||
interface PkgJson {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Text } from '@polkadot/types';
|
||||
import type { ChainProperties, Hash, RuntimeVersion, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import type { ChainProperties, Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { Observable, Subscription } from '@polkadot/x-rxjs';
|
||||
import type { ApiBase, ApiOptions, ApiTypes, DecorateMethod } from '../types';
|
||||
@@ -12,17 +12,16 @@ import BN from 'bn.js';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/Extrinsic';
|
||||
import { getSpecAlias, getSpecExtensions, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
|
||||
import { assert, BN_ZERO, logger, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
|
||||
import { assert, BN_ZERO, logger, stringify, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { detectedCapabilities } from './capabilities';
|
||||
import { Decorate } from './Decorate';
|
||||
import { detectedCapabilities } from './util';
|
||||
|
||||
const KEEPALIVE_INTERVAL = 15000;
|
||||
const KEEPALIVE_INTERVAL = 10000;
|
||||
const DEFAULT_BLOCKNUMBER = { unwrap: () => BN_ZERO };
|
||||
|
||||
const l = logger('api/init');
|
||||
@@ -32,7 +31,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
#registries: VersionedRegistry[] = [];
|
||||
|
||||
#updateSub?: Subscription;
|
||||
#updateSub?: Subscription | null = null;
|
||||
|
||||
constructor (options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(options, type, decorateMethod);
|
||||
@@ -85,6 +84,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
registry.setChainProperties(chainProps || this.registry.getChainProperties());
|
||||
registry.setKnownTypes(this._options);
|
||||
registry.register(getSpecTypes(registry, chain, version.specName, version.specVersion));
|
||||
registry.setHasher(getSpecHasher(registry, chain, version.specName));
|
||||
|
||||
// for bundled types, pull through the aliases defined
|
||||
if (registry.knownTypes.typesBundle) {
|
||||
@@ -139,7 +139,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
// nothing has been found, construct new
|
||||
const metadata = await this._rpcCore.state.getMetadata(header.parentHash).toPromise();
|
||||
const registry = this._initRegistry(new TypeRegistry(), this._runtimeChain as Text, version, metadata);
|
||||
const registry = this._initRegistry(new TypeRegistry(blockHash), this._runtimeChain as Text, version, metadata);
|
||||
|
||||
// For now, since this is new we ignore the capability lookups (this could be useful once proven)
|
||||
// this._detectCapabilities(registry, blockHash);
|
||||
@@ -156,10 +156,10 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
// on re-connection to the same chain, we don't want to re-do everything from chain again
|
||||
if (this._isReady) {
|
||||
return true;
|
||||
} else if (this.#updateSub) {
|
||||
this.#updateSub.unsubscribe();
|
||||
}
|
||||
|
||||
this._unsubscribeUpdates();
|
||||
|
||||
// only load from on-chain if we are not a clone (default path), alternatively
|
||||
// just use the values from the source instance provided
|
||||
[this._genesisHash, this._runtimeMetadata] = this._options.source?._isReady
|
||||
@@ -197,7 +197,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
if (Object.keys(types).length) {
|
||||
(registry || this.registry).register(types as Record<string, string>);
|
||||
|
||||
l.debug(`Capabilities detected${blockHash ? ` (${u8aToHex(u8aToU8a(blockHash))})` : ''}: ${JSON.stringify(types)}`);
|
||||
l.debug(() => `Capabilities detected${blockHash ? ` (${u8aToHex(u8aToU8a(blockHash))})` : ''}: ${stringify(types)}`);
|
||||
}
|
||||
})
|
||||
.catch(l.error);
|
||||
@@ -285,20 +285,8 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
return [genesisHash, metadata];
|
||||
}
|
||||
|
||||
private async _initFromMeta (metadata: Metadata): Promise<boolean> {
|
||||
const metaExtrinsic = metadata.asLatest.extrinsic;
|
||||
|
||||
// only inject if we are not a clone (global init)
|
||||
if (metaExtrinsic.version.gt(BN_ZERO)) {
|
||||
this._extrinsicType = metaExtrinsic.version.toNumber();
|
||||
} else if (!this._options.source) {
|
||||
// detect the extrinsic version in-use based on the last block
|
||||
const { block: { extrinsics: [firstTx] } }: SignedBlock = await this._rpcCore.chain.getBlock().toPromise();
|
||||
|
||||
// If we haven't sync-ed to 1 yes, this won't have any values
|
||||
this._extrinsicType = firstTx ? firstTx.type : LATEST_EXTRINSIC_VERSION;
|
||||
}
|
||||
|
||||
private _initFromMeta (metadata: Metadata): boolean {
|
||||
this._extrinsicType = metadata.asLatest.extrinsic.version.toNumber();
|
||||
this._rx.extrinsicType = this._extrinsicType;
|
||||
this._rx.genesisHash = this._genesisHash;
|
||||
this._rx.runtimeVersion = this._runtimeVersion as RuntimeVersion; // must be set here
|
||||
@@ -314,6 +302,25 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
return true;
|
||||
}
|
||||
|
||||
private _unsubscribeHealth (): void {
|
||||
if (this.#healthTimer) {
|
||||
clearInterval(this.#healthTimer);
|
||||
this.#healthTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private _unsubscribeUpdates (): void {
|
||||
if (this.#updateSub) {
|
||||
this.#updateSub.unsubscribe();
|
||||
this.#updateSub = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected _unsubscribe (): void {
|
||||
this._unsubscribeHealth();
|
||||
this._unsubscribeUpdates();
|
||||
}
|
||||
|
||||
#onProviderConnect = async (): Promise<void> => {
|
||||
this.emit('connected');
|
||||
this._isConnected.next(true);
|
||||
@@ -333,7 +340,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
}
|
||||
|
||||
this.#healthTimer = setInterval((): void => {
|
||||
this._rpcCore.system.health().toPromise().catch(() => null);
|
||||
this._rpcCore.system.health().toPromise().catch((error) => l.warn(`Health keepalive check failed: ${(error as Error).message}`));
|
||||
}, KEEPALIVE_INTERVAL);
|
||||
} catch (_error) {
|
||||
const error = new Error(`FATAL: Unable to initialize the API: ${(_error as Error).message}`);
|
||||
@@ -349,10 +356,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
this.emit('disconnected');
|
||||
this._isConnected.next(false);
|
||||
|
||||
if (this.#healthTimer) {
|
||||
clearInterval(this.#healthTimer);
|
||||
this.#healthTimer = null;
|
||||
}
|
||||
this._unsubscribeHealth();
|
||||
};
|
||||
|
||||
#onProviderError = (error: Error): void => {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { bool, Raw, u32 } from '@polkadot/types';
|
||||
import type { Releases } from '@polkadot/types/interfaces';
|
||||
import type { InterfaceTypes } from '@polkadot/types/types';
|
||||
|
||||
import { assert, compactFromU8a } from '@polkadot/util';
|
||||
import { combineLatest, Observable, of } from '@polkadot/x-rxjs';
|
||||
import { map, take } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
// the order and types needs to map with the all array setup below
|
||||
type ExtractedQ = [bool | null, bool | null, bool | null, Releases | null];
|
||||
|
||||
type ExtractedR = [Raw | null];
|
||||
|
||||
type ExtractedC = [u32 | null, u32 | null];
|
||||
|
||||
type DetectedKeys = keyof Pick<InterfaceTypes, 'AccountInfo' | 'ValidatorPrefs'>;
|
||||
|
||||
type DetectedValues = keyof InterfaceTypes;
|
||||
|
||||
interface DetectedTypes extends Record<DetectedKeys, DetectedValues> {
|
||||
AccountInfo: 'AccountInfoWithRefCount' | 'AccountInfoWithDualRefCount' | 'AccountInfoWithTripleRefCount',
|
||||
Keys: 'SessionKeys1' | 'SessionKeys2' | 'SessionKeys3' | 'SessionKeys4' | 'SessionKeys5' | 'SessionKeys6' | 'SessionKeys7' | 'SessionKeys8' | 'SessionKeys9' | 'SessionKeys10';
|
||||
RefCount: 'u8' | 'u32',
|
||||
SlotRange: Record<string, unknown>;
|
||||
ValidatorPrefs: 'ValidatorPrefsWithBlocked' | 'ValidatorPrefsWithCommission';
|
||||
WinningData: string;
|
||||
}
|
||||
|
||||
interface AvailableMap<T> {
|
||||
filtered: T[];
|
||||
included: boolean[];
|
||||
original: T[];
|
||||
}
|
||||
|
||||
interface Constants {
|
||||
accountIdLength: number;
|
||||
}
|
||||
|
||||
const NumberMap = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];
|
||||
|
||||
function mapCapabilities ({ accountIdLength }: Constants, [leasePeriodsPerSlot, slotRangeCount]: ExtractedC, [systemRefcount32, systemRefcountDual, systemRefcountTriple, stakingVersion]: ExtractedQ, [keys]: ExtractedR): Partial<DetectedTypes> {
|
||||
const types: Partial<DetectedTypes> = {};
|
||||
|
||||
// AccountInfo
|
||||
if (systemRefcountTriple && systemRefcountTriple.isTrue) {
|
||||
types.AccountInfo = 'AccountInfoWithTripleRefCount';
|
||||
} else if (systemRefcountDual && systemRefcountDual.isTrue) {
|
||||
types.AccountInfo = 'AccountInfoWithDualRefCount';
|
||||
} else {
|
||||
types.AccountInfo = 'AccountInfoWithRefCount';
|
||||
|
||||
if (!systemRefcount32 || systemRefcount32.isFalse) {
|
||||
types.RefCount = 'u8';
|
||||
}
|
||||
}
|
||||
|
||||
// ValidatorPrefs
|
||||
if (stakingVersion) {
|
||||
if (stakingVersion.index >= 4) { // v1 = index 0, V5 = index 4
|
||||
types.ValidatorPrefs = 'ValidatorPrefsWithBlocked';
|
||||
} else {
|
||||
types.ValidatorPrefs = 'ValidatorPrefsWithCommission';
|
||||
}
|
||||
}
|
||||
|
||||
// Keys
|
||||
if (keys) {
|
||||
try {
|
||||
const [offset, numItems] = compactFromU8a(keys);
|
||||
const tupleLength = (keys.length - offset) / numItems.toNumber();
|
||||
const numIds = tupleLength / accountIdLength;
|
||||
const numIdsRound = Math.floor(numIds);
|
||||
|
||||
assert(numIds >= 2 && numIds <= 11, () => `Detected ${numIds} in Keys, should be >= 2 and <= 11`);
|
||||
|
||||
if (numIdsRound !== numIds) {
|
||||
// Beefy?
|
||||
if ((((numIdsRound - 1) * accountIdLength) + 33) === tupleLength) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
types.Keys = `SessionKeys${numIdsRound - 1}B`;
|
||||
} else {
|
||||
assert(false, () => `Expected integer number of keys, found ${numIds.toFixed(2)}`);
|
||||
}
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
types.Keys = `SessionKeys${numIds - 1}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
// auctions
|
||||
if (leasePeriodsPerSlot && slotRangeCount) {
|
||||
const _enum: string[] = [];
|
||||
|
||||
for (let i = 0; leasePeriodsPerSlot.gtn(i); i++) {
|
||||
for (let j = i; leasePeriodsPerSlot.gtn(j); j++) {
|
||||
_enum.push(`${NumberMap[i]}${NumberMap[j]}`);
|
||||
}
|
||||
}
|
||||
|
||||
types.SlotRange = { _enum };
|
||||
types.WinningData = `[WinningDataEntry; ${slotRangeCount.toNumber()}]`;
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
function filterEntries <T> (original: T[]): AvailableMap<T> {
|
||||
const included = original.map((c) => !!c);
|
||||
const filtered = original.filter((_, index) => included[index]);
|
||||
|
||||
return { filtered, included, original };
|
||||
}
|
||||
|
||||
function extractResults <R, T = unknown> (results: unknown[], map: AvailableMap<T>): R {
|
||||
let offset = -1;
|
||||
|
||||
return map.included.map((isIncluded) =>
|
||||
isIncluded
|
||||
? results[++offset]
|
||||
: null
|
||||
) as unknown as R;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Query the chain for the specific capabilities
|
||||
*/
|
||||
export function detectedCapabilities (api: ApiInterfaceRx, blockHash?: Uint8Array | string | undefined): Observable<Partial<DetectedTypes>> {
|
||||
const consts = filterEntries([
|
||||
api.consts.auctions?.leasePeriodsPerSlot,
|
||||
api.consts.auctions?.slotRangeCount
|
||||
]);
|
||||
const queries = filterEntries([
|
||||
api.query.system?.upgradedToU32RefCount,
|
||||
api.query.system?.upgradedToDualRefCount,
|
||||
api.query.system?.upgradedToTripleRefCount,
|
||||
api.query.staking?.storageVersion
|
||||
]);
|
||||
const raws = filterEntries([
|
||||
api.query.session?.queuedKeys
|
||||
]);
|
||||
|
||||
return combineLatest([
|
||||
consts.filtered.length
|
||||
? blockHash
|
||||
// FIXME consts don't have .at as of yet...
|
||||
? of([])
|
||||
: of(consts.filtered)
|
||||
: of([]),
|
||||
queries.filtered.length
|
||||
? blockHash
|
||||
? combineLatest(queries.filtered.map((c) => c.at(blockHash)))
|
||||
: api.queryMulti(queries.filtered)
|
||||
: of([]),
|
||||
raws.filtered.length
|
||||
? blockHash
|
||||
? combineLatest(raws.filtered.map((k) => api.rpc.state.getStorage.raw(k.key(), blockHash)))
|
||||
: combineLatest(raws.filtered.map((k) => api.rpc.state.getStorage.raw(k.key())))
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([cResults, qResults, rResults]): Partial<DetectedTypes> =>
|
||||
mapCapabilities(
|
||||
{
|
||||
accountIdLength: api.registry.createType('AccountId').encodedLength
|
||||
},
|
||||
extractResults<ExtractedC>(cResults, consts),
|
||||
extractResults<ExtractedQ>(qResults, queries),
|
||||
extractResults<ExtractedR>(rResults, raws)
|
||||
)
|
||||
),
|
||||
take(1)
|
||||
);
|
||||
}
|
||||
@@ -50,6 +50,8 @@ export abstract class ApiBase<ApiType extends ApiTypes> extends Getters<ApiType>
|
||||
* @description Disconnect from the underlying provider, halting all network traffic
|
||||
*/
|
||||
public disconnect (): Promise<void> {
|
||||
this._unsubscribe();
|
||||
|
||||
return this._rpcCore.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { bool } from '@polkadot/types';
|
||||
import type { Releases } from '@polkadot/types/interfaces';
|
||||
import type { InterfaceTypes } from '@polkadot/types/types';
|
||||
|
||||
import { combineLatest, Observable, of } from '@polkadot/x-rxjs';
|
||||
import { map, take } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
// the order and types needs to map with the all array setup below
|
||||
type Extracted = [bool | null, bool | null, Releases | null];
|
||||
|
||||
type DetectedKeys = keyof Pick<InterfaceTypes, 'AccountInfo' | 'ValidatorPrefs'>;
|
||||
|
||||
type DetectedValues = keyof InterfaceTypes;
|
||||
|
||||
interface DetectedTypes extends Record<DetectedKeys, DetectedValues> {
|
||||
AccountInfo: 'AccountInfoWithRefCount' | 'AccountInfoWithProviders',
|
||||
ValidatorPrefs: 'ValidatorPrefsWithBlocked' | 'ValidatorPrefsWithCommission';
|
||||
}
|
||||
|
||||
function mapCapabilities ([systemRefcount32, systemRefcountDual, stakingVersion]: Extracted): Partial<DetectedTypes> {
|
||||
const types: Partial<DetectedTypes> = {};
|
||||
|
||||
// AccountInfo
|
||||
if (systemRefcountDual && systemRefcountDual.isTrue) {
|
||||
types.AccountInfo = 'AccountInfoWithProviders';
|
||||
} else if (systemRefcount32 && systemRefcount32.isTrue) {
|
||||
types.AccountInfo = 'AccountInfoWithRefCount';
|
||||
}
|
||||
|
||||
// ValidatorPrefs
|
||||
if (stakingVersion) {
|
||||
if (stakingVersion.index >= 4) { // v1 = index 0, V5 = index 4
|
||||
types.ValidatorPrefs = 'ValidatorPrefsWithBlocked';
|
||||
} else {
|
||||
types.ValidatorPrefs = 'ValidatorPrefsWithCommission';
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Query the chain for the specific capabilities
|
||||
*/
|
||||
export function detectedCapabilities (api: ApiInterfaceRx, blockHash?: Uint8Array | string | undefined): Observable<Partial<DetectedTypes>> {
|
||||
const all = [
|
||||
api.query.system?.upgradedToU32RefCount,
|
||||
api.query.system?.upgradedToDualRefCount,
|
||||
api.query.staking?.storageVersion
|
||||
];
|
||||
const included = all.map((c) => !!c);
|
||||
const filtered = all.filter((_, index) => included[index]);
|
||||
|
||||
return (
|
||||
filtered.length
|
||||
? blockHash
|
||||
? combineLatest(filtered.map((c) => c.at(blockHash)))
|
||||
: api.queryMulti(filtered)
|
||||
: of([])
|
||||
).pipe(
|
||||
map((results): Partial<DetectedTypes> => {
|
||||
let offset = -1;
|
||||
|
||||
return mapCapabilities(
|
||||
included.map((isIncluded) => isIncluded ? results[++offset] : null) as Extracted
|
||||
);
|
||||
}),
|
||||
take(1)
|
||||
);
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import type { HeaderExtended } from '@polkadot/api-derive/types';
|
||||
import type { StorageKey } from '@polkadot/types';
|
||||
import type { AccountId, Balance, DispatchErrorModule, Event, Header, Index } from '@polkadot/types/interfaces';
|
||||
import type { AnyTuple, IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs';
|
||||
import { createTypeUnsafe, TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
|
||||
@@ -1,25 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
||||
//
|
||||
// new URL(import.meta.url).pathname)
|
||||
//
|
||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
||||
// there is a complete dead end with usage thereof
|
||||
//
|
||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
||||
//
|
||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
import { packageInfo as deriveInfo } from '@polkadot/api-derive/packageInfo';
|
||||
import { packageInfo as metaInfo } from '@polkadot/metadata/packageInfo';
|
||||
import { packageInfo as coreInfo } from '@polkadot/rpc-core/packageInfo';
|
||||
import { packageInfo as providerInfo } from '@polkadot/rpc-provider/packageInfo';
|
||||
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
||||
import { packageInfo as knownInfo } from '@polkadot/types-known/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import packageInfo from './package-info.json';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [deriveInfo, metaInfo, coreInfo, providerInfo, typesInfo, knownInfo]);
|
||||
|
||||
@@ -6,7 +6,7 @@ import './detectPackage';
|
||||
export { Keyring } from '@polkadot/keyring';
|
||||
export { WsProvider } from '@polkadot/rpc-provider/ws';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
export { ApiPromise } from './promise';
|
||||
export { ApiRx } from './rx';
|
||||
|
||||
export { SubmittableResult } from './submittable';
|
||||
export { ApiRx } from './rx';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api', version: '4.7.2' };
|
||||
@@ -211,7 +211,19 @@ export class ApiPromise extends ApiBase<'promise'> {
|
||||
* ```
|
||||
*/
|
||||
public static create (options?: ApiOptions): Promise<ApiPromise> {
|
||||
return new ApiPromise(options).isReady;
|
||||
const instance = new ApiPromise(options);
|
||||
|
||||
if (options && options.throwOnConnect) {
|
||||
return instance.isReadyOrError;
|
||||
}
|
||||
|
||||
// Swallow any rejections on isReadyOrError
|
||||
// (in Node 15.x this creates issues, when not being looked at)
|
||||
instance.isReadyOrError.catch(() => {
|
||||
// ignore
|
||||
});
|
||||
|
||||
return instance.isReady;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,18 +247,14 @@ export class ApiPromise extends ApiBase<'promise'> {
|
||||
super(options, 'promise', decorateMethod);
|
||||
|
||||
this.#isReadyPromise = new Promise((resolve): void => {
|
||||
super.once('ready', (): void => {
|
||||
resolve(this);
|
||||
});
|
||||
super.once('ready', () => resolve(this));
|
||||
});
|
||||
|
||||
this.#isReadyOrErrorPromise = new Promise((resolve, reject): void => {
|
||||
super.once('ready', (): void => {
|
||||
resolve(this);
|
||||
});
|
||||
super.once('error', (e): void => {
|
||||
reject(e);
|
||||
});
|
||||
const tracker = promiseTracker(resolve, reject);
|
||||
|
||||
super.once('ready', () => tracker.resolve(this));
|
||||
super.once('error', (e) => tracker.reject(e));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -165,9 +165,7 @@ export class ApiRx extends ApiBase<'rxjs'> {
|
||||
this.#isReadyRx = from<Promise<ApiRx>>(
|
||||
// You can create an observable from an event, however my mind groks this form better
|
||||
new Promise((resolve): void => {
|
||||
super.on('ready', (): void => {
|
||||
resolve(this);
|
||||
});
|
||||
super.on('ready', () => resolve(this));
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,14 +32,17 @@ export class SubmittableResult implements ISubmittableResult {
|
||||
|
||||
public readonly dispatchInfo?: DispatchInfo;
|
||||
|
||||
public readonly internalError?: Error;
|
||||
|
||||
public readonly events: EventRecord[];
|
||||
|
||||
public readonly status: ExtrinsicStatus;
|
||||
|
||||
constructor ({ dispatchError, dispatchInfo, events, status }: SubmittableResultValue) {
|
||||
constructor ({ dispatchError, dispatchInfo, events, internalError, status }: SubmittableResultValue) {
|
||||
this.dispatchError = dispatchError || extractError(events);
|
||||
this.dispatchInfo = dispatchInfo || extractInfo(events);
|
||||
this.events = events || [];
|
||||
this.internalError = internalError;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@@ -85,6 +88,7 @@ export class SubmittableResult implements ISubmittableResult {
|
||||
dispatchError: this.dispatchError?.toHuman(),
|
||||
dispatchInfo: this.dispatchInfo?.toHuman(),
|
||||
events: this.events.map((event) => event.toHuman(isExtended)),
|
||||
internalError: this.internalError?.message.toString(),
|
||||
status: this.status.toHuman(isExtended)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { AddressOrPair, SignerOptions, SubmittableDryRunResult, Submittable
|
||||
|
||||
import { assert, isBn, isFunction, isNumber, isString, isU8a } from '@polkadot/util';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { first, map, mapTo, mergeMap, switchMap, tap } from '@polkadot/x-rxjs/operators';
|
||||
import { catchError, first, map, mapTo, mergeMap, switchMap, tap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { ApiBase } from '../base';
|
||||
import { filterEvents, isKeyringPair } from '../util';
|
||||
@@ -242,6 +242,9 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorate
|
||||
events: filterEvents(hash, block, events, status),
|
||||
status
|
||||
}))
|
||||
),
|
||||
catchError((internalError: Error) =>
|
||||
of(this.#transformResult(new SubmittableResult({ internalError, status })))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface SubmittableResultValue {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
events?: EventRecord[];
|
||||
internalError?: Error;
|
||||
status: ExtrinsicStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ export interface ApiOptions extends RegisteredTypes {
|
||||
* @description The source object to use for runtime information (only used when cloning)
|
||||
*/
|
||||
source?: ApiBase<any>;
|
||||
/**
|
||||
* @description Throws an error when the initial connection fails (same as isReadyOrError)
|
||||
*/
|
||||
throwOnConnect?: boolean;
|
||||
}
|
||||
|
||||
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
|
||||
|
||||
@@ -13,7 +13,7 @@ function sig ({ method, section }: StorageEntry, ...args: Type[]): string {
|
||||
function doDoubleMap (creator: StorageEntry, args: unknown[]): [StorageEntry, [any, any]] {
|
||||
const { key1, key2 } = creator.meta.type.asDoubleMap;
|
||||
|
||||
assert(args.length === 2, `${sig(creator, key1, key2)} is a doublemap, requiring 2 arguments, ${args.length} found`);
|
||||
assert(args.length === 2, () => `${sig(creator, key1, key2)} is a doublemap, requiring 2 arguments, ${args.length} found`);
|
||||
|
||||
// pass as tuple
|
||||
return [creator, args as [any, any]];
|
||||
@@ -22,7 +22,7 @@ function doDoubleMap (creator: StorageEntry, args: unknown[]): [StorageEntry, [a
|
||||
function doMap (creator: StorageEntry, args: unknown[]): [StorageEntry] | [StorageEntry, any] {
|
||||
const { key } = creator.meta.type.asMap;
|
||||
|
||||
assert(args.length === 1, `${sig(creator, key)} is a map, requiring 1 argument, ${args.length} found`);
|
||||
assert(args.length === 1, () => `${sig(creator, key)} is a map, requiring 1 argument, ${args.length} found`);
|
||||
|
||||
// expand
|
||||
return args.length
|
||||
@@ -41,7 +41,7 @@ export function extractStorageArgs (creator: StorageEntry, _args: unknown[]): [S
|
||||
return doMap(creator, args);
|
||||
}
|
||||
|
||||
assert(args.length === 0, `${sig(creator)} does not take any arguments, ${args.length} found`);
|
||||
assert(args.length === 0, () => `${sig(creator)} does not take any arguments, ${args.length} found`);
|
||||
|
||||
// no args
|
||||
return [creator];
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "3.9.2",
|
||||
"version": "4.7.2",
|
||||
"type": "module",
|
||||
"description": "Helpers to extract information from runtime metadata",
|
||||
"main": "index.js",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"repository": "github:polkadot-js/api",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -15,14 +19,14 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.13",
|
||||
"@polkadot/types": "3.9.2",
|
||||
"@polkadot/types-known": "3.9.2",
|
||||
"@polkadot/util": "^5.6.2",
|
||||
"@polkadot/util-crypto": "^5.6.2",
|
||||
"@babel/runtime": "^7.13.17",
|
||||
"@polkadot/types": "4.7.2",
|
||||
"@polkadot/types-known": "4.7.2",
|
||||
"@polkadot/util": "^6.3.1",
|
||||
"@polkadot/util-crypto": "^6.3.1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.6.2"
|
||||
"@polkadot/keyring": "^6.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export class MagicNumber extends U32 {
|
||||
if (!this.isEmpty) {
|
||||
const magic = registry.createType('u32', MAGIC_NUMBER);
|
||||
|
||||
assert(this.eq(magic), `MagicNumber mismatch: expected ${magic.toHex()}, found ${this.toHex()}`);
|
||||
assert(this.eq(magic), () => `MagicNumber mismatch: expected ${magic.toHex()}, found ${this.toHex()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { isString, u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
import { isString, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { MetadataVersioned } from './MetadataVersioned';
|
||||
|
||||
@@ -11,7 +11,7 @@ import { MetadataVersioned } from './MetadataVersioned';
|
||||
const VERSION_IDX = 4;
|
||||
|
||||
// magic + lowest supported version
|
||||
const EMPTY_METADATA = u8aConcat(new Uint8Array([0x6d, 0x65, 0x74, 0x61, 9]));
|
||||
const EMPTY_METADATA = new Uint8Array([0x6d, 0x65, 0x74, 0x61, 9]);
|
||||
const EMPTY_U8A = new Uint8Array();
|
||||
|
||||
function sanitizeInput (_value: Uint8Array | string = EMPTY_U8A): Uint8Array {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { MetadataAll, MetadataLatest, MetadataV9, MetadataV10, MetadataV11, MetadataV12 } from '@polkadot/types/interfaces/metadata';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { AnyJson, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { Struct } from '@polkadot/types/codec';
|
||||
import { assert } from '@polkadot/util';
|
||||
@@ -33,18 +33,18 @@ export class MetadataVersioned extends Struct {
|
||||
}, value as Map<unknown, unknown>);
|
||||
}
|
||||
|
||||
private _assertVersion (version: number): boolean {
|
||||
assert(this.version <= version, `Cannot convert metadata from v${this.version} to v${version}`);
|
||||
#assertVersion = (version: number): boolean => {
|
||||
assert(this.version <= version, () => `Cannot convert metadata from v${this.version} to v${version}`);
|
||||
|
||||
return this.version === version;
|
||||
}
|
||||
};
|
||||
|
||||
private _getVersion<T extends MetaMapped, F extends MetaMapped> (version: MetaVersions, fromPrev: (registry: Registry, input: F, metaVersion: number) => T): T {
|
||||
#getVersion = <T extends MetaMapped, F extends MetaMapped>(version: MetaVersions, fromPrev: (registry: Registry, input: F, metaVersion: number) => T): T => {
|
||||
const asCurr = `asV${version}` as MetaAsX;
|
||||
const asPrev = `asV${version - 1}` as MetaAsX;
|
||||
|
||||
if (this._assertVersion(version)) {
|
||||
return this._metadata[asCurr] as T;
|
||||
if (this.#assertVersion(version)) {
|
||||
return this.#metadata()[asCurr] as T;
|
||||
}
|
||||
|
||||
if (!this.#converted.has(version)) {
|
||||
@@ -52,6 +52,13 @@ export class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
return this.#converted.get(version) as T;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description the metadata wrapped
|
||||
*/
|
||||
#metadata = (): MetadataAll => {
|
||||
return this.get('metadata') as MetadataAll;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,30 +75,30 @@ export class MetadataVersioned extends Struct {
|
||||
* @description Returns the wrapped metadata as a V9 object
|
||||
*/
|
||||
public get asV9 (): MetadataV9 {
|
||||
this._assertVersion(9);
|
||||
this.#assertVersion(9);
|
||||
|
||||
return this._metadata.asV9;
|
||||
return this.#metadata().asV9;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V10 object
|
||||
*/
|
||||
public get asV10 (): MetadataV10 {
|
||||
return this._getVersion(10, toV10);
|
||||
return this.#getVersion(10, toV10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V11 object
|
||||
*/
|
||||
public get asV11 (): MetadataV11 {
|
||||
return this._getVersion(11, toV11);
|
||||
return this.#getVersion(11, toV11);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V12 object
|
||||
*/
|
||||
public get asV12 (): MetadataV12 {
|
||||
return this._getVersion(12, toV12);
|
||||
return this.#getVersion(12, toV12);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +106,7 @@ export class MetadataVersioned extends Struct {
|
||||
*/
|
||||
public get asLatest (): MetadataLatest {
|
||||
// This is non-existent & latest - applied here to do the module-specific type conversions
|
||||
return this._getVersion(13, toLatest);
|
||||
return this.#getVersion(13, toLatest);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,21 +116,26 @@ export class MetadataVersioned extends Struct {
|
||||
return this.get('magicNumber') as MagicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the metadata wrapped
|
||||
*/
|
||||
private get _metadata (): MetadataAll {
|
||||
return this.get('metadata') as MetadataAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the metadata version this structure represents
|
||||
*/
|
||||
public get version (): number {
|
||||
return this._metadata.index;
|
||||
return this.#metadata().index;
|
||||
}
|
||||
|
||||
public getUniqTypes (throwError: boolean): string[] {
|
||||
return getUniqTypes(this.registry, this.asLatest, throwError);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): Record<string, AnyJson> {
|
||||
// HACK(y): ensure that we apply the aliasses if we have not done so already, this is
|
||||
// needed to ensure we have the overrides as intended (only applied in toLatest)
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
this.asLatest;
|
||||
|
||||
return super.toJSON();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export function createUnchecked (registry: Registry, section: string, callIndex:
|
||||
const funcName = stringCamelCase(callMetadata.name);
|
||||
|
||||
const extrinsicFn = (...args: any[]): Call => {
|
||||
assert(expectedArgs.length === args.length, `Extrinsic ${section}.${funcName} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.`);
|
||||
assert(expectedArgs.length === args.length, () => `Extrinsic ${section}.${funcName} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.`);
|
||||
|
||||
return registry.createType('Call', {
|
||||
args,
|
||||
|
||||
@@ -30,4 +30,4 @@ export function expandMetadata (registry: Registry, metadata: Metadata): Decorat
|
||||
};
|
||||
}
|
||||
|
||||
export { decorateConstants, decorateExtrinsics, decorateStorage };
|
||||
export { decorateConstants, decorateErrors, decorateEvents, decorateExtrinsics, decorateStorage };
|
||||
|
||||
@@ -65,7 +65,7 @@ function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, args: [Cr
|
||||
const { meta: { name, type } } = itemFn;
|
||||
|
||||
// since we are passing an almost-unknown through, trust, but verify
|
||||
assert(Array.isArray(args) && !isUndefined(args[0]) && !isNull(args[0]) && !isUndefined(args[1]) && !isNull(args[1]), `${(name || 'unknown').toString()} is a DoubleMap and requires two arguments`);
|
||||
assert(Array.isArray(args) && !isUndefined(args[0]) && !isNull(args[0]) && !isUndefined(args[1]) && !isNull(args[1]), () => `${(name || 'unknown').toString()} is a DoubleMap and requires two arguments`);
|
||||
|
||||
// if this fails, we have bigger issues
|
||||
assert(!isUndefined(hasher2), '2 hashing functions should be defined for DoubleMaps');
|
||||
@@ -92,7 +92,7 @@ function createKey (registry: Registry, itemFn: CreateItemFn, arg: CreateArgType
|
||||
if (type.isMap) {
|
||||
const map = type.asMap;
|
||||
|
||||
assert(!isUndefined(arg) && !isNull(arg), `${name.toString()} is a Map and requires one argument`);
|
||||
assert(!isUndefined(arg) && !isNull(arg), () => `${name.toString()} is a Map and requires one argument`);
|
||||
|
||||
param = registry.createType(map.key.toString() as 'Raw', arg).toU8a();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { StorageEntry } from '@polkadot/types/primitive/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { Storage } from '../types';
|
||||
|
||||
import * as substrate from './substrate';
|
||||
import { substrate } from './substrate';
|
||||
|
||||
/** @internal */
|
||||
export function getStorage (registry: Registry, metaVersion: number): Storage {
|
||||
|
||||
@@ -12,6 +12,8 @@ interface SubstrateMetadata {
|
||||
type: string;
|
||||
}
|
||||
|
||||
type Creator = (registry: Registry, metaVersion: number) => StorageEntry;
|
||||
|
||||
// Small helper function to factorize code on this page.
|
||||
/** @internal */
|
||||
function createRuntimeFunction (method: string, key: string, { documentation, type }: SubstrateMetadata): (registry: Registry, metaVersion: number) => StorageEntry {
|
||||
@@ -29,27 +31,25 @@ function createRuntimeFunction (method: string, key: string, { documentation, ty
|
||||
}, { key, metaVersion, skipHashing: true });
|
||||
}
|
||||
|
||||
export const code = createRuntimeFunction('code', ':code', {
|
||||
documentation: 'Wasm code of the runtime.',
|
||||
type: 'Bytes'
|
||||
});
|
||||
|
||||
export const heapPages = createRuntimeFunction('heapPages', ':heappages', {
|
||||
documentation: 'Number of wasm linear memory pages required for execution of the runtime.',
|
||||
type: 'u64'
|
||||
});
|
||||
|
||||
export const extrinsicIndex = createRuntimeFunction('extrinsicIndex', ':extrinsic_index', {
|
||||
documentation: 'Current extrinsic index (u32) is stored under this key.',
|
||||
type: 'u32'
|
||||
});
|
||||
|
||||
export const changesTrieConfig = createRuntimeFunction('changesTrieConfig', ':changes_trie', {
|
||||
documentation: 'Changes trie configuration is stored under this key.',
|
||||
type: 'u32'
|
||||
});
|
||||
|
||||
export const childStorageKeyPrefix = createRuntimeFunction('childStorageKeyPrefix', ':child_storage:', {
|
||||
documentation: 'Prefix of child storage keys.',
|
||||
type: 'u32'
|
||||
});
|
||||
export const substrate: Record<string, Creator> = {
|
||||
changesTrieConfig: createRuntimeFunction('changesTrieConfig', ':changes_trie', {
|
||||
documentation: ' Changes trie configuration is stored under this key.',
|
||||
type: 'u32'
|
||||
}),
|
||||
childStorageKeyPrefix: createRuntimeFunction('childStorageKeyPrefix', ':child_storage:', {
|
||||
documentation: ' Prefix of child storage keys.',
|
||||
type: 'u32'
|
||||
}),
|
||||
code: createRuntimeFunction('code', ':code', {
|
||||
documentation: ' Wasm code of the runtime.',
|
||||
type: 'Bytes'
|
||||
}),
|
||||
extrinsicIndex: createRuntimeFunction('extrinsicIndex', ':extrinsic_index', {
|
||||
documentation: ' Current extrinsic index (u32) is stored under this key.',
|
||||
type: 'u32'
|
||||
}),
|
||||
heapPages: createRuntimeFunction('heapPages', ':heappages', {
|
||||
documentation: ' Number of wasm linear memory pages required for execution of the runtime.',
|
||||
type: 'u64'
|
||||
})
|
||||
};
|
||||
|
||||
@@ -1,25 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
||||
//
|
||||
// new URL(import.meta.url).pathname)
|
||||
//
|
||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
||||
// there is a complete dead end with usage thereof
|
||||
//
|
||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
||||
//
|
||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
||||
import { packageInfo as knownInfo } from '@polkadot/types-known/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import packageInfo from './package-info.json';
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [typesInfo, knownInfo]);
|
||||
|
||||
@@ -5,3 +5,4 @@ import './detectPackage';
|
||||
|
||||
export { Metadata } from './Metadata';
|
||||
export { decorateConstants, decorateExtrinsics, decorateStorage, expandMetadata } from './decorate';
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/metadata', version: '4.7.2' };
|
||||
@@ -5,6 +5,7 @@ import type { Codec, Registry } from '@polkadot/types/types';
|
||||
import type { MetadataInterface } from '../types';
|
||||
|
||||
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, hexToU8a, stringify, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../Metadata';
|
||||
import { getUniqTypes } from './getUniqTypes';
|
||||
@@ -21,7 +22,7 @@ export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry
|
||||
expect((metadata[`asV${version}` as keyof Metadata] as unknown as MetadataInterface<Modules>).modules.length).not.toBe(0);
|
||||
expect(metadata.toJSON()).toEqual(staticSubstrate);
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(metadata.toJSON()));
|
||||
console.error(stringify(metadata.toJSON()));
|
||||
|
||||
throw error;
|
||||
}
|
||||
@@ -47,19 +48,25 @@ export function toLatest<Modules extends Codec> (registry: Registry, version: nu
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function defaultValues (registry: Registry, rpcData: string, withThrow = true): void {
|
||||
export function defaultValues (registry: Registry, rpcData: string, withThrow = true, withFallbackCheck = false): void {
|
||||
describe('storage with default values', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
|
||||
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
|
||||
mod.storage.unwrap().items.forEach(({ fallback, name, type }): void => {
|
||||
const inner = unwrapStorageType(type);
|
||||
mod.storage.unwrap().items.forEach(({ fallback, modifier, name, type }): void => {
|
||||
const inner = unwrapStorageType(type, modifier.isOptional);
|
||||
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
|
||||
|
||||
it(`creates default types for ${location}`, (): void => {
|
||||
expect((): void => {
|
||||
try {
|
||||
registry.createType(inner, fallback);
|
||||
const type = registry.createType(inner, hexToU8a(fallback.toHex()));
|
||||
|
||||
if (withFallbackCheck) {
|
||||
const [hexType, hexOrig] = [u8aToHex(type.toU8a()), u8aToHex(fallback.toU8a(true))];
|
||||
|
||||
assert(hexType === hexOrig, () => `Fallback does not match (${((hexOrig.length - 2) / 2) - ((hexType.length - 2) / 2)} bytes missing): ${hexType} !== ${hexOrig}`);
|
||||
}
|
||||
} catch (error) {
|
||||
const message = `${location}:: ${(error as Error).message}`;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user