Compare commits

..
156 Commits
Author SHA1 Message Date
Github Actions c412f7fa11 [CI Skip] 1.13.1
skip-checks: true
2020-05-06 18:33:13 +00:00
Jaco Greeff a1ad90c2b4 1.13 (#2248)
* 1.13

* Add grandpa_roundState RPC

* RPC interfaces
2020-05-06 20:22:18 +02:00
Github Actions 92f62bfa15 [CI Skip] 1.13.0-beta.19
skip-checks: true
2020-05-06 16:48:28 +00:00
Jaco Greeff fa9c5778be Adjust Centrifuge versions (#2247) 2020-05-06 18:37:44 +02:00
Github Actions e6f877621a [CI Skip] 1.13.0-beta.18
skip-checks: true
2020-05-06 15:22:36 +00:00
Jaco Greeff 5c35a70e9d Centrifuge Chain Node (#2246) 2020-05-06 17:11:33 +02:00
Github Actions a287096cc3 [CI Skip] 1.13.0-beta.17
skip-checks: true
2020-05-06 13:47:59 +00:00
Jaco Greeff c35f31bfbd Adjust mock timeouts (#2244)
* Adjust mock timeouts

* Play with timeouts some more...

* Ooops, overzealous search-and-replace
2020-05-06 15:36:20 +02:00
Jaco Greeff 718afa91e3 Multiple endpoints CHANGELOG (#2243) 2020-05-06 15:10:37 +02:00
Hoani BrysonandJaco Greeff 102a06b0f2 Multiple Endpoint support for WsProvider (#2234)
* Fix incorrect ws connect test cases

* Make endpoint an array of endpoints

* Add requirement that WsProvider endpoint arrays must not be empty

* Simple endpoint increment

* Add multi-endpoint test for endpoint closing its connection

* Implement endpoint round robin

* Revert change to mock's TEST_WS_URL

* Address Lint errors

* Change endpoint variable to plural in WsProvider

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* Review corrections to WsProvider

* Grouping improvement in WsProvider connect

* Correct endpoint logging to only show the specific endpoint involved

* Correct ordering of endpoint increment on connect

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-05-06 14:42:30 +02:00
Github Actions 58f0df1ef0 [CI Skip] 1.13.0-beta.16
skip-checks: true
2020-05-06 12:08:40 +00:00
Jaco Greeff a458589222 Fix CompactAssignment decoding (#2242)
* Fix CompactAssignment decoding

* CHANGELOG
2020-05-06 13:56:17 +02:00
Github Actions deef4ce4c7 [CI Skip] 1.13.0-beta.15
skip-checks: true
2020-05-06 08:36:29 +00:00
Jaco Greeff f5d2449407 Grandpa Equivocation types (#2239)
* Grandpa Equivocation types

* typo
2020-05-06 10:25:37 +02:00
Github Actions 8bb1d1259e [CI Skip] 1.13.0-beta.14
skip-checks: true
2020-05-06 08:23:10 +00:00
Jaco Greeff abd860d548 Bump deps (#2240)
* Bump deps

* Jest revert
2020-05-06 10:11:58 +02:00
Github Actions 25936d882f [CI Skip] 1.13.0-beta.13
skip-checks: true
2020-05-06 06:29:54 +00:00
Keith YeungandJaco Greeff 9deaff54e4 Make the 2nd argument to SubmittableExtrinsic.sign/signAsync optional (#2238)
* Make the 2nd argument to SubmittableExtrinsic.sign/signAsync optional

* Use default argument for optionsOrNonce

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-05-06 08:17:51 +02:00
Github Actions bc479a995b [CI Skip] 1.13.0-beta.12
skip-checks: true
2020-05-05 09:44:03 +00:00
Jaco Greeff 458b7fa7e4 Update with latest Substrate metadata (#2233) 2020-05-05 11:33:04 +02:00
Github Actions 2fc17a66e1 [CI Skip] 1.13.0-beta.11
skip-checks: true
2020-05-05 05:26:31 +00:00
codingsh 94f81db568 #2182 - add: search for docs (#2232) 2020-05-05 07:16:39 +02:00
Github Actions e83d97c849 [CI Skip] 1.13.0-beta.10
skip-checks: true
2020-05-05 05:09:33 +00:00
Joshy Orndorff 4a497fa970 minor typo: RC -> RPC (#2229) 2020-05-05 06:58:52 +02:00
Github Actions cb40d459b5 [CI Skip] 1.13.0-beta.9
skip-checks: true
2020-05-04 18:40:00 +00:00
Jaco Greeff c70cdb351f Additional modules/methods in RPC samples 2020-05-04 20:29:02 +02:00
Github Actions 001aa0d011 [CI Skip] 1.13.0-beta.8
skip-checks: true
2020-05-04 15:58:01 +00:00
Jaco Greeff 961d27ad46 Update CHANGELOG.md 2020-05-04 17:47:09 +02:00
Github Actions 1c09bb69dd [CI Skip] 1.13.0-beta.7
skip-checks: true
2020-05-04 13:32:30 +00:00
Xiliang ChenandJaco Greeff 174510a928 use handlebars for code generation (#2228)
* use handlebars for code generation

* update docs

* fix isStrict

* fix lint

* Apply suggestions from code review

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* convert consts

* keep empty lines in doc comments

* update rpc

* update tx

* update interfaceRegistry

* update tsDef

* remove no longer used code

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-05-04 15:21:09 +02:00
Github Actions 39ed76f2de [CI Skip] 1.13.0-beta.6
skip-checks: true
2020-05-04 12:20:51 +00:00
Jaco Greeff 7d1c93db59 Update CHANGELOG.md 2020-05-04 14:08:18 +02:00
Github Actions e9b1b4ee77 [CI Skip] 1.13.0-beta.5
skip-checks: true
2020-05-01 19:11:49 +00:00
Jaco Greeff 2367978f6e Remove polkadot metadata (not mainatained, outdated) (#2227) 2020-05-01 21:01:08 +02:00
Github Actions e77050b9f5 [CI Skip] 1.13.0-beta.4
skip-checks: true
2020-04-30 13:24:43 +00:00
Jaco Greeff 844d1a2928 Allow failures on preimage (instead of swallow) (#2225) 2020-04-30 15:14:56 +02:00
Github Actions 6a70beda0f [CI Skip] 1.13.0-beta.3
skip-checks: true
2020-04-30 09:16:39 +00:00
Alexander Krupenkin 05a834b822 Fix extrinsic ECDSA signatures (#2222)
* Fix extrinsic ECDSA signatures

* Fix lint
2020-04-30 11:04:55 +02:00
Github Actions 6a3af506a4 [CI Skip] 1.13.0-beta.2
skip-checks: true
2020-04-30 07:37:46 +00:00
Jaco Greeff c82b85ef79 Bump deps (#2224) 2020-04-30 09:27:04 +02:00
Github Actions 91ab81ef60 [CI Skip] 1.13.0-beta.1
skip-checks: true
2020-04-30 05:47:17 +00:00
Jaco Greeff 3665690444 Beta bump (#2223) 2020-04-30 07:37:12 +02:00
Github Actions 03dcefceb5 [CI Skip] 1.12.2
skip-checks: true
2020-04-29 22:56:16 +00:00
Jaco Greeff e84be032f4 1.12.2 (stable util) 2020-04-30 00:46:45 +02:00
Github Actions 033ff7a28c [CI Skip] 1.12.1
skip-checks: true
2020-04-29 22:23:45 +00:00
Jaco Greeff 7c8b2abf92 1.12 (#2221) 2020-04-30 00:13:27 +02:00
Github Actions 5312ec1f3a [CI Skip] 1.12.0-beta.15
skip-checks: true
2020-04-29 16:13:00 +00:00
Matej Nemček cdfbf91ee6 added Kodadot to @polkadot/api users section (#2220) 2020-04-29 18:00:50 +02:00
Github Actions 14f2abdc37 [CI Skip] 1.12.0-beta.14
skip-checks: true
2020-04-29 15:50:05 +00:00
Jake Naviasky 04c8d49e9d Add configurable provider auto-reconnect time. (#2215) 2020-04-29 17:39:31 +02:00
Github Actions 722929d0d4 [CI Skip] 1.12.0-beta.13
skip-checks: true
2020-04-29 14:57:15 +00:00
Jaco Greeff d1fae523ac Fix CompactAssignments types (#2219)
* Fix CompactAssignments types

* Cleanup mistaken type adjustments
2020-04-29 16:45:59 +02:00
Github Actions ce9a92cdc0 [CI Skip] 1.12.0-beta.12
skip-checks: true
2020-04-27 17:09:59 +00:00
Jaco Greeff 3de09a2e27 Hack around preimage failures (#2217) 2020-04-27 18:59:18 +02:00
Github Actions f28479180f [CI Skip] 1.12.0-beta.11
skip-checks: true
2020-04-27 14:04:29 +00:00
Jaco Greeff 0d1d42f6c2 Update promise combineLatest with generics (#2214) 2020-04-27 15:53:17 +02:00
Github Actions c93dad0bc5 [CI Skip] 1.12.0-beta.10
skip-checks: true
2020-04-27 07:04:47 +00:00
Jaco Greeff e3d3a1ff71 Handle no keysReturn StorageChangeSet with no keys (#2212) 2020-04-27 08:54:02 +02:00
Github Actions 1c8bd896e1 [CI Skip] 1.12.0-beta.9
skip-checks: true
2020-04-26 11:56:32 +00:00
Jaco Greeff e0119c1873 Bump metadata to current Substrate master (incl. types) (#2210) 2020-04-26 13:46:36 +02:00
Github Actions defe81e560 [CI Skip] 1.12.0-beta.8
skip-checks: true
2020-04-26 11:42:47 +00:00
Xiliang Chen 932122cd21 subscribeStorage parameter should be optional (#2208) 2020-04-26 13:32:43 +02:00
Github Actions 40d035eca7 [CI Skip] 1.12.0-beta.7
skip-checks: true
2020-04-25 07:58:44 +00:00
Jaco Greeff a135abaea2 Fix flags (council may not exist) (#2207) 2020-04-25 09:47:46 +02:00
Github Actions 00b8c10881 [CI Skip] 1.12.0-beta.6
skip-checks: true
2020-04-24 14:34:08 +00:00
Jaco Greeff 11e7b90918 Bump deps (#2206) 2020-04-24 16:22:18 +02:00
Github Actions ae74467e6a [CI Skip] 1.12.0-beta.5
skip-checks: true
2020-04-24 13:40:02 +00:00
Jeremías Díaz 5a929d3810 remove unnecessary parentheses and duplicate types (#2204)
* remove unnecessary parentheses and duplicate types

* fix: remove test code
2020-04-24 15:28:47 +02:00
Github Actions 63732f1456 [CI Skip] 1.12.0-beta.4
skip-checks: true
2020-04-24 08:54:04 +00:00
Jaco Greeff ea6bb83c01 Voting delegations (#2205) 2020-04-24 10:41:30 +02:00
Github Actions d6a443ca2a [CI Skip] 1.12.0-beta.3
skip-checks: true
2020-04-23 09:50:46 +00:00
Jaco Greeff d983ee106c migrateEra is first stakerPayouts era (#2202) 2020-04-23 11:39:39 +02:00
Github Actions beed1df5bd [CI Skip] 1.12.0-beta.2
skip-checks: true
2020-04-22 09:04:55 +00:00
Jaco Greeff 426aef6088 Update .123trigger 2020-04-22 10:55:01 +02:00
Github Actions 9be9b3fb83 [CI Skip] 1.12.0-beta.1
skip-checks: true
2020-04-22 07:56:01 +00:00
Jaco Greeff 8676f30cbf Reset to beta 2020-04-22 09:44:59 +02:00
Github Actions 154561c34c [CI Skip] 1.11.2
skip-checks: true
2020-04-22 07:40:26 +00:00
Jaco Greeff 714b242ec0 0.11.2 (#2200) 2020-04-22 09:30:02 +02:00
Github Actions 32ce650ee1 [CI Skip] 1.12.0-beta.0
skip-checks: true
2020-04-21 17:05:00 +00:00
Jaco Greeff 3715df2f5b Additional parachains types (#2199)
* Additional parachains types

* missing extensions listing

* trigger
2020-04-21 18:53:00 +02:00
Github Actions dd6e6ddfc1 [CI Skip] 1.11.1
skip-checks: true
2020-04-21 07:47:25 +00:00
Jaco Greeff 9975f58cfb 1.11 (#2198)
* 1.11

* isOptional is custom RPC sample

* Names is one-liner for custom RPCs
2020-04-21 09:38:09 +02:00
Github Actions 536369261f [CI Skip] 1.11.0-beta.35
skip-checks: true
2020-04-21 07:10:16 +00:00
Jaco Greeff 33165e93dc Add state_getReadProof (#2196) 2020-04-21 09:00:03 +02:00
Github Actions 39a38a6c44 [CI Skip] 1.11.0-beta.34
skip-checks: true
2020-04-21 05:41:16 +00:00
Keith Ingram b18bdc37f9 Add api.derive.accounts.flags (#2195)
* account flags in new call

* Fix
2020-04-21 07:31:00 +02:00
Github Actions 79847aabf7 [CI Skip] 1.11.0-beta.33
skip-checks: true
2020-04-20 09:22:55 +00:00
Jaco Greeff ab75863d94 Fix derive.democracy.preimage signature (#2194) 2020-04-20 11:12:03 +02:00
Github Actions c908a27b7d [CI Skip] 1.11.0-beta.32
skip-checks: true
2020-04-18 07:31:19 +00:00
Jaco Greeff 98c7e5d5ea Optimize entries retrieval (#2193) 2020-04-18 09:21:06 +02:00
Github Actions fd4587a0bc [CI Skip] 1.11.0-beta.31
skip-checks: true
2020-04-17 13:41:21 +00:00
Jaco Greeff e211ae1667 Added types for DoubleVoteReport (parachains) (#2192) 2020-04-17 15:32:51 +02:00
Github Actions af735176fe [CI Skip] 1.11.0-beta.30
skip-checks: true
2020-04-17 10:34:48 +00:00
Jaco Greeff 9eb44d6e89 console warnings on the use of node-template (#2191)
* console warnings on the use of node-template

* Message formatting
2020-04-17 12:23:44 +02:00
Github Actions 379e841808 [CI Skip] 1.11.0-beta.29
skip-checks: true
2020-04-17 06:07:08 +00:00
Jaco Greeff 5c16b8e8a1 Adjust spec types (starting versions) (#2189) 2020-04-17 07:55:53 +02:00
Github Actions 96d7d9ff5a [CI Skip] 1.11.0-beta.28
skip-checks: true
2020-04-16 19:55:16 +00:00
Jaco Greeff e9fbbbbd42 Typos 2020-04-16 21:44:04 +02:00
Github Actions 73750ddb7d [CI Skip] 1.11.0-beta.27
skip-checks: true
2020-04-16 19:39:17 +00:00
Jaco Greeff 4e1145c66f FAQ entry for Weight adjustment (#2188)
* FAQ entry for Weight adjustment

* CHANGELOG entry for rxjs Observable exposure

* Event decoding
2020-04-16 21:29:22 +02:00
Github Actions 7f35fa22d5 [CI Skip] 1.11.0-beta.26
skip-checks: true
2020-04-16 17:14:23 +00:00
Jeremías Díaz da1daf5bd9 fix: ensure consistent Observable version (#2187) 2020-04-16 19:03:00 +02:00
Github Actions 5afc87ce47 [CI Skip] 1.11.0-beta.25
skip-checks: true
2020-04-16 16:21:36 +00:00
Jaco Greeff a2269cd999 Explain where args come from and their types (#2186)
* Explain where args come from and their types

* Update api.query.other.md
2020-04-16 18:11:12 +02:00
Github Actions 201308c259 [CI Skip] 1.11.0-beta.24
skip-checks: true
2020-04-16 14:32:15 +00:00
Jaco Greeff 00490116dd Add system_{localPeerId, localListenAddresses} RPCs (#2185)
* Add system_{localPeerId, localListenAddresses} RPCs

* CHANGELOG
2020-04-16 16:21:40 +02:00
Github Actions 1968c878f5 [CI Skip] 1.11.0-beta.23
skip-checks: true
2020-04-16 13:52:16 +00:00
Jaco Greeff 52ccb9fbbf Linkage fixes (#2184)
* Fix linkage decoding

* Actually fix linkage

* CHANGELOG
2020-04-16 15:41:42 +02:00
Github Actions 03e21ea64b [CI Skip] 1.11.0-beta.22
skip-checks: true
2020-04-16 13:39:19 +00:00
Jaco Greeff 8c949bb3df StorageKey toHuman returns decoded key (#2183) 2020-04-16 15:28:15 +02:00
Github Actions e484e7cf35 [CI Skip] 1.11.0-beta.21
skip-checks: true
2020-04-16 11:32:18 +00:00
Jaco Greeff 7aac4c7936 Add missing cookbook .keys 2020-04-16 13:21:04 +02:00
Github Actions 933c8d48e2 [CI Skip] 1.11.0-beta.20
skip-checks: true
2020-04-16 11:18:25 +00:00
Jaco Greeff d3d3bb9b5a Adjust Weight to u64 (#2181)
* Adjust Weight to u64

* Adjust copy (really should be reading folders...)

* build:interfaces

* EventRecord test expectation update
2020-04-16 13:08:46 +02:00
Github Actions f4d976c337 [CI Skip] 1.11.0-beta.19
skip-checks: true
2020-04-16 10:17:47 +00:00
Jaco Greeff 07c4037fcf On subscriptions, ensure rx.runtimeVersion is set (#2180) 2020-04-16 12:05:35 +02:00
Github Actions 52d73d8698 [CI Skip] 1.11.0-beta.18
skip-checks: true
2020-04-16 09:02:05 +00:00
Jeremías Díaz ccfab75f41 fix: use camelCase for storage module names (#2176) 2020-04-16 10:51:19 +02:00
Github Actions b8204b138d [CI Skip] 1.11.0-beta.17
skip-checks: true
2020-04-16 08:46:32 +00:00
Jaco Greeff a97cb6e25d Return all identity hashes (not just as subset) (#2179) 2020-04-16 10:36:37 +02:00
Github Actions 11534a1153 [CI Skip] 1.11.0-beta.16
skip-checks: true
2020-04-16 07:21:00 +00:00
Jaco Greeff dd1fab5366 Adjust set bitfileds to LE (#2178) 2020-04-16 09:09:17 +02:00
Github Actions dbb3a5ccc2 [CI Skip] 1.11.0-beta.15
skip-checks: true
2020-04-15 16:26:29 +00:00
Jaco Greeff fb08215e0d Add Fixed128 type (#2175) 2020-04-15 18:15:11 +02:00
Github Actions d7d7ab2f89 [CI Skip] 1.11.0-beta.14
skip-checks: true
2020-04-15 08:54:43 +00:00
Jaco Greeff 25393cd982 Add note on field ordering (#2173)
* Add note on field ordering

* Field ordering additional links
2020-04-15 10:43:15 +02:00
Github Actions d6a6089e2d [CI Skip] 1.11.0-beta.13
skip-checks: true
2020-04-15 06:55:53 +00:00
Jaco Greeff a3eaca0270 Small doc cleanups (#2172) 2020-04-15 08:44:15 +02:00
Github Actions f9d1b4d653 [CI Skip] 1.11.0-beta.12
skip-checks: true
2020-04-14 20:22:21 +00:00
Jaco Greeff f81712343a Transaction batching (#2171) 2020-04-14 22:10:25 +02:00
Github Actions 33e414be12 [CI Skip] 1.11.0-beta.11
skip-checks: true
2020-04-14 16:27:55 +00:00
Jaco Greeff 9387103558 cookbook link 2020-04-14 18:15:28 +02:00
Github Actions 3b7c1afa95 [CI Skip] 1.11.0-beta.10
skip-checks: true
2020-04-14 15:28:01 +00:00
Jaco Greeff 7e1fa8954b Extend storage cookbook (#2169)
* Extend storage cookbook

* Update storage.md

* Update storage.md
2020-04-14 17:16:46 +02:00
Github Actions 53c62f1542 [CI Skip] 1.11.0-beta.9
skip-checks: true
2020-04-14 14:56:23 +00:00
Jaco Greeff 5ed94a50e1 Update .123trigger 2020-04-14 16:45:30 +02:00
Github Actions b1c047149b [CI Skip] 1.11.0-beta.8
skip-checks: true
2020-04-14 14:35:37 +00:00
Jaco Greeff 7a0efaf58c Kusama 1057 known types (#2168) 2020-04-14 16:24:19 +02:00
Github Actions 5acce98346 [CI Skip] 1.11.0-beta.7
skip-checks: true
2020-04-14 11:52:00 +00:00
Jaco Greeff 165179ebf2 Remove flags on derive.accounts.info (#2167)
* Remove flags from derive.account.info

* adjust types
2020-04-14 13:40:12 +02:00
Github Actions def60dce9e [CI Skip] 1.11.0-beta.6
skip-checks: true
2020-04-14 10:49:12 +00:00
Jaco Greeff c8f91fcf7a Parameterize DoNotConstruct (#2165)
* Parameterize DoNotConstruct

* Update DoNotConstruct list

* typo fix
2020-04-14 12:37:30 +02:00
Github Actions 70a160cca0 [CI Skip] 1.11.0-beta.5
skip-checks: true
2020-04-14 10:31:23 +00:00
Jaco Greeff 9691fd5ba7 don't subscribe to runtime updates with no subs (#2166) 2020-04-14 12:20:07 +02:00
Jaco Greeff 475cb4fa69 Move Digest to interfaces (#2164)
* Move Digest to interfaces

* Unconstructable typos
2020-04-14 12:09:36 +02:00
Github Actions 5c54b3cc92 [CI Skip] 1.11.0-beta.4
skip-checks: true
2020-04-14 10:05:31 +00:00
Jaco Greeff 55d8c58d95 Add transactionVerions to RuntimeVersion struct (#2163) 2020-04-14 11:54:42 +02:00
Github Actions edf8adaa88 [CI Skip] 1.11.0-beta.3
skip-checks: true
2020-04-14 08:49:43 +00:00
Jaco Greeff 1f8f6e54bd Add unsigned sending to cookbook (#2162)
* Add unsigned sending to cookbook

* Block author extraction example
2020-04-14 10:36:15 +02:00
Github Actions f6ca7b9a9d [CI Skip] 1.11.0-beta.2
skip-checks: true
2020-04-14 07:52:33 +00:00
Jaco Greeff 7732339fc0 Line lengths 2020-04-14 09:41:04 +02:00
Jaco Greeff 5a8a8c7ecb Fix cookbook links 2020-04-14 09:34:39 +02:00
Github Actions 05df087e73 [CI Skip] 1.11.0-beta.1
skip-checks: true
2020-04-14 06:58:37 +00:00
Jaco Greeff 5b71abfe80 Make a start at a cookbook... still loads to go (#2160) 2020-04-14 08:48:14 +02:00
Github Actions 1d6c33060a [CI Skip] 1.11.0-beta.0
skip-checks: true
2020-04-13 10:45:21 +00:00
Jaco Greeff eae573e6a2 Simplify entries() decoding (#2159) 2020-04-13 12:33:24 +02:00
157 changed files with 4293 additions and 9301 deletions
+4 -2
View File
@@ -1,3 +1,5 @@
21
1.4.2
24
1.4.2
1.6.2
1.11.2
1.12.2
+50
View File
@@ -1,3 +1,53 @@
# 1.13.1 May 6, 2020
- Add support for ECDSA keypairs in extrinsic signers (Thanks to https://github.com/akru)
- Rework type generation to use templating for better maintenance (Thanks to https://github.com/xlc)
- Adjust extrinsic `sign/signAsync` signature to optional options (Thanks to https://github.com/KiChjang)
- Support round-robin endpoints in the `WsProvider` with array of urls (Thanks to https://github.com/hoani)
- Remove static test-only metadata for Polkadot dev chains (not updated regularly, Substrate dev to remain)
- Revert error swallow for wrong preimage data (temp. override for Kusama upgrade with no migration)
- Fix `.encodedLength` calculation on `[Type; N]` types
- Update types & metadata as per latest Substrate master
- Adjust Centrifuge starting version
# 1.12.2 Apr 30, 2020
- Update @polkadot/util to stable 2.9.1 (sadly missed in the previous version, stable should match to stable)
# 1.12.1 Apr 29, 2020
- Fix `CompactAssignments` types (Thanks to https://github.com/arjanz)
- Provider ayo-connect now allows for interval config (Thanks to https://github.com/jnaviask)
- Cleanup generation for c-like enums (Thanks to https://github.com/monitz87)
- Allow subscription to all storage keys, alignment with Substrate (Thanks to https://github.com/xlc)
- Cater for vote delegations in democracy derives
- Cleanup account derive flags where to allow for optional council modules
- Allow generic types in ApiPromise.combineLatest
- Update to latest substrate metadata
# 1.11.2 Apr 22, 2020
- Small patch to add missing Polkadot master types (will be in next Kusama update)
# 1.11.1 Apr 21, 2020
- **Important** Substrate master has an updated `Weight` (to `u64`), on older chains apply `Weight: 'u32'` (This does affect event decoding if wrongly set)
- Allow user type augmentation to work with different versions of rxjs (Thanks to https://github.com/monitz87)
- Align augmented generation with camelCase (Thanks to https://github.com/monitz87)
- Fix bitfield endian encoding (Thanks to investigation by https://github.com/xlc)
- Add account flag derives via `accounts.flags(accountId)` (Thanks to https://github.com/kwingram25)
- Fix entries decoding for `Option<Number>` (& simplify, decoding correctly on rpc layer)
- Add `system.{localPeerId, localListenAddresses}` & `state.getReadProof` RPCs
- Ensure proper propagation of `api.runtimeVersion` (used for signing) after upgrade
- Field ordering fix for deprecated `Linkage` (used in linked maps)
- `derive.account.info` now returns all field enum types decoded (not only raw)
- Add banner with FAQ entries for node-template to aid with common issues
- `Digest` has been moved to definitions, removal of `GenericDigest` type
- Support `Fixed128` type
- Add `transactionVersion` to `RuntimeVersion` struct
- Enhance API support for non-subscription providers (skip subscription to runtimeVersion)
- Adjust types for Kusama 1057 (notably the new `StakingLedger`)
# 1.10.1 Apr 13, 2020
- **Important** Substrate master has updated staking, on older chains apply `StakingLedger: 'StakingLedgerTo240'`
+1
View File
@@ -19,4 +19,5 @@ copy_folder "metadata"
copy_folder "rpc-core"
copy_folder "rpc-provider"
copy_folder "types"
copy_folder "types-known"
copy_folder "typegen"
+19 -2
View File
@@ -20,7 +20,8 @@ module.exports = {
},
{ text: 'GitHub', link: 'https://github.com/polkadot-js/api' }
],
search: false,
search: true,
searchMaxSuggestions: 10,
sidebar: [
{
title: 'Getting started',
@@ -50,6 +51,17 @@ module.exports = {
['start/FAQ.md', 'FAQ']
]
},
{
title: 'Cookbook',
path: '/cookbook/',
collapsable: false,
sidebarDepth: 0,
children: [
['cookbook/blocks.md', 'Blocks'],
['cookbook/storage.md', 'Storage'],
['cookbook/tx.md', 'Transactions']
]
},
{
title: 'Examples (Promise API)',
path: '/examples/promise/',
@@ -86,5 +98,10 @@ module.exports = {
['/types/', '@polkadot/types'],
'/CONTRIBUTING.md'
]
}
},
plugins: [
['@vuepress/search', {
searchMaxSuggestions: 10
}]
]
};
+3
View File
@@ -1,5 +1,8 @@
$accentColor = #fd8824
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
$arrowBgColor = #ccc
.home .hero .description,
.home .feature h2,
+2 -9
View File
@@ -13,7 +13,7 @@ features:
- title: Types
details: Various type interfaces to make using returned values from API calls transparent in your code.
footer: Apache-2 Licensed | Copyright © 2017-2019 polkadot-js authors and contributors
footer: Apache-2 Licensed | Copyright © 2017-2020 polkadot-js authors and contributors
---
## Welcome
@@ -21,16 +21,9 @@ footer: Apache-2 Licensed | Copyright © 2017-2019 polkadot-js authors and contr
The API provides application developers the ability to query a node and interact with the Polkadot or Substrate chains using Javascript. Here you will find documentation and examples to get you started.
::: tip Getting started & Examples
[Jump right in](/start/) and get an overview on using the API in your projects, from installation all the way through to making it do magic. Already understand how things work and just want the examples? [The ApiPromise examples](/examples/promise/) provide some basic recipies.
[Jump right in](/start/) and get an overview on using the API in your projects, from installation all the way through to making it do magic. Have things working and want tips? The [cookbook](/cookbook/) provides some tips and tricks. Getting started and want some full examples? [The ApiPromise examples](/examples/promise/) provide some basic examples.
:::
## Available packages
This repository split up into a number of internal packages, namely -
- [api](api/README.md) Promise and RxJS-based APIs
- [types](types/README.md) Type encoding and decoding wrappers
## The Polkadot Project
You can read more about the Polkadot Network at [https://polkadot.network/](https://polkadot.network/) and more about the polkadot-js projects at [https://polkadot.js.org](https://polkadot.js.org)
+19
View File
@@ -0,0 +1,19 @@
# Cookbook
The cookbook hosts small code snippets in a question-answer format. It does not walk you through the whole setup, like the [basic examples](../examples/), but rather aims to answer some questions around specific uses. It also does not replace the [getting started FAQ](../start/FAQ.md), rather this is focussed explicitly on code samples, instead of general trouble-shooting for common mishaps.
These questions are added as they do come up and the hope is that the snippets here is will be useful to others, instead of just the original person who asked on a specific use-case. As of today, it is only making a start and not fully comprehensive yet - check back early, check back often.
## Sections
The following cookbook sections are available -
- [Blocks](blocks.md) - Snippets around working with blocks and headers
- [Storage](storage.md) - Snippets for working with storage
- [Transactions](tx.md) - Snippets for working with transactions
... more to come.
## Contribute
And as always, if you have an addition to make, or a question to ask any [any PRs](https://github.com/polkadot-js/api/tree/master/docs) or [issues](https://github.com/polkadot-js/api/issues) are appreciated. The initial content was generate from exactly such questions, either in Riot chat or as submitted as issues.
+44
View File
@@ -0,0 +1,44 @@
# Blocks
The building blocks for each blockchain. As such there are a number of examples for working with blocks and headers, that could be useful.
## How do I retrieve the header/extrinsic hash from blocks?
A block hash refers to the hash over the header, the extrinsic hash refers to the hash of the encoded extrinsic. Since all objects returned by the API implements the `.hash => Hash` getter, we can simply use this to view the actual hash.
```js
// returns Hash
const blockHash = await this.api.rpc.chain.getBlockHash(blockNumber);
// returns SignedBlock
const signedBlock = await this.api.rpc.chain.getBlock(blockHash);
// the hash for the block, always via header (Hash -> toHex()) - will be
// the same as blockHash above (also available on any header retrieved,
// subscription or once-off)
console.log(signedBlock.header.hash.toHex());
// the hash for each extrinsic in the block
signedBlock.block.extrinsics.forEach((ex, index) => {
console.log(index, ex.hash.toHex());
});
```
## How do I extract the block author?
Th block author is encoded inside the consensus logs for the block. To extract, you need to decode the log (which the API does do) and then map the index of the validator to the list of session validators. This extraction is however available on the api derive for new head subscriptions, which returns an extended header with the author populated (assuming that the digest logs are known).
```js
// subscribe to all new headers (with extended info)
api.derive.chain.subscribeNewHeads((header) => {
console.log(`#${header.number}: ${header.author}`);
});
```
For a single header only, the derives also contain a `getHeader`, which once again returns a header extended with the author -
```js
// retrieve the last header (hash optional)
const header = await api.derive.chain.getHeader();
console.log(`#${header.number}: ${header.author}`);
```
+55
View File
@@ -0,0 +1,55 @@
# Storage
Here you will find snippets for working with storage.
## How do I check for storage existence?
In the metadata, for each storage item a fallback is provided. This means that when an entry does not exist, the fallback (which is the default value for the type) will be provided. This means, that querying for a non-existent key (unless an option), will yield a value -
```js
// retrieve Option<StakingLedger>
const ledger = await api.query.staking.ledger('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
// retrieve ValidatorPrefs (will yield the default value)
const prefs = await api.query.staking.validators('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
console.log(ledger.isNone, ledger.isSome); // true, false
console.log(JSON.stringify(prefs.toHuman())); // {"commission":"0"}
```
In the second case, the non-existent prefs returns the default/fallback value for the storage item. So in this case we don't know if the value is set to 0 or unset. Existence can be checked by using the storage size, which would be zero if nothing is stored.
```js
// exists
const sizeY = await api.query.staking.validators.size('DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4');
// non existent
const sizeN = await api.query.staking.validators.size('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
console.log(sizeY.isZero(), sizeY.toNumber()); // false 4
console.log(sizeN.isZero(), sizeY.toNumber()); // true 0
```
## How do I use .entries()/.keys() on double maps?
As [explained elsewhere](../start/api.query.other.md#map-keys-entries) each map-type storage entry exposes the entries/keys helpers to retrieve the whole list. In the case of double maps, with the addition of a single argument, you can retrieve either all entries or a subset based on the first map key.
In both these cases, entries/keys operate the same way, `.entries()` retrieving `(StorageKey, Codec)[]` and `.keys()` retrieving `StorageKey[]`
```js
// Retrieves the entries for all slashes, in all eras (no arg)
const allEntries = await api.query.staking.nominatorSlashInEra.entries();
// nominatorSlashInEra(EraIndex, AccountId) for the types of the key args
allEntries.forEach(([{ args: [era, nominatorId] }, value]) => {
console.log(`${era}: ${nominatorId} slashed ${value.toHuman()}`);
});
```
While we can retrieve only the keys for a specific era, using a argument for the first part of the doublemap (as defined here, an `EraIndex`) -
```js
// Retrieves the keys for the slashed validators in era 652
const slashedKeys = await api.query.staking.nominatorSlashInEra.keys(652);
// key args still contains [EraIndex, AccountId] decoded
console.log(`slashed: ${slashedKeys.map(({ args: [era, nominatorId] }) => nominatorId)`);
```
+112
View File
@@ -0,0 +1,112 @@
# Transactions
A blockchain is no fun if you are not submitting transactions. Or at least if somebody is not submitting any. Here you will find some snippets for dealing with some common issues.
## How do I estimate the transaction fees?
In addition to the `signAndSend` helper on transactions, `.paymentInfo` (with the exact same parameters) are also exposed. Using the same sender, it applies a dummy signature to the transaction and then gets the fee estimation via RPC.
```js
// estimate the fees as RuntimeDispatchInfo, using the signer (either
// address or locked/unlocked keypair) (When overrides are applied, e.g
// nonce, the format would be `paymentInfo(sender, { nonce })`)
const info = await api.tx.balances
.transfer(recipient, 123)
.paymentInfo(sender);
// log relevant info, partialFee is Balance, estimated for current
console.log(`
class=${class.toString()},
weight=${weight.toString()},
partialFee=${partialFee.toHuman()}
`);
```
## How do I get the decoded enum for an ExtrinsicFailed event?
Assuming you are sending a tx via `.signAndSend`, the callback yields information around the tx pool status as well as any events when `isInBlock` or `isFinalized`. If an extrinsic fails via `system.ExtrinsicFailed` event, you can retrieve the error, if defined as an enum on a module.
```js
api.tx.balances
.transfer(recipient, 123)
.signAndSend(sender, ({ status, events }) => {
if (status.isInBlock || status.isFinalized) {
events
// find/filter for failed events
.filter(({ section, method }) =>
section === 'system' &&
method === 'ExtrinsicFailed'
)
// we know that data for system.ExtrinsicFailed is
// (DispatchError, DispatchInfo)
.forEach(({ data: [error, info] }) => {
if (error.isModule) {
// for module errors, we have the section indexed, lookup
const decoded = api.registry.findMetaError(error.asModule);
const { documentation, method, section } = decoded;
console.log(`${section}.${method}: ${documentation.join(' ')}`);
} else {
// Other, CannotLookup, BadOrigin, no extra info
console.log(error.toString());
}
});
}
});
```
## How do I send an unsigned extrinsic?
For most runtime modules, transactions need to be signed and validation for this happens node-side. There are however modules that accepts unsigned extrinsics, an example would be the Polkadot/Kusama token claims (which is here used as an example).
```js
// construct the transaction, exactly as per normal
const utx = api.tx.claims.claim(beneficiary, ethSignature);
// send it without calling sign, pass callback with status/events
tx.send(({ status }) => {
if (status.isInBlock) {
console.log(`included in ${status.asInBlock}`);
}
});
```
The signing is indicated by the first byte in the transaction, so in this case we have called `.send` on it (no `.sign` or `.signAndSend`), so it will be sent using the unsigned state, without signature attached.
## How can I batch transactions?
Polkadot/Substrate provides a `utility.batch` method that can be used to send a number of transactions at once. These are then executed from a single sender (single nonce specified) in sequence. This is very useful in a number of cases, for instance if you wish to create a payout for a validator for multiple eras, you can use this method. Likewise, you can send a number of transfers at once. Or even batch different types of transactions.
```js
// construct a list of transactions we want to batch
const txs = [
api.tx.balances.transfer(addrBob, 12345),
api.tx.balances.transfer(addrEve, 12345),
api.tx.staking.unbond(12345)
];
// construct the batch and send the transactions
api.tx.utility
.batch(txs)
.signAndSend(sender, ({ status }) => {
if (status.isInBlock) {
console.log(`included in ${status.asInBlock}`);
}
});
```
## How do I take the pending tx pool into account in my nonce?
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signandSend` operation, we can override the nonce, either by manually incrementing it o querying it via `nextNonce`.
```js
for (let i = 0; i < 10; i++) {
// retrieve the nextNonce, taking txs in the pool into account
const nonce = await api.rpc.account.nextNonce(sender);
// send, just retrieving the hash, not waiting on status
const txhash = await api.tx.balances
.transfer(recipient, 123)
.signAndSend(sender, { nonce });
}
```
+6
View File
@@ -57,3 +57,9 @@ The API always injects the default type definitions as specified by the Substrat
The Substrate node-template has added customizations for some types in the default template, specifically around the `Address` and `Lookup` types, removing any lookups based on indices. This means that the transaction payload saves 2 bytes for a transfer and is an approach followed by other chains as well, notably Polkadot & Kusama.
Due to these customizations and differences that bleed through to the transaction formats, out-of-the-box chains based on the node-template will have issues when sending transactions. To fix this, you would need to add [the customized Address types into your API](types.extend.md#impact-on-extrinsics) instances (or UIs), allowing the API to have the information required to adjust the encoding.
## Using a non-current-master node, I have issues parsing events
Recently Substrate master updated the `Weight` type from `u32` -> `u64`. This type is used in the `DispatchInfo` struct in the `system.ExtrinsicSuccess` events, to return the applied call weights as well as the resulting fees. Since the API master branch tracks Substrate master, this means the change has been applied by default, with the default set to `u64`.
If you are on a chain that has not been upgraded yet, you need to add `Weight: 'u32'` to your types to allow for successful parsing of all events. Without this override, parsing will fail. As soon as one event in the `Vec<EventRecord>` structure from `system.events` fails to parse, all subsequent events are affected and the decoding will return an error.
+1 -1
View File
@@ -23,7 +23,7 @@ A couple of items to note in the example above: we don't call `account` directly
...
// Retrieve a snapshot of the validators
const validators = await api.query.session.validators();
const validatorKeys = await api.query.session.validators.keys();
// Subscribe to the balances for these accounts
const unsub = await api.query.balances.account.multi(validators, (balances) => {
+10 -5
View File
@@ -71,18 +71,23 @@ exposures.forEach(([key, exposure]) => {
});
```
Here we are querying a double-map, so we supply 1 argument. No arguments on double-maps will be very costly, retrieving all the eras and associated entries. Additionally when `twox64_concat` & `blake2_concat` is used, the key `.args` will contain decoded values of the params, in this case it will contain the actual `AccountId` of the staker. (Since that was not supplied)
To understand the usage of the `key.args`, you need to understand that map/doublemap keys are stored alongside their lookups. This means that the raw key has hashed parts as well as the raw data. The API will decode the keys and provide the raw key arguments in args. This would mean -
In the same way as above we can simply do `.keys(activeEra.index): StorageKey[]` to retrieve all the keys here, including the individual keys args (available on maps with decodable hashing functions) -
- if we are querying `api.query.staking.validators(validatorId: AccountId)` via `entries`, the `key.args` would be `[AccountId]`
- if we are querying `api.query.staking.erasStakers(era: EraIndex, validatorId: AccountId)` via `entries`, the `key.args` would be `[EraIndex, AccountId]`
the same applies to `.keys()` - here the list of keys also have the decoded args, as specified. You can think of `.args` as a tuple with the same types as the types required to retrieve a single entry in the map.
In the first example we are querying a double-map, so we supply 1 argument. No arguments on double-maps will be very costly, retrieving all the eras and associated entries. In the same way as above we can simply do `.keys(activeEra.index): StorageKey[]` to retrieve all the keys here, including the individual keys args (available on maps with decodable hashing functions) -
```js
// retrieve all the nominator keys
const keys = await api.query.staking.nominators.keys();
// extract the first key argument (AccountId) as string
const nominatorIds = keys.map((key) => key.args[0].toString());
// extract the first key argument [AccountId] as string
const nominatorIds = keys.map(({ args: [nominatorId] }) => nominatorId);
console.log('all nominators:', nminatorIds.join(', '));
console.log('all nominators:', nominatorIds.join(', '));
```
## State entries
+17 -5
View File
@@ -1,6 +1,6 @@
# Custom RPC
In previous sections we looked at the injection of types, as in use and defined in modules from the node. Another area that can be customized is RC definitions, and like with the types, the API provides the capability to add user-defined RPCs (in addition to the Polkadot/Substrate base) to allow use of these RPCs via the API.
In previous sections we looked at the injection of types, as in use and defined in modules from the node. Another area that can be customized is RPC definitions, and like with the types, the API provides the capability to add user-defined RPCs (in addition to the Polkadot/Substrate base) to allow use of these RPCs via the API.
## Custom definitions
@@ -17,16 +17,28 @@ const api = await ApiPromise.create({
{
name: 'index',
type: 'u64'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Balance'
}
}
}
},
anotherMethod: { ... },
...
},
anotherModule: { ... },
...
},
...
});
```
In the above example we have defined a new method, which is now available on the RPCs as `api.rpc.firstModule.testMethod(u64) => Promise<Balance>`. Do be aware that while defined, the method will only appear if it is in the list as returned by `api.rpc.rpc.methods()`, which is the list of known RPCs the node exposes. When making changes to the node, always ensure that it does expose the RPC method correctly, otherwise it will not be decorated.
In the above example we have defined a new method, which is now available on the RPCs as `api.rpc.firstModule.testMethod(index: u64, at?: Hash) => Promise<Balance>`. In the case of optional params, we have added the `isOptional: true` flag alongside the `name` & `type` in the param definition.
Be aware that while defined, the method will only appear on the API if it is in the list as returned by `api.rpc.rpc.methods()`, which is the list of known RPCs the node exposes. When making changes to the node, always ensure that it does expose the RPC method correctly, otherwise it will not be decorated.
## Definition breakdown
+9
View File
@@ -26,6 +26,15 @@ const api = await ApiPromise.create({
The above introduces the `types` registry, effectively allowing overrides and the definition of new types. The override above would mean that immediately the API will treat all occurrences of `Balance` not as the default, but rather as the defined size.
## Field ordering
When defining any custom structures or types, it is critical that the following rules are applied -
- Map exactly to what is defined in the Rust code, i.e. defining a `SaleType` cannot be `u16` on the one end and `u32` on the other end. If mismatches occur, the serialization will fail.
- Ensure that the field order is maintained in all definitions. The SCALE serialization is binary and contains no field names in the serialization, only the encoded values. Any decoding is therefore done based on the size of the type and the order thereof in the definitions.
These rules apply everywhere. Always ensure that the types match exactly between the environments and that the ordering is maintained, be it for structs, tuples or enums.
## User-defined structs
Registration also applies to any type that can be found on a specific chain, i.e. we can add any types that is available on a specific node -
+1 -1
View File
@@ -4,7 +4,7 @@ In the previous section we looked at the TypeScript definitions that are availab
## Definitions
A large part of the type definitions are defined not as classes, but rather as structures from which type definitions are extracted and that can be used as-is to let the API know how to decode a type. By now you should be familiar with [type extensions](types.extend.md), but effectively the [types library does exactly the same](https://github.com/polkadot-js/api/tree/master/packages/types/src/interfaces).
A large part of the type definitions are defined not as classes, but rather as structures from which type definitions are extracted and that can be used as-is to let the API know how to decode a type. By now you should be familiar with [type extensions](types.extend.md) and the [rules around fields](types.extend.md#field-ordering), but effectively the [types library does exactly the same](https://github.com/polkadot-js/api/tree/master/packages/types/src/interfaces).
To create TypeScript-aware definitions and keep your files in a single place, you can follow the same approach. Assuming you have a package named `@MeInc/stuff` where you have the definitions in an `stuff/interfaces` folder. Each sub-folder would indicate a runtime module, e.g.
+1 -1
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "1.10.1"
"version": "1.13.1"
}
+5 -4
View File
@@ -24,13 +24,14 @@
"test:watch": "polkadot-dev-run-test --watch"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/core": "^7.9.6",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@polkadot/dev": "^0.52.9",
"@polkadot/ts": "^0.3.18",
"@babel/runtime": "^7.9.6",
"@polkadot/dev": "^0.52.15",
"@polkadot/ts": "^0.3.19",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^25.2.1",
"@vuepress/plugin-search": "^1.4.1",
"copyfiles": "^2.2.0"
}
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "1.10.1",
"version": "1.13.1",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
"keywords": [
@@ -26,11 +26,11 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/api": "1.10.1",
"@polkadot/rpc-core": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/api": "1.13.1",
"@polkadot/rpc-core": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"bn.js": "^5.1.1",
"rxjs": "^6.5.5"
}
+9 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "1.10.1",
"version": "1.13.1",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
"keywords": [
@@ -27,18 +27,18 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/api": "1.10.1",
"@polkadot/rpc-core": "1.10.1",
"@polkadot/rpc-provider": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@polkadot/util-crypto": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/api": "1.13.1",
"@polkadot/rpc-core": "1.13.1",
"@polkadot/rpc-provider": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"@polkadot/util-crypto": "^2.9.1",
"bn.js": "^5.1.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.1"
}
}
+69
View File
@@ -0,0 +1,69 @@
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, Address, Balance } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DeriveAccountFlags } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Vec } from '@polkadot/types';
import { memo } from '../util';
type FlagsIntermediate = [
Vec<ITuple<[AccountId, Balance]>> | undefined,
AccountId[],
AccountId[],
AccountId[],
AccountId | undefined
];
function isIncludedFn (accountId: AccountId | Address | string): (_: AccountId | Address |string) => boolean {
return function (id: AccountId | Address | string): boolean {
return id.toString() === accountId.toString();
};
}
/**
* @name info
* @description Returns account membership flags
*/
export function flags (api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
return memo((address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
const councilSection = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
return (
combineLatest([
address && api.query[councilSection]?.members
? api.query[councilSection].members()
: of(undefined),
address && api.query.council?.members
? api.query.council.members()
: of([]),
address && api.query.technicalCommittee?.members
? api.query.technicalCommittee.members()
: of([]),
address && api.query.society?.members
? api.query.society.members()
: of([]),
address && api.query.sudo?.key
? api.query.sudo.key()
: of(undefined)
]) as Observable<FlagsIntermediate>
).pipe(
map(([electionsMembers, councilMembers, technicalCommitteeMembers, societyMembers, sudoKey]): DeriveAccountFlags => {
const isIncluded = address ? isIncludedFn(address) : (): boolean => false;
return {
isCouncil: (electionsMembers?.map(([id]: ITuple<[AccountId, Balance]>) => id) || councilMembers || []).some(isIncluded),
isSociety: (societyMembers || []).some(isIncluded),
isSudo: sudoKey?.toString() === address?.toString(),
isTechCommittee: (technicalCommitteeMembers || []).some(isIncluded)
};
})
);
});
}
@@ -3,6 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import { AccountIdAndIndex } from '../types';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
@@ -12,8 +13,6 @@ import { decodeAddress } from '@polkadot/util-crypto';
import { memo } from '../util';
export type AccountIdAndIndex = [AccountId?, AccountIndex?];
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | string | null | undefined): Observable<AccountIdAndIndex> {
try {
// yes, this can fail, don't care too much, catch will catch it
@@ -2,6 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export * from './flags';
export * from './idAndIndex';
export * from './idToIndex';
export * from './indexToId';
+8 -48
View File
@@ -5,11 +5,11 @@
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DeriveAccountFlags, DeriveAccountInfo, DeriveAccountRegistration } from '../types';
import { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Bytes, Data, Option, u32, Vec } from '@polkadot/types';
import { Bytes, Data, Option, u32 } from '@polkadot/types';
import { u8aToString } from '@polkadot/util';
import { memo } from '../util';
@@ -17,15 +17,9 @@ import { memo } from '../util';
function dataAsString (data: Data): string | undefined {
return data.isRaw
? u8aToString(data.asRaw.toU8a(true))
: data.isSha256
? data.asSha256.toHex()
: undefined;
}
function includedWrapper (accountId?: AccountId): (_: AccountId) => boolean {
return function (id: AccountId): boolean {
return id.eq(accountId);
};
: data.isNone
? undefined
: data.toHex();
}
function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<string | undefined> {
@@ -115,39 +109,6 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab
);
}
function retrieveFlags (api: ApiInterfaceRx, accountId?: AccountId): Observable<DeriveAccountFlags> {
const councilSection = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
return combineLatest([
api.query[councilSection]?.members
? api.query[councilSection].members<Vec<ITuple<[AccountId, Balance]>>>()
: of(undefined),
api.query.council?.members
? api.query.council.members()
: of([]),
api.query.technicalCommittee?.members
? api.query.technicalCommittee.members()
: of([]),
api.query.society?.members
? api.query.society.members()
: of([]),
api.query.sudo?.key
? api.query.sudo.key()
: of(undefined)
]).pipe(
map(([electionsMembers, councilMembers, technicalCommitteeMembers, societyMembers, sudoKey]): DeriveAccountFlags => {
const checkIncluded = includedWrapper(accountId);
return {
isCouncil: (electionsMembers?.map(([id]) => id) || councilMembers || []).some(checkIncluded),
isSociety: societyMembers.some(checkIncluded),
isSudo: !!sudoKey && sudoKey.eq(accountId),
isTechCommittee: technicalCommitteeMembers.some(checkIncluded)
};
})
);
}
/**
* @name info
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
@@ -155,16 +116,15 @@ function retrieveFlags (api: ApiInterfaceRx, accountId?: AccountId): Observable<
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
api.derive.accounts.idAndIndex(address).pipe(
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountFlags, DeriveAccountRegistration, string?]> =>
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
combineLatest([
of({ accountId, accountIndex }),
retrieveFlags(api, accountId),
retrieveIdentity(api, accountId),
retrieveNick(api, accountId)
])
),
map(([{ accountId, accountIndex }, flags, identity, nickname]): DeriveAccountInfo => ({
accountId, accountIndex, ...flags, identity, nickname
map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({
accountId, accountIndex, identity, nickname
}))
));
}
+38
View File
@@ -0,0 +1,38 @@
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, RegistrationJudgement } from '@polkadot/types/interfaces';
export type AccountIdAndIndex = [AccountId?, AccountIndex?];
export type AccountIndexes = Record<string, AccountIndex>;
export interface DeriveAccountRegistration {
display?: string;
displayParent?: string;
email?: string;
image?: string;
legal?: string;
other?: Record<string, string>;
parent?: AccountId;
pgp?: string;
riot?: string;
twitter?: string;
web?: string;
judgements: RegistrationJudgement[];
}
export interface DeriveAccountFlags {
isCouncil: boolean;
isSociety: boolean;
isSudo: boolean;
isTechCommittee: boolean;
}
export interface DeriveAccountInfo {
accountId?: AccountId;
accountIndex?: AccountIndex;
identity: DeriveAccountRegistration;
nickname?: string;
}
@@ -17,8 +17,8 @@ import { parseImage } from './util';
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
export function preimage (api: ApiInterfaceRx): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
return memo((hashes: Hash[]): Observable<DeriveProposalImage | undefined> =>
api.query.democracy.preimages<PreImage>(hashes).pipe(
return memo((hash: Hash): Observable<DeriveProposalImage | undefined> =>
api.query.democracy.preimages<PreImage>(hash).pipe(
map((imageOpt) => parseImage(api, imageOpt))
)
);
@@ -20,9 +20,7 @@ export function preimages (api: ApiInterfaceRx): (hashes: Hash[]) => Observable<
return memo((hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
map((images): (DeriveProposalImage | undefined)[] =>
images.map((imageOpt) =>
parseImage(api, imageOpt)
)
images.map((imageOpt) => parseImage(api, imageOpt))
)
)
);
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, ReferendumInfo, ReferendumInfoTo239, Vote, Voting, VotingDirectVote } from '@polkadot/types/interfaces';
import { AccountId, ReferendumInfo, ReferendumInfoTo239, Vote, Voting, VotingDirectVote, VotingDelegating } from '@polkadot/types/interfaces';
import { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
import BN from 'bn.js';
@@ -33,6 +33,7 @@ function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveRef
votersFor.map((accountId, index): DeriveReferendumVote => ({
accountId,
balance: balances[index].votingBalance || api.registry.createType('Balance'),
isDelegating: false,
vote: votes[index] || api.registry.createType('Vote')
}))
)
@@ -41,10 +42,9 @@ function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveRef
function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
return api.query.democracy.votingOf.entries<Voting>().pipe(
map((allVoting): DeriveReferendumVote[] =>
allVoting
.map(([key, voting]): [AccountId, Voting] => [key.args[0] as AccountId, voting])
// FIXME We are ignoring delegated votes
map((allVoting): DeriveReferendumVote[] => {
const mapped = allVoting.map(([key, voting]): [AccountId, Voting] => [key.args[0] as AccountId, voting]);
const votes = mapped
.filter(([, voting]) => voting.isDirect)
.map(([accountId, voting]): [AccountId, VotingDirectVote[]] => [
accountId,
@@ -57,14 +57,37 @@ function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveRef
if (vote.isStandard) {
result.push({
accountId,
isDelegating: false,
...vote.asStandard
});
}
return result;
}, result), []
)
)
);
const delegations = mapped
.filter(([, voting]) => voting.isDelegating)
.map(([accountId, voting]): [AccountId, VotingDelegating] => [accountId, voting.asDelegating]);
// add delegations
delegations.forEach(([accountId, { balance, conviction, target }]): void => {
// Are we delegating to a delegator
const toDelegator = delegations.find(([accountId]) => accountId.eq(target));
const to = votes.find(({ accountId }) => accountId.eq(toDelegator ? toDelegator[0] : target));
// this delegation has a target
if (to) {
votes.push({
accountId,
balance,
isDelegating: true,
vote: api.registry.createType('Vote', { aye: to.vote.isAye, conviction })
});
}
});
return votes;
})
);
}
@@ -46,6 +46,7 @@ export interface DeriveReferendum {
export interface DeriveReferendumVote {
accountId: AccountId;
balance: Balance;
isDelegating: boolean;
vote: Vote;
}
+22 -7
View File
@@ -8,7 +8,7 @@ import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlo
import BN from 'bn.js';
import { Observable, combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import { map, switchMap } from 'rxjs/operators';
import { isUndefined } from '@polkadot/util';
@@ -70,16 +70,31 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, query
};
}
export function _account (api: ApiInterfaceRx): (sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
return memo((sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
api.derive.staking.query(accountId).pipe(
map((query) => parseResult(api, sessionInfo, query))
));
}
/**
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
*/
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
return memo((accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
combineLatest([
api.derive.session.info(),
api.derive.staking.query(accountId)
]).pipe(
map(([sessionInfo, query]: [DeriveSessionInfo, DeriveStakingQuery]) =>
parseResult(api, sessionInfo, query))
api.derive.session.info().pipe(
switchMap((sessionInfo) => api.derive.staking._account(sessionInfo, accountId))
));
}
/**
* @description From a list of stashes, fill in all the relevant staking details
*/
export function accounts (api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[]) => Observable<DeriveStakingAccount[]> {
return memo((accountIds: (Uint8Array | string)[]): Observable<DeriveStakingAccount[]> =>
api.derive.session.info().pipe(
switchMap((sessionInfo) =>
combineLatest(accountIds.map((accountId) => api.derive.staking._account(sessionInfo, accountId)))
)
));
}
@@ -107,18 +107,18 @@ function filterRewards (api: ApiInterfaceRx, rewards: DeriveStakerReward[], stak
return combineLatest([
api.query.staking.migrateEra
? api.query.staking.migrateEra<Option<EraIndex>>()
: of({ unwrapOr: () => api.tx.staking.payoutStakers ? MIN_ONE : MAX_ERAS }),
: of({ unwrapOr: () => api.tx.staking.payoutStakers ? ZERO : MAX_ERAS }),
api.tx.staking.payoutStakers
? api.derive.staking.queryMulti(validators)
: of([])
]).pipe(
map(([optMigrate, queryValidators]): DeriveStakerReward[] => {
const migrateEra: BN = optMigrate.unwrapOr(MIN_ONE);
const migrateEra: BN = optMigrate.unwrapOr(ZERO);
return rewards
.filter(({ isEmpty }) => !isEmpty)
.filter((reward): boolean => {
if (reward.era.lte(migrateEra)) {
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);
}
@@ -26,7 +26,7 @@ export default class HeaderExtended extends _Header {
}
private _extractAuthor (sessionValidators: AccountId[] = []): AccountId | undefined {
const [pitem] = this.digest.logsWith('PreRuntime');
const [pitem] = this.digest.logs.filter(({ type }) => type === 'PreRuntime');
// extract from the substrate 2.0 PreRuntime digest
if (pitem) {
@@ -34,7 +34,7 @@ export default class HeaderExtended extends _Header {
return engine.extractAuthor(data, sessionValidators);
} else {
const [citem] = this.digest.logsWith('Consensus');
const [citem] = this.digest.logs.filter(({ type }) => type === 'Consensus');
// extract author from the consensus (substrate 1.0, digest)
if (citem) {
+2 -32
View File
@@ -2,48 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, ProposalIndex, RegistrationJudgement, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces';
import { AccountId, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, ProposalIndex, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import { u32 } from '@polkadot/types';
export * from './accounts/types';
export * from './council/types';
export * from './democracy/types';
export * from './parachains/types';
export * from './session/types';
export * from './staking/types';
export type AccountIndexes = Record<string, AccountIndex>;
export interface DeriveAccountRegistration {
display?: string;
displayParent?: string;
email?: string;
image?: string;
legal?: string;
other?: Record<string, string>;
parent?: AccountId;
pgp?: string;
riot?: string;
twitter?: string;
web?: string;
judgements: RegistrationJudgement[];
}
export interface DeriveAccountFlags {
isCouncil: boolean;
isSociety: boolean;
isSudo: boolean;
isTechCommittee: boolean;
}
export interface DeriveAccountInfo extends DeriveAccountFlags {
accountId?: AccountId;
accountIndex?: AccountIndex;
identity: DeriveAccountRegistration;
nickname?: string;
}
export interface DeriveBalancesAccount {
accountId: AccountId;
accountNonce: Index;
+1
View File
@@ -92,6 +92,7 @@ const api = await ApiPromise.create({
Some of the users of the API (let us know if you are missing from the list), include -
- [Polkadot-JS UI](https://github.com/polkadot-js/apps) A user-interface that allows you to make transactions, query the network or participate in actions on the network such as referendums and staking
- [KodaDot](https://github.com/vue-polkadot/apps) ([twitter](https://twitter.com/KodaDot)) - Vue.js web wallet, governance dashboard and aspiring performance (lightweight) alternative to original apps, mobile-first.
- [Polkabot](https://gitlab.com/Polkabot) Polkabot is a Matrix chatbot that keeps an eye on the Polkadot network. You can see Polkabot in action in https://matrix.to/#/#polkadot-network-status:matrix.org
- [Polkawallet.io](https://polkawallet.io) and [Polkawallet (Github)](https://github.com/polkawallet-io/polkawallet-RN/) A mobile wallet for the Polkadot network to manage funds and make transactions, available on both Androind and iOS
- [PolkaStats.io](https://polkastats.io), [PolkaStats frontend GitHub repository](https://github.com/Colm3na/polkastats-v2) and [PolkaStats backend GitHub repository](https://github.com/Colm3na/polkastats-backend-v2) Polkadot network statistics (currently Kusama and Alexander). Shows network information and staking details from validators and intentions.
+12 -12
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "1.10.1",
"version": "1.13.1",
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
"main": "index.js",
"keywords": [
@@ -26,21 +26,21 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/api-derive": "1.10.1",
"@polkadot/keyring": "^2.8.1",
"@polkadot/metadata": "1.10.1",
"@polkadot/rpc-core": "1.10.1",
"@polkadot/rpc-provider": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/types-known": "1.10.1",
"@polkadot/util": "^2.8.1",
"@polkadot/util-crypto": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/api-derive": "1.13.1",
"@polkadot/keyring": "^2.9.1",
"@polkadot/metadata": "1.13.1",
"@polkadot/rpc-core": "1.13.1",
"@polkadot/rpc-provider": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/types-known": "1.13.1",
"@polkadot/util": "^2.9.1",
"@polkadot/util-crypto": "^2.9.1",
"bn.js": "^5.1.1",
"eventemitter3": "^4.0.0",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.1"
}
}
+67 -34
View File
@@ -3,8 +3,7 @@
import { Codec } from '@polkadot/types/types';
import { u32, u64 } from '@polkadot/types/primitive';
import { Gas } from '@polkadot/types/interfaces/contracts';
import { Balance, BalanceOf, BlockNumber, Moment, Percent, Permill } from '@polkadot/types/interfaces/runtime';
import { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
import { SessionIndex } from '@polkadot/types/interfaces/session';
import { EraIndex } from '@polkadot/types/interfaces/staking';
@@ -36,26 +35,6 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
};
contracts: {
[index: string]: AugmentedConst<object & Codec>;
/**
* The maximum amount of gas that could be expended per block. A reasonable
* default value is 10_000_000.
**/
blockGasLimit: AugmentedConst<Gas>;
/**
* The base fee charged for calling into a contract. A reasonable default
* value is 135.
**/
callBaseFee: AugmentedConst<Gas>;
/**
* The fee required to instantiate a contract instance. A reasonable default value
* is 21.
**/
contractFee: AugmentedConst<BalanceOf>;
/**
* The base fee charged for instantiating a contract. A reasonable default value
* is 175.
**/
instantiateBaseFee: AugmentedConst<Gas>;
/**
* The maximum nesting level of a call/instantiate stack. A reasonable default
* value is 100.
@@ -72,6 +51,7 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
/**
* The amount of funds a contract should deposit in order to offset
* the cost of one byte.
*
* Let's suppose the deposit is 1,000 BU (balance units)/byte and the rent is 1 BU/byte/day,
* then a contract with 1,000,000 BU that uses 1,000 bytes of storage would pay no rent.
* But if the balance reduced to 500,000 BU and the storage stayed the same at 1,000,
@@ -80,6 +60,7 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
rentDepositOffset: AugmentedConst<BalanceOf>;
/**
* Number of block delay an extrinsic claim surcharge has.
*
* When claim surcharge is called by an extrinsic the rent is checked
* for current_block - delay
**/
@@ -98,14 +79,6 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
* The minimum amount required to generate a tombstone.
**/
tombstoneDeposit: AugmentedConst<BalanceOf>;
/**
* The fee to be paid for making a transaction; the base.
**/
transactionBaseFee: AugmentedConst<BalanceOf>;
/**
* The fee to be paid for making a transaction; the per-byte portion.
**/
transactionByteFee: AugmentedConst<BalanceOf>;
};
democracy: {
[index: string]: AugmentedConst<object & Codec>;
@@ -115,6 +88,7 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
cooloffPeriod: AugmentedConst<BlockNumber>;
/**
* The minimum period of locking and the period between a proposal being approved and enacted.
*
* It should generally be a little more than the unstake period to ensure that
* voting stakers have an opportunity to remove themselves from the system in the case where
* they are on the losing side of a vote.
@@ -146,6 +120,7 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
candidacyBond: AugmentedConst<BalanceOf>;
desiredMembers: AugmentedConst<u32>;
desiredRunnersUp: AugmentedConst<u32>;
moduleId: AugmentedConst<LockIdentifier>;
termDuration: AugmentedConst<BlockNumber>;
votingBond: AugmentedConst<BalanceOf>;
};
@@ -160,6 +135,37 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
**/
windowSize: AugmentedConst<BlockNumber>;
};
identity: {
[index: string]: AugmentedConst<object & Codec>;
/**
* The amount held on deposit for a registered identity.
**/
basicDeposit: AugmentedConst<BalanceOf>;
/**
* The amount held on deposit per additional field for a registered identity.
**/
fieldDeposit: AugmentedConst<BalanceOf>;
/**
* Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O
* required to access an identity, but can be pretty high.
**/
maxAdditionalFields: AugmentedConst<u32>;
/**
* Maxmimum number of registrars allowed in the system. Needed to bound the complexity
* of, e.g., updating judgements.
**/
maxRegistrars: AugmentedConst<u32>;
/**
* The maximum number of sub-accounts allowed per identified account.
**/
maxSubAccounts: AugmentedConst<u32>;
/**
* The amount held on deposit for a registered subaccount. This should account for the fact
* that one storage item's value will increase by the size of an account ID, and there will be
* another trie item whose value is the size of an account ID plus 32 bytes.
**/
subAccountDeposit: AugmentedConst<BalanceOf>;
};
society: {
[index: string]: AugmentedConst<object & Codec>;
/**
@@ -175,6 +181,10 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
* before they become suspended.
**/
maxStrikes: AugmentedConst<u32>;
/**
* The societies's module id
**/
moduleId: AugmentedConst<ModuleId>;
/**
* The amount of incentive paid within each period. Doesn't include VoterTip.
**/
@@ -200,6 +210,29 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
**/
sessionsPerEra: AugmentedConst<SessionIndex>;
};
system: {
[index: string]: AugmentedConst<object & Codec>;
/**
* The base weight of executing a block, independent of the transactions in the block.
**/
blockExecutionWeight: AugmentedConst<Weight>;
/**
* The weight of runtime database operations the runtime can invoke.
**/
dbWeight: AugmentedConst<RuntimeDbWeight>;
/**
* The base weight of an Extrinsic in the block, independent of the of extrinsic being executed.
**/
extrinsicBaseWeight: AugmentedConst<Weight>;
/**
* The maximum length of a block (in bytes).
**/
maximumBlockLength: AugmentedConst<u32>;
/**
* The maximum weight of a block.
**/
maximumBlockWeight: AugmentedConst<Weight>;
};
timestamp: {
[index: string]: AugmentedConst<object & Codec>;
/**
@@ -212,10 +245,6 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
};
transactionPayment: {
[index: string]: AugmentedConst<object & Codec>;
/**
* The fee to be paid for making a transaction; the base.
**/
transactionBaseFee: AugmentedConst<BalanceOf>;
/**
* The fee to be paid for making a transaction; the per-byte portion.
**/
@@ -227,6 +256,10 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
* Percentage of spare funds (if any) that are burnt per spend period.
**/
burn: AugmentedConst<Permill>;
/**
* The treasury's module id, used for deriving its sovereign account ID.
**/
moduleId: AugmentedConst<ModuleId>;
/**
* 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.
+39 -15
View File
@@ -1,15 +1,15 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { AnyNumber, ITuple } from '@polkadot/types/types';
import { AnyNumber, ITuple, Observable } from '@polkadot/types/types';
import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types/primitive';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BabeAuthorityWeight, MaybeVrf, Randomness } from '@polkadot/types/interfaces/babe';
import { BabeAuthorityWeight, MaybeRandomness, Randomness } from '@polkadot/types/interfaces/babe';
import { AccountData, BalanceLock, ReleasesBalances } from '@polkadot/types/interfaces/balances';
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
import { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { CodeHash, ContractInfo, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
import { PreimageStatus, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, Voting } from '@polkadot/types/interfaces/democracy';
import { VoteThreshold } from '@polkadot/types/interfaces/elections';
import { SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
@@ -27,7 +27,6 @@ import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig } from '@polkadot/types/interfaces/utility';
import { VestingInfo } from '@polkadot/types/interfaces/vesting';
import { Observable } from 'rxjs';
import { ApiTypes } from '@polkadot/api/types';
declare module '@polkadot/api/types/storage' {
@@ -70,9 +69,10 @@ declare module '@polkadot/api/types/storage' {
* Temporary value (cleared at block finalization) which is `Some`
* if per-block initialization has already been called for current block.
**/
initialized: AugmentedQuery<ApiType, () => Observable<Option<MaybeVrf>>> & QueryableStorageEntry<ApiType>;
initialized: AugmentedQuery<ApiType, () => Observable<Option<MaybeRandomness>>> & QueryableStorageEntry<ApiType>;
/**
* How late the current block is compared to its parent.
*
* This entry is populated as part of block execution and is cleaned up
* on block finalization. Querying this storage entry outside of block
* execution context should always yield zero.
@@ -84,7 +84,9 @@ declare module '@polkadot/api/types/storage' {
nextRandomness: AugmentedQuery<ApiType, () => Observable<Randomness>> & QueryableStorageEntry<ApiType>;
/**
* The epoch randomness for the *current* epoch.
*
* # Security
*
* This MUST NOT be used for gambling, as it can be influenced by a
* malicious validator in the short term. It MAY be used in many
* cryptographic protocols, however, so long as one remembers that this
@@ -95,22 +97,26 @@ declare module '@polkadot/api/types/storage' {
randomness: AugmentedQuery<ApiType, () => Observable<Randomness>> & QueryableStorageEntry<ApiType>;
/**
* Randomness under construction.
*
* We make a tradeoff between storage accesses and list length.
* We store the under-construction randomness in segments of up to
* `UNDER_CONSTRUCTION_SEGMENT_LENGTH`.
*
* Once a segment reaches this length, we begin the next one.
* We reset all segments and return to `0` at the beginning of every
* epoch.
**/
segmentIndex: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
underConstruction: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Vec<RawVRFOutput>>> & QueryableStorageEntry<ApiType>;
underConstruction: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Vec<Randomness>>> & QueryableStorageEntry<ApiType>;
};
balances: {
[index: string]: QueryableStorageEntry<ApiType>;
/**
* The balance of an account.
*
* NOTE: THIS MAY NEVER BE IN EXISTENCE AND YET HAVE A `total().is_zero()`. If the total
* is ever zero, then the entry *MUST* be removed.
*
* NOTE: This is only used in the case that this module is used to store balances.
**/
account: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<AccountData>> & QueryableStorageEntry<ApiType>;
@@ -121,6 +127,7 @@ declare module '@polkadot/api/types/storage' {
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>> & QueryableStorageEntry<ApiType>;
/**
* Storage version of the pallet.
*
* This is set to v2.0.0 for new networks.
**/
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesBalances>> & QueryableStorageEntry<ApiType>;
@@ -147,14 +154,6 @@ declare module '@polkadot/api/types/storage' {
* Current cost schedule for contracts.
**/
currentSchedule: AugmentedQuery<ApiType, () => Observable<Schedule>> & QueryableStorageEntry<ApiType>;
/**
* The price of one unit of gas.
**/
gasPrice: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
/**
* Gas spent so far in this block.
**/
gasSpent: AugmentedQuery<ApiType, () => Observable<Gas>> & QueryableStorageEntry<ApiType>;
/**
* A mapping from an original code hash to the original code, untouched by instrumentation.
**/
@@ -319,11 +318,13 @@ declare module '@polkadot/api/types/storage' {
/**
* The set of registrars. Not expected to get very big as can only be added through a
* special origin (likely a council motion).
*
* The index into this can be cast to `RegistrarIndex` to get a valid value.
**/
registrars: AugmentedQuery<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>> & QueryableStorageEntry<ApiType>;
/**
* Alternative "sub" identities of this account.
*
* The first item is the deposit, the second is a vector of the accounts.
**/
subsOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>> & QueryableStorageEntry<ApiType>;
@@ -342,6 +343,7 @@ declare module '@polkadot/api/types/storage' {
authoredBlocks: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>> & QueryableStorageEntry<ApiType>;
/**
* The block number after which it's ok to send heartbeats in 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
@@ -382,7 +384,9 @@ declare module '@polkadot/api/types/storage' {
reports: AugmentedQuery<ApiType, (arg: ReportIdOf | string | Uint8Array) => Observable<Option<OffenceDetails>>> & QueryableStorageEntry<ApiType>;
/**
* Enumerates all reports of a kind along with the time they happened.
*
* All reports are sorted by the time of offence.
*
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
* different types are not supported at the moment so we are doing the manual serialization.
**/
@@ -401,12 +405,14 @@ declare module '@polkadot/api/types/storage' {
[index: string]: QueryableStorageEntry<ApiType>;
/**
* Active recovery attempts.
*
* First account is the account to be recovered, and the second account
* is the user trying to recover the account.
**/
activeRecoveries: AugmentedQueryDoubleMap<ApiType, (key1: AccountId | string | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ActiveRecovery>>> & QueryableStorageEntry<ApiType>;
/**
* The list of allowed proxy accounts.
*
* Map from the user who can access it to the recovered account.
**/
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
@@ -434,6 +440,7 @@ declare module '@polkadot/api/types/storage' {
currentIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
/**
* Indices of disabled validators.
*
* The set is cleared when `on_session_ending` returns a new set of identities.
**/
disabledValidators: AugmentedQuery<ApiType, () => Observable<Vec<u32>>> & QueryableStorageEntry<ApiType>;
@@ -532,6 +539,7 @@ declare module '@polkadot/api/types/storage' {
[index: string]: QueryableStorageEntry<ApiType>;
/**
* The active era information, it holds index and start.
*
* The active era is the era currently rewarded.
* Validator set of this era must be equal to `SessionInterface::validators`.
**/
@@ -542,6 +550,7 @@ declare module '@polkadot/api/types/storage' {
bonded: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
/**
* A mapping from still-bonded eras to the first session index of that era.
*
* Must contains information for eras for the range:
* `[active_era - bounding_duration; active_era]`
**/
@@ -553,6 +562,7 @@ declare module '@polkadot/api/types/storage' {
canceledSlashPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
/**
* The current era index.
*
* This is the latest planned era, depending on how the Session pallet queues the validator
* set, it might be active or not.
**/
@@ -573,18 +583,23 @@ declare module '@polkadot/api/types/storage' {
erasRewardPoints: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<EraRewardPoints>> & QueryableStorageEntry<ApiType>;
/**
* Exposure of validator at era.
*
* This is keyed first by the era index to allow bulk deletion and then the stash account.
*
* Is it removed after `HISTORY_DEPTH` eras.
* If stakers hasn't been set or has been removed then empty exposure is returned.
**/
erasStakers: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
/**
* Clipped Exposure of validator at era.
*
* This is similar to [`ErasStakers`] but number of nominators exposed is reduced to the
* `T::MaxNominatorRewardedPerValidator` biggest stakers.
* (Note: the field `total` and `own` of the exposure remains unchanged).
* This is used to limit the i/o cost for the nominator payout.
*
* This is keyed fist by the era index to allow bulk deletion and then the stash account.
*
* Is it removed after `HISTORY_DEPTH` eras.
* If stakers hasn't been set or has been removed then empty exposure is returned.
**/
@@ -600,12 +615,15 @@ declare module '@polkadot/api/types/storage' {
erasTotalStake: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
/**
* Similar to `ErasStakers`, this holds the preferences of validators.
*
* This is keyed first by the era index to allow bulk deletion and then the stash account.
*
* Is it removed after `HISTORY_DEPTH` eras.
**/
erasValidatorPrefs: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>> & QueryableStorageEntry<ApiType>;
/**
* The total validator era payout for the last `HISTORY_DEPTH` eras.
*
* Eras that haven't finished yet or has been removed doesn't have reward.
**/
erasValidatorReward: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Option<BalanceOf>>> & QueryableStorageEntry<ApiType>;
@@ -615,7 +633,9 @@ declare module '@polkadot/api/types/storage' {
forceEra: AugmentedQuery<ApiType, () => Observable<Forcing>> & QueryableStorageEntry<ApiType>;
/**
* Number of eras to keep in history.
*
* Information is kept for eras in `[current_era - history_depth; current_era]`.
*
* Must be more than the number of eras delayed by session otherwise.
* I.e. active era must always be in history.
* I.e. `active_era > current_era - history_depth` must be guaranteed.
@@ -672,6 +692,7 @@ declare module '@polkadot/api/types/storage' {
slashingSpans: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SlashingSpans>>> & QueryableStorageEntry<ApiType>;
/**
* The percentage of the slash that is distributed to reporters.
*
* The rest of the slashed value is handled by the `Slash`.
**/
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>> & QueryableStorageEntry<ApiType>;
@@ -693,6 +714,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 v3.0.0 for new networks.
**/
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesStaking>> & QueryableStorageEntry<ApiType>;
@@ -754,9 +776,11 @@ declare module '@polkadot/api/types/storage' {
/**
* Mapping between a topic (represented by T::Hash) and a vector of indexes
* of events in the `<Events<T>>` list.
*
* All topic vectors have deterministic storage locations depending on the topic. This
* allows light-clients to leverage the changes trie storage tracking mechanism and
* in case of changes fetch the list of events of interest.
*
* The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
* the `EventIndex` then in case if the topic has the same contents on the next block
* no notification will be triggered thus the event might be lost.
+25 -7
View File
@@ -1,7 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types';
import { AnyNumber, Codec, IExtrinsic, Observable } from '@polkadot/types/types';
import { HashMap, Option, Vec } from '@polkadot/types/codec';
import { Bytes, Null, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primitive';
import { Metadata } from '@polkadot/types';
@@ -13,13 +13,13 @@ import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
import { CreatedBlock } from '@polkadot/types/interfaces/engine';
import { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
import { ReportedRoundStates } from '@polkadot/types/interfaces/grandpa';
import { StorageKind } from '@polkadot/types/interfaces/offchain';
import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
import { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, KeyValue, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
import { RuntimeVersion } from '@polkadot/types/interfaces/state';
import { ReadProof, RuntimeVersion } from '@polkadot/types/interfaces/state';
import { ChainProperties, ChainType, Health, NetworkState, NodeRole, PeerInfo } from '@polkadot/types/interfaces/system';
import { Observable } from 'rxjs';
declare module '@polkadot/rpc-core/types.jsonrpc' {
export interface RpcInterface {
@@ -141,15 +141,21 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
**/
finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification | string | Uint8Array) => Observable<bool>>;
};
grandpa: {
/**
* Returns the state of the current best round state as well as the ongoing background rounds
**/
roundState: AugmentedRpc<() => Observable<ReportedRoundStates>>;
};
offchain: {
/**
* 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 | '__UNUSED' | '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 | '__UNUSED' | 'PERSISTENT' | 'LOCAL' | number | Uint8Array, key: Bytes | string | Uint8Array, value: Bytes | string | Uint8Array) => Observable<Null>>;
};
payment: {
/**
@@ -197,9 +203,13 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
**/
getMetadata: AugmentedRpc<(at?: BlockHash | string | Uint8Array) => Observable<Metadata>>;
/**
* Returns the keys with prefix, leave empty to get all the keys
* Returns the keys with prefix, leave empty to get all the keys (deprecated: Use getKeysPaged)
**/
getPairs: AugmentedRpc<(prefix: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Vec<KeyValue>>>;
/**
* Returns proof of storage entries at a specific block state
**/
getReadProof: AugmentedRpc<(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], at?: BlockHash | string | Uint8Array) => Observable<ReadProof>>;
/**
* Get the runtime version
**/
@@ -231,7 +241,7 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
/**
* Subscribes to storage changes for the provided keys
**/
subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[]) => Observable<T>>;
subscribeStorage: AugmentedRpc<<T = Codec[]>(keys?: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[]) => Observable<T>>;
};
system: {
/**
@@ -250,6 +260,14 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
* Return health status of the node
**/
health: AugmentedRpc<() => Observable<Health>>;
/**
* The addresses include a trailing /p2p/ with the local PeerId, and are thus suitable to be passed to addReservedPeer or as a bootnode address for example
**/
localListenAddresses: AugmentedRpc<() => Observable<Vec<Text>>>;
/**
* Returns the base58-encoded PeerId of the node
**/
localPeerId: AugmentedRpc<() => Observable<Text>>;
/**
* Retrieves the node name
**/
File diff suppressed because it is too large Load Diff
+18 -29
View File
@@ -10,8 +10,8 @@ import { SubmittableExtrinsic } from '../submittable/types';
import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, DecoratedRpcSection, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
import BN from 'bn.js';
import { BehaviorSubject, Observable, combineLatest, from, of } from 'rxjs';
import { concatMap, map, switchMap, take, tap, toArray } from 'rxjs/operators';
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs';
import { map, switchMap, take, tap, toArray } from 'rxjs/operators';
import decorateDerive, { ExactDerive } from '@polkadot/api-derive';
import { memo } from '@polkadot/api-derive/util';
import DecoratedMeta from '@polkadot/metadata/Decorated';
@@ -235,7 +235,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
const unknown = exposed.filter((key) => !allKeys.includes(key));
if (unknown.length) {
l.warn(`RPC methods not decorated: ${unknown.join(', ')}}`);
l.warn(`RPC methods not decorated: ${unknown.join(', ')}`);
}
// loop through all entries we have (populated in decorate) and filter as required
@@ -477,7 +477,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
? startSubject.pipe(
switchMap((startKey) =>
this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey).pipe(
map((keys) => keys.map((key) => key.decodeArgsFromMeta(meta)))
map((keys) => keys.map((key) => key.setMeta(meta)))
)
),
tap((keys): void => {
@@ -489,42 +489,31 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
map((keysArr: StorageKey[][]) => keysArr.reduce((result: StorageKey[], keys) => result.concat(keys), []))
)
: this._rpcCore.state.getKeys(headKey).pipe(
map((keys) => keys.map((key) => key.decodeArgsFromMeta(meta)))
map((keys) => keys.map((key) => key.setMeta(meta)))
);
}
private _retrieveMapEntries (entry: StorageEntry, arg?: Arg): Observable<[StorageKey, Codec][]> {
const outputType = unwrapStorageType(entry.meta.type, entry.meta.modifier.isOptional);
return this._retrieveMapKeys(entry, arg).pipe(
switchMap((keys): Observable<[StorageKey[], Option<Raw>[][]]> =>
combineLatest([
switchMap((keys) =>
combineLatest<[StorageKey[], ...Codec[][]]>([
of(keys),
from(Array(Math.ceil(keys.length / PAGE_SIZE_VALS)).fill(0)).pipe(
concatMap((_, index): Observable<Option<Raw>[]> => {
...Array(Math.ceil(keys.length / PAGE_SIZE_VALS))
.fill(0)
.map((_, index): Observable<Codec[]> => {
const keyset = keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS);
return this._rpcCore.state.queryStorageAt
? this._rpcCore.state.queryStorageAt<Option<Raw>[]>(keyset)
: this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keyset).pipe(take(1));
}),
toArray()
)
? this._rpcCore.state.queryStorageAt<Codec[]>(keyset)
: this._rpcCore.state.subscribeStorage<Codec[]>(keyset).pipe(take(1));
})
])
),
map(([keys, valsArr]): [StorageKey, Codec][] => {
const vals = valsArr.reduce((result: Option<Raw>[], vals) => result.concat(vals), []);
return keys.map((key, index): [StorageKey, Codec] => [
key,
this.createType(
outputType,
vals[index].isSome
? vals[index].unwrap().toHex()
: undefined
)
]);
})
map(([keys, ...valsArr]): [StorageKey, Codec][] =>
valsArr
.reduce((result: Codec[], vals) => result.concat(vals), [])
.map((value, index) => [keys[index], value])
)
);
}
+2 -1
View File
@@ -119,7 +119,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
// subscribe to metadata updates, inject the types on changes
private _subscribeUpdates (): void {
if (this.#updateSub) {
if (this.#updateSub || !this.hasSubscriptions) {
return;
}
@@ -139,6 +139,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
this._runtimeMetadata = metadata;
this._runtimeVersion = version;
this._rx.runtimeVersion = version;
this.registerTypes(getSpecTypes(this.registry, this._runtimeChain as Text, version.specName, version.specVersion));
this.injectMetadata(metadata, false);
+1 -1
View File
@@ -264,7 +264,7 @@ export default class ApiPromise extends ApiBase<'promise'> {
* ```
*/
// eslint-disable-next-line @typescript-eslint/require-await
public async combineLatest (fns: (CombinatorFunction | [CombinatorFunction, ...any[]])[], callback: CombinatorCallback): UnsubscribePromise {
public async combineLatest <T extends any[] = any[]> (fns: (CombinatorFunction | [CombinatorFunction, ...any[]])[], callback: CombinatorCallback<T>): UnsubscribePromise {
const combinator = new Combinator(fns, callback);
return (): void => {
+6 -5
View File
@@ -7,15 +7,16 @@ import { UnsubscribePromise } from '../types';
import { isFunction } from '@polkadot/util';
export type CombinatorCallback = Callback<any[]>;
export type CombinatorCallback <T extends any[]> = Callback<T>;
export interface CombinatorFunction {
(cb: Callback<any>): UnsubscribePromise;
}
export default class Combinator {
export default class Combinator<T extends any[] = any[]> {
#allHasFired = false;
#callback: CombinatorCallback;
#callback: CombinatorCallback<T>;
#fired: boolean[] = [];
@@ -27,7 +28,7 @@ export default class Combinator {
#subscriptions: UnsubscribePromise[] = [];
constructor (fns: (CombinatorFunction | [CombinatorFunction, ...any[]])[], callback: CombinatorCallback) {
constructor (fns: (CombinatorFunction | [CombinatorFunction, ...any[]])[], callback: CombinatorCallback<T>) {
this.#callback = callback;
// eslint-disable-next-line @typescript-eslint/require-await
@@ -67,7 +68,7 @@ export default class Combinator {
}
try {
this.#callback(this.#results);
this.#callback(this.#results as T);
} catch (error) {
// swallow, we don't want the handler to trip us up
}
+17
View File
@@ -49,5 +49,22 @@ describe('ApiRx', (): void => {
})
);
});
it('allows the second argument to signAsync to be omitted', () => {
const signer = new SingleAccountSigner(registry, keyring.alice_session);
ApiRx.create({ provider, registry, signer }).pipe(
switchMap((api: ApiRx): Observable<SubmittableExtrinsic<'rxjs'>> =>
api.tx.balances
.transfer(keyring.eve.address, 12345)
.signAsync(keyring.alice_session)
),
map((tx: SubmittableExtrinsic<'rxjs'>): void => {
expect(tx.signature.toHex()).toEqual(
'0x97f3cfe5088fcd575313e983f45d02b0f630e7b94ff9a3ac50e20cd096a8f554fda73d42ead891b5a1d3ce5607d83f20b0c6570b555e949cfb5763d0abcd590b'
);
})
);
});
});
});
+4 -4
View File
@@ -60,7 +60,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
}
// sign a transaction, returning the this to allow chaining, i.e. .sign(...).send()
public sign (account: IKeyringPair, optionsOrNonce: Partial<SignerOptions>): this {
public sign (account: IKeyringPair, optionsOrNonce?: Partial<SignerOptions>): this {
super.sign(account, this.#makeSignOptions(this.#optionsOrNonce(optionsOrNonce), {}));
return this;
@@ -69,7 +69,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
// signs a transaction, returning `this` to allow chaining. E.g.: `sign(...).send()`
//
// also supports signing through external signers
public signAsync (account: AddressOrPair, optionsOrNonce: Partial<SignerOptions>): SubmittableThis<ApiType, this> {
public signAsync (account: AddressOrPair, optionsOrNonce?: Partial<SignerOptions>): SubmittableThis<ApiType, this> {
return decorateMethod(
(): Observable<this> =>
this.#observeSign(account, optionsOrNonce).pipe(mapTo(this))
@@ -164,7 +164,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
return [options, statusCb];
}
#observeSign = (account: AddressOrPair, optionsOrNonce: Partial<SignerOptions>): Observable<number | undefined> => {
#observeSign = (account: AddressOrPair, optionsOrNonce?: Partial<SignerOptions>): Observable<number | undefined> => {
const address = isKeyringPair(account) ? account.address : account.toString();
const options = this.#optionsOrNonce(optionsOrNonce);
let updateId: number | undefined;
@@ -224,7 +224,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
// NOTE here we actually override nonce if it was specified (backwards compat for
// the previous signature - don't let userspace break, but allow then time to upgrade)
#optionsOrNonce = (optionsOrNonce: Partial<SignerOptions>): Partial<SignerOptions> => {
#optionsOrNonce = (optionsOrNonce: Partial<SignerOptions> = {}): Partial<SignerOptions> => {
return isBn(optionsOrNonce) || isNumber(optionsOrNonce)
? { nonce: optionsOrNonce }
: optionsOrNonce;
+2 -2
View File
@@ -50,9 +50,9 @@ export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends Extrinsi
send(statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
sign(account: IKeyringPair, _options: Partial<SignatureOptions>): this;
sign(account: IKeyringPair, _options?: Partial<SignatureOptions>): this;
signAsync(account: AddressOrPair, _options: Partial<SignatureOptions>): SubmittableThis<ApiType, this>;
signAsync(account: AddressOrPair, _options?: Partial<SignatureOptions>): SubmittableThis<ApiType, this>;
signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableResultResult<ApiType>;
+2
View File
@@ -9,6 +9,8 @@ function createApi (): Promise<ApiPromise> {
process.env.NODE_ENV = 'test';
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
// const provider = new WsProvider('wss://westend-rpc.polkadot.io/');
// const provider = new WsProvider('ws://127.0.0.1:9944/');
return new ApiPromise({ provider }).isReady;
}
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/metadata",
"version": "1.10.1",
"version": "1.13.1",
"description": "Helpers to extract information from runtime metadata",
"main": "index.js",
"publishConfig": {
@@ -26,14 +26,14 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/types": "1.10.1",
"@polkadot/types-known": "1.10.1",
"@polkadot/util": "^2.8.1",
"@polkadot/util-crypto": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/types": "1.13.1",
"@polkadot/types-known": "1.13.1",
"@polkadot/util": "^2.9.1",
"@polkadot/util-crypto": "^2.9.1",
"bn.js": "^5.1.1"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.1"
}
}
@@ -4,8 +4,6 @@
import { TypeRegistry } from '@polkadot/types';
import polkadotJson from './static-polkadot.json';
import polkadotData from './static.polkadot';
import substrateJson from './static-substrate.json';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
@@ -19,13 +17,3 @@ describe('MetadataV11 (substrate)', (): void => {
defaultValues(registry, substrateData);
});
describe('MetadataV11 (polkadot)', (): void => {
const registry = new TypeRegistry();
decodeLatestSubstrate(registry, 11, polkadotData, polkadotJson);
toLatest(registry, 11, polkadotData);
defaultValues(registry, polkadotData);
});
File diff suppressed because it is too large Load Diff
@@ -226,7 +226,11 @@
}
],
"documentation": [
" Make some on-chain remark."
" Make some on-chain remark.",
"",
" # <weight>",
" - `O(1)`",
" # </weight>"
]
},
{
@@ -238,7 +242,12 @@
}
],
"documentation": [
" Set the number of pages in the WebAssembly environment's heap."
" Set the number of pages in the WebAssembly environment's heap.",
"",
" # <weight>",
" - `O(1)`",
" - 1 storage write.",
" # </weight>"
]
},
{
@@ -250,7 +259,14 @@
}
],
"documentation": [
" Set the new runtime code."
" Set the new runtime code.",
"",
" # <weight>",
" - `O(C + S)` where `C` length of `code` and `S` complexity of `can_set_code`",
" - 1 storage write (codec `O(C)`).",
" - 1 call to `can_set_code`: `O(S)` (calls `sp_io::misc::runtime_version` which is expensive).",
" - 1 event.",
" # </weight>"
]
},
{
@@ -262,7 +278,13 @@
}
],
"documentation": [
" Set the new runtime code without doing any checks of the given `code`."
" Set the new runtime code without doing any checks of the given `code`.",
"",
" # <weight>",
" - `O(C)` where `C` length of `code`",
" - 1 storage write (codec `O(C)`).",
" - 1 event.",
" # </weight>"
]
},
{
@@ -274,7 +296,13 @@
}
],
"documentation": [
" Set the new changes trie configuration."
" Set the new changes trie configuration.",
"",
" # <weight>",
" - `O(D)` where `D` length of `Digest`",
" - 1 storage write or delete (codec `O(1)`).",
" - 1 call to `deposit_log`: `O(D)` (which depends on the length of `Digest`)",
" # </weight>"
]
},
{
@@ -286,7 +314,12 @@
}
],
"documentation": [
" Set some items of storage."
" Set some items of storage.",
"",
" # <weight>",
" - `O(I)` where `I` length of `items`",
" - `I` storage writes (`O(1)`).",
" # </weight>"
]
},
{
@@ -298,7 +331,12 @@
}
],
"documentation": [
" Kill some items from storage."
" Kill some items from storage.",
"",
" # <weight>",
" - `O(VK)` where `V` length of `keys` and `K` length of one key",
" - `V` storage deletions.",
" # </weight>"
]
},
{
@@ -310,7 +348,12 @@
}
],
"documentation": [
" Kill all storage items with a key that starts with the given prefix."
" Kill all storage items with a key that starts with the given prefix.",
"",
" # <weight>",
" - `O(P)` where `P` amount of keys with prefix `prefix`",
" - `P` storage deletions.",
" # </weight>"
]
},
{
@@ -318,7 +361,12 @@
"args": [],
"documentation": [
" Kill the sending account, assuming there are no references outstanding and the composite",
" data is equal to its default value."
" data is equal to its default value.",
"",
" # <weight>",
" - `O(1)`",
" - 1 storage read and deletion.",
" # </weight>"
]
}
],
@@ -368,7 +416,48 @@
]
}
],
"constants": [],
"constants": [
{
"name": "MaximumBlockWeight",
"type": "Weight",
"value": "0x00204aa9d1010000",
"documentation": [
" The maximum weight of a block."
]
},
{
"name": "DbWeight",
"type": "RuntimeDbWeight",
"value": "0x40787d010000000000e1f50500000000",
"documentation": [
" The weight of runtime database operations the runtime can invoke."
]
},
{
"name": "BlockExecutionWeight",
"type": "Weight",
"value": "0x00f2052a01000000",
"documentation": [
" The base weight of executing a block, independent of the transactions in the block."
]
},
{
"name": "ExtrinsicBaseWeight",
"type": "Weight",
"value": "0x4059730700000000",
"documentation": [
" The base weight of an Extrinsic in the block, independent of the of extrinsic being executed."
]
},
{
"name": "MaximumBlockLength",
"type": "u32",
"value": "0x00005000",
"documentation": [
" The maximum length of a block (in bytes)."
]
}
],
"errors": [
{
"name": "InvalidSpecName",
@@ -449,8 +538,9 @@
" - `calls`: The calls to be dispatched from the same origin.",
"",
" # <weight>",
" - The sum of the weights of the `calls`.",
" - One event.",
" - Base weight: 14.39 + .987 * c µs",
" - Plus the sum of the weights of the `calls`.",
" - Plus one additional event. (repeat read/write)",
" # </weight>",
"",
" This will return `Ok` in all circumstances. To determine the success of the batch, an",
@@ -478,7 +568,8 @@
" The dispatch origin for this call must be _Signed_.",
"",
" # <weight>",
" - The weight of the `call` + 10,000.",
" - Base weight: 2.861 µs",
" - Plus the weight of the `call`",
" # </weight>"
]
},
@@ -543,6 +634,15 @@
" - Storage: inserts one item, value size bounded by `MaxSignatories`, with a",
" deposit taken for its lifetime of",
" `MultisigDepositBase + threshold * MultisigDepositFactor`.",
" -------------------------------",
" - Base Weight:",
" - Create: 46.55 + 0.089 * S µs",
" - Approve: 34.03 + .112 * S µs",
" - Complete: 40.36 + .225 * S µs",
" - DB Weight:",
" - Reads: Multisig Storage, [Caller Account]",
" - Writes: Multisig Storage, [Caller Account]",
" - Plus Call Weight",
" # </weight>"
]
},
@@ -598,6 +698,13 @@
" - Storage: inserts one item, value size bounded by `MaxSignatories`, with a",
" deposit taken for its lifetime of",
" `MultisigDepositBase + threshold * MultisigDepositFactor`.",
" ----------------------------------",
" - Base Weight:",
" - Create: 44.71 + 0.088 * S",
" - Approve: 31.48 + 0.116 * S",
" - DB Weight:",
" - Read: Multisig Storage, [Caller Account]",
" - Write: Multisig Storage, [Caller Account]",
" # </weight>"
]
},
@@ -643,6 +750,11 @@
" - One event.",
" - I/O: 1 read `O(S)`, one remove.",
" - Storage: removes one item.",
" ----------------------------------",
" - Base Weight: 37.6 + 0.084 * S",
" - DB Weight:",
" - Read: Multisig Storage, [Caller Account]",
" - Write: Multisig Storage, [Caller Account]",
" # </weight>"
]
}
@@ -902,7 +1014,7 @@
"Map": {
"hasher": "Twox64Concat",
"key": "u32",
"value": "Vec<RawVRFOutput>",
"value": "Vec<Randomness>",
"linked": false
}
},
@@ -913,7 +1025,7 @@
"name": "Initialized",
"modifier": "Optional",
"type": {
"Plain": "MaybeVrf"
"Plain": "MaybeRandomness"
},
"fallback": "0x00",
"documentation": [
@@ -1012,7 +1124,16 @@
" The timestamp should be greater than the previous one by the amount specified by",
" `MinimumPeriod`.",
"",
" The dispatch origin for this call must be `Inherent`."
" The dispatch origin for this call must be `Inherent`.",
"",
" # <weight>",
" - `O(T)` where `T` complexity of `on_timestamp_set`",
" - 1 storage read and 1 storage mutation (codec `O(1)`). (because of `DidUpdate::take` in `on_finalize`)",
" - 1 event handler `on_timestamp_set` `O(T)`.",
" - Benchmark: 8.523 (min squares analysis)",
" - NOTE: This benchmark was done for a runtime with insignificant `on_timestamp_set` handlers.",
" New benchmarking is needed when adding new handlers.",
" # </weight>"
]
}
],
@@ -1403,7 +1524,10 @@
" - Removing enough funds from an account will trigger `T::DustRemoval::on_unbalanced`.",
" - `transfer_keep_alive` works the same way as `transfer`, but has an additional",
" check that the transfer will not kill the origin account.",
"",
" ---------------------------------",
" - Base Weight: 73.64 µs, worst case scenario (account created, account removed)",
" - DB Weight: 1 Read and 1 Write to destination account",
" - Origin account is already in memory, so no DB operations for them.",
" # </weight>"
]
},
@@ -1436,6 +1560,11 @@
" # <weight>",
" - Independent of the arguments.",
" - Contains a limited number of reads and writes.",
" ---------------------",
" - Base Weight:",
" - Creating: 27.56 µs",
" - Killing: 35.11 µs",
" - DB Weight: 1 Read, 1 Write to `who`",
" # </weight>"
]
},
@@ -1457,7 +1586,11 @@
],
"documentation": [
" Exactly as `transfer`, except the origin must be root and the source account may be",
" specified."
" specified.",
" # <weight>",
" - Same as transfer, but additional read and write because the source account is",
" not assumed to be in the overlay.",
" # </weight>"
]
},
{
@@ -1478,7 +1611,12 @@
"",
" 99% of the time you want [`transfer`] instead.",
"",
" [`transfer`]: struct.Module.html#method.transfer"
" [`transfer`]: struct.Module.html#method.transfer",
" # <weight>",
" - Cheaper than transfer because account cannot be killed.",
" - Base Weight: 51.4 µs",
" - DB Weight: 1 Read and 1 Write to dest (sender is in overlay already)",
" #</weight>"
]
}
],
@@ -1609,7 +1747,7 @@
"type": {
"Plain": "Multiplier"
},
"fallback": "0x0000000000000000",
"fallback": "0x00000000000000000000000000000000",
"documentation": []
}
]
@@ -1617,14 +1755,6 @@
"calls": null,
"events": null,
"constants": [
{
"name": "TransactionBaseFee",
"type": "BalanceOf",
"value": "0x0010a5d4e80000000000000000000000",
"documentation": [
" The fee to be paid for making a transaction; the base."
]
},
{
"name": "TransactionByteFee",
"type": "BalanceOf",
@@ -2754,7 +2884,7 @@
" - Memory: O(n + m) reads to map index to `AccountId` for un-compact.",
"",
" - Storage: O(e) accountid reads from `Nomination` to read correct nominations.",
" - Storage: O(e) calls into `slashable_balance_of_extended` to convert ratio to staked.",
" - Storage: O(e) calls into `slashable_balance_of_vote_weight` to convert ratio to staked.",
"",
" - Memory: build_support_map. O(e).",
" - Memory: evaluate_support: O(E).",
@@ -2796,6 +2926,18 @@
}
],
"events": [
{
"name": "EraPayout",
"args": [
"EraIndex",
"Balance",
"Balance"
],
"documentation": [
" The era payout has been set; the first balance is the validator-payout; the second is",
" the remainder from the maximum amount of reward."
]
},
{
"name": "Reward",
"args": [
@@ -3181,10 +3323,12 @@
" The dispatch origin of this function must be signed.",
"",
" # <weight>",
" - O(log n) in number of accounts.",
" - One extra DB entry.",
" - Increases system account refs by one on success iff there were previously no keys set.",
" In this case, purge_keys will need to be called before the account can be removed.",
" - Complexity: `O(1)`",
" Actual cost depends on the number of length of `T::Keys::key_ids()` which is fixed.",
" - DbReads: `origin account`, `T::ValidatorIdOf`, `NextKeys`",
" - DbWrites: `origin account`, `NextKeys`",
" - DbReads per key id: `KeyOwner`",
" - DbWrites per key id: `KeyOwner`",
" # </weight>"
]
},
@@ -3198,9 +3342,11 @@
" The dispatch origin of this function must be signed.",
"",
" # <weight>",
" - O(N) in number of key types.",
" - Removes N + 1 DB entries.",
" - Reduces system account refs by one on success.",
" - Complexity: `O(1)` in number of key types.",
" Actual cost depends on the number of length of `T::Keys::key_ids()` which is fixed.",
" - DbReads: `T::ValidatorIdOf`, `NextKeys`, `origin account`",
" - DbWrites: `NextKeys`, `origin account`",
" - DbWrites per key id: `KeyOwnder`",
" # </weight>"
]
}
@@ -5475,15 +5621,18 @@
"Vec<(AccountId,Balance)>"
],
"documentation": [
" A new term with new members. This indicates that enough candidates existed, not that",
" enough have has been elected. The inner value must be examined for this purpose."
" 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."
]
},
{
"name": "EmptyTerm",
"args": [],
"documentation": [
" No (or not enough) candidates existed for this round."
" No (or not enough) candidates existed for this round. This is different from",
" `NewTerm([])`. See the description of `NewTerm`."
]
},
{
@@ -5548,6 +5697,12 @@
"type": "BlockNumber",
"value": "0x80130300",
"documentation": []
},
{
"name": "ModuleId",
"type": "LockIdentifier",
"value": "0x706872656c656374",
"documentation": []
}
],
"errors": [
@@ -6115,9 +6270,9 @@
" proposal is awarded.",
"",
" # <weight>",
" - O(1).",
" - Limited storage reads.",
" - One DB change, one extra DB entry.",
" - Complexity: O(1)",
" - DbReads: `ProposalCount`, `origin account`",
" - DbWrites: `ProposalCount`, `Proposals`, `origin account`",
" # </weight>"
]
},
@@ -6133,9 +6288,9 @@
" Reject a proposed spend. The original deposit will be slashed.",
"",
" # <weight>",
" - O(1).",
" - Limited storage reads.",
" - One DB clear.",
" - Complexity: O(1)",
" - DbReads: `Proposals`, `rejected proposer account`",
" - DbWrites: `Proposals`, `rejected proposer account`",
" # </weight>"
]
},
@@ -6152,9 +6307,9 @@
" and the original deposit will be returned.",
"",
" # <weight>",
" - O(1).",
" - Limited storage reads.",
" - One DB change.",
" - Complexity: O(1).",
" - DbReads: `Proposals`, `Approvals`",
" - DbWrite: `Approvals`",
" # </weight>"
]
},
@@ -6185,10 +6340,10 @@
" Emits `NewTip` if successful.",
"",
" # <weight>",
" - `O(R)` where `R` length of `reason`.",
" - One balance operation.",
" - One storage mutation (codec `O(R)`).",
" - One event.",
" - Complexity: `O(R)` where `R` length of `reason`.",
" - encoding and hashing of 'reason'",
" - DbReads: `Reasons`, `Tips`, `who account data`",
" - DbWrites: `Tips`, `who account data`",
" # </weight>"
]
},
@@ -6215,10 +6370,10 @@
" Emits `TipRetracted` if successful.",
"",
" # <weight>",
" - `O(T)`",
" - One balance operation.",
" - Two storage removals (one read, codec `O(T)`).",
" - One event.",
" - Complexity: `O(1)`",
" - Depends on the length of `T::Hash` which is fixed.",
" - DbReads: `Tips`, `origin account`",
" - DbWrites: `Reasons`, `Tips`, `origin account`",
" # </weight>"
]
},
@@ -6253,10 +6408,13 @@
" Emits `NewTip` if successful.",
"",
" # <weight>",
" - `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. `T` is",
" naturally capped as a membership set, `R` is limited through transaction-size.",
" - Two storage insertions (codecs `O(R)`, `O(T)`), one read `O(1)`.",
" - One event.",
" - Complexity: `O(R + T)` where `R` length of `reason`, `T` is the number of tippers.",
" - `O(T)`: decoding `Tipper` vec of length `T`",
" `T` is charged as upper bound given by `ContainsLengthBound`.",
" The actual cost depends on the implementation of `T::Tippers`.",
" - `O(R)`: hashing and encoding of reason of length `R`",
" - DbReads: `Tippers`, `Reasons`",
" - DbWrites: `Reasons`, `Tips`",
" # </weight>"
]
},
@@ -6288,9 +6446,15 @@
" has started.",
"",
" # <weight>",
" - `O(T)`",
" - One storage mutation (codec `O(T)`), one storage read `O(1)`.",
" - Up to one event.",
" - Complexity: `O(T)` where `T` is the number of tippers.",
" decoding `Tipper` vec of length `T`, insert tip and check closing,",
" `T` is charged as upper bound given by `ContainsLengthBound`.",
" The actual cost depends on the implementation of `T::Tippers`.",
"",
" Actually weight could be lower as it depends on how many tips are in `OpenTip` but it",
" is weighted as if almost full i.e of length `T-1`.",
" - DbReads: `Tippers`, `Tips`",
" - DbWrites: `Tips`",
" # </weight>"
]
},
@@ -6313,9 +6477,12 @@
" as the hash of the tuple of the original tip `reason` and the beneficiary account ID.",
"",
" # <weight>",
" - `O(T)`",
" - One storage retrieval (codec `O(T)`) and two removals.",
" - Up to three balance operations.",
" - Complexity: `O(T)` where `T` is the number of tippers.",
" decoding `Tipper` vec of length `T`.",
" `T` is charged as upper bound given by `ContainsLengthBound`.",
" The actual cost depends on the implementation of `T::Tippers`.",
" - DbReads: `Tips`, `Tippers`, `tip finder`",
" - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder`",
" # </weight>"
]
}
@@ -6491,6 +6658,14 @@
"documentation": [
" The amount held on deposit per byte within the tip report reason."
]
},
{
"name": "ModuleId",
"type": "ModuleId",
"value": "0x70792f7472737279",
"documentation": [
" The treasury's module id, used for deriving its sovereign account ID."
]
}
],
"errors": [
@@ -6549,24 +6724,13 @@
"storage": {
"prefix": "Contracts",
"items": [
{
"name": "GasSpent",
"modifier": "Default",
"type": {
"Plain": "Gas"
},
"fallback": "0x0000000000000000",
"documentation": [
" Gas spent so far in this block."
]
},
{
"name": "CurrentSchedule",
"modifier": "Default",
"type": {
"Plain": "Schedule"
},
"fallback": "0x0000000001000000000000000100000000000000010000000000000001000000000000000100000000000000010000000000000001000000000000008700000000000000af00000000000000010000000000000001000000000000006400000000000000040000000000010010000000004000000020000000",
"fallback": "0x0000000020a107000000000020a107000000000020a107000000000020a107000000000020a107000000000020a107000000000020a1070000000000e0f7050400000000e024370500000000e0f705040000000020a107000000000020a107000000000080f0fa020000000000e1f50500000000040000000000010010000000004000000020000000",
"documentation": [
" Current cost schedule for contracts."
]
@@ -6629,17 +6793,6 @@
"documentation": [
" The code associated with a given account."
]
},
{
"name": "GasPrice",
"modifier": "Default",
"type": {
"Plain": "BalanceOf"
},
"fallback": "0x01000000000000000000000000000000",
"documentation": [
" The price of one unit of gas."
]
}
]
},
@@ -6661,10 +6814,6 @@
{
"name": "put_code",
"args": [
{
"name": "gas_limit",
"type": "Compact<Gas>"
},
{
"name": "code",
"type": "Bytes"
@@ -6917,49 +7066,6 @@
" to removal of a contract."
]
},
{
"name": "TransactionBaseFee",
"type": "BalanceOf",
"value": "0x0010a5d4e80000000000000000000000",
"documentation": [
" The fee to be paid for making a transaction; the base."
]
},
{
"name": "TransactionByteFee",
"type": "BalanceOf",
"value": "0x00e40b54020000000000000000000000",
"documentation": [
" The fee to be paid for making a transaction; the per-byte portion."
]
},
{
"name": "ContractFee",
"type": "BalanceOf",
"value": "0x0010a5d4e80000000000000000000000",
"documentation": [
" The fee required to instantiate a contract instance. A reasonable default value",
" is 21."
]
},
{
"name": "CallBaseFee",
"type": "Gas",
"value": "0xe803000000000000",
"documentation": [
" The base fee charged for calling into a contract. A reasonable default",
" value is 135."
]
},
{
"name": "InstantiateBaseFee",
"type": "Gas",
"value": "0xe803000000000000",
"documentation": [
" The base fee charged for instantiating a contract. A reasonable default value",
" is 175."
]
},
{
"name": "MaxDepth",
"type": "u32",
@@ -6976,15 +7082,6 @@
"documentation": [
" The maximum size of a storage value in bytes. A reasonable default is 16 KiB."
]
},
{
"name": "BlockGasLimit",
"type": "Gas",
"value": "0x8096980000000000",
"documentation": [
" The maximum amount of gas that could be expended per block. A reasonable",
" default value is 10_000_000."
]
}
],
"errors": [
@@ -7117,7 +7214,7 @@
{
"name": "Sudid",
"args": [
"bool"
"DispatchResult"
],
"documentation": [
" A sudo just took place."
@@ -7235,7 +7332,18 @@
"type": "Signature"
}
],
"documentation": []
"documentation": [
" # <weight>",
" - Complexity: `O(K + E)` where K is length of `Keys` and E is length of",
" `Heartbeat.network_state.external_address`",
"",
" - `O(K)`: decoding of length `K`",
" - `O(E)`: decoding/encoding of length `E`",
" - DbReads: pallet_session `Validators`, pallet_session `CurrentIndex`, `Keys`,",
" `ReceivedHeartbeats`",
" - DbWrites: `ReceivedHeartbeats`",
" # </weight>"
]
}
],
"events": [
@@ -7497,9 +7605,10 @@
" Emits `RegistrarAdded` if successful.",
"",
" # <weight>",
" - `O(R)` where `R` registrar-count (governance-bounded).",
" - `O(R)` where `R` registrar-count (governance-bounded and code-bounded).",
" - One storage mutation (codec `O(R)`).",
" - One event.",
" - Benchmark: 24.63 + R * 0.53 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7517,18 +7626,20 @@
" If the account already has identity information, the deposit is taken as part payment",
" for the new deposit.",
"",
" The dispatch origin for this call must be _Signed_ and the sender must have a registered",
" identity.",
" The dispatch origin for this call must be _Signed_.",
"",
" - `info`: The identity information.",
"",
" Emits `IdentitySet` if successful.",
"",
" # <weight>",
" - `O(X + X' + R)` where `X` additional-field-count (deposit-bounded and code-bounded).",
" - At most two balance operations.",
" - `O(X + X' + R)`",
" - where `X` additional-field-count (deposit-bounded and code-bounded)",
" - where `R` judgements-count (registrar-count-bounded)",
" - One balance reserve operation.",
" - One storage mutation (codec-read `O(X' + R)`, codec-write `O(X + R)`).",
" - One event.",
" - Benchmark: 59.44 + R * 0.389 + X * 1.434 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7549,13 +7660,19 @@
" The dispatch origin for this call must be _Signed_ and the sender must have a registered",
" identity.",
"",
" - `subs`: The identity's sub-accounts.",
" - `subs`: The identity's (new) sub-accounts.",
"",
" # <weight>",
" - `O(S)` where `S` subs-count (hard- and deposit-bounded).",
" - At most two balance operations.",
" - At most O(2 * S + 1) storage mutations; codec complexity `O(1 * S + S * 1)`);",
" one storage-exists.",
" - `O(P + S)`",
" - where `P` old-subs-count (hard- and deposit-bounded).",
" - where `S` subs-count (hard- and deposit-bounded).",
" - At most one balance operations.",
" - DB:",
" - `P + S` storage mutations (codec complexity `O(1)`)",
" - One storage read (codec complexity `O(P)`).",
" - One storage write (codec complexity `O(S)`).",
" - One storage-exists (`IdentityOf::contains_key`).",
" - Benchmark: 39.43 + P * 2.522 + S * 3.698 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7563,7 +7680,7 @@
"name": "clear_identity",
"args": [],
"documentation": [
" Clear an account's identity info and all sub-account and return all deposits.",
" Clear an account's identity info and all sub-accounts and return all deposits.",
"",
" Payment: All reserved balances on the account are returned.",
"",
@@ -7573,10 +7690,16 @@
" Emits `IdentityCleared` if successful.",
"",
" # <weight>",
" - `O(R + S + X)`.",
" - One balance-reserve operation.",
" - `S + 2` storage deletions.",
" - `O(R + S + X)`",
" - where `R` registrar-count (governance-bounded).",
" - where `S` subs-count (hard- and deposit-bounded).",
" - where `X` additional-field-count (deposit-bounded and code-bounded).",
" - One balance-unreserve operation.",
" - `2` storage reads and `S + 2` storage deletions.",
" - One event.",
" - Benchmarks:",
" - 57.36 + R * 0.019 + S * 2.577 + X * 0.874 µs (median slopes analysis)",
" - 57.06 + R * 0.006 + S * 2.579 + X * 0.878 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7605,7 +7728,7 @@
" - `max_fee`: The maximum fee that may be paid. This should just be auto-populated as:",
"",
" ```nocompile",
" Self::registrars(reg_index).unwrap().fee",
" Self::registrars().get(reg_index).unwrap().fee",
" ```",
"",
" Emits `JudgementRequested` if successful.",
@@ -7615,6 +7738,7 @@
" - One balance-reserve operation.",
" - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`.",
" - One event.",
" - Benchmark: 59.02 + R * 0.488 + X * 1.7 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7643,6 +7767,7 @@
" - One balance-reserve operation.",
" - One storage mutation `O(R + X)`.",
" - One event.",
" - Benchmark: 50.05 + R * 0.321 + X * 1.688 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7670,6 +7795,7 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmark: 8.848 + R * 0.425 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7697,6 +7823,7 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmark: 10.05 + R * 0.438 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7724,6 +7851,7 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmark: 8.985 + R * 0.413 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7762,6 +7890,7 @@
" - Up to one account-lookup operation.",
" - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`.",
" - One event.",
" - Benchmark: 47.77 + R * 0.336 + X * 1.664 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7792,6 +7921,7 @@
" - One balance-reserve operation.",
" - `S + 2` storage mutations.",
" - One event.",
" - Benchmark: 101.9 + R * 0.091 + S * 2.589 + X * 0.871 µs (min squares analysis)",
" # </weight>"
]
}
@@ -7866,7 +7996,60 @@
]
}
],
"constants": [],
"constants": [
{
"name": "BasicDeposit",
"type": "BalanceOf",
"value": "0x0080c6a47e8d03000000000000000000",
"documentation": [
" The amount held on deposit for a registered identity."
]
},
{
"name": "FieldDeposit",
"type": "BalanceOf",
"value": "0x00a031a95fe300000000000000000000",
"documentation": [
" The amount held on deposit per additional field for a registered identity."
]
},
{
"name": "SubAccountDeposit",
"type": "BalanceOf",
"value": "0x0080f420e6b500000000000000000000",
"documentation": [
" The amount held on deposit for a registered subaccount. This should account for the fact",
" that one storage item's value will increase by the size of an account ID, and there will be",
" another trie item whose value is the size of an account ID plus 32 bytes."
]
},
{
"name": "MaxSubAccounts",
"type": "u32",
"value": "0x64000000",
"documentation": [
" The maximum number of sub-accounts allowed per identified account."
]
},
{
"name": "MaxAdditionalFields",
"type": "u32",
"value": "0x64000000",
"documentation": [
" Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O",
" required to access an identity, but can be pretty high."
]
},
{
"name": "MaxRegistrars",
"type": "u32",
"value": "0x14000000",
"documentation": [
" Maxmimum number of registrars allowed in the system. Needed to bound the complexity",
" of, e.g., updating judgements."
]
}
],
"errors": [
{
"name": "TooManySubAccounts",
@@ -7939,6 +8122,12 @@
"documentation": [
" Too many additional fields."
]
},
{
"name": "TooManyRegistrars",
"documentation": [
" Maximum amount of registrars reached. Cannot add any more."
]
}
]
},
@@ -8793,6 +8982,14 @@
"documentation": [
" The number of blocks between membership challenges."
]
},
{
"name": "ModuleId",
"type": "ModuleId",
"value": "0x70792f736f636965",
"documentation": [
" The societies's module id"
]
}
],
"errors": [
@@ -9453,9 +9650,13 @@
"",
" # <weight>",
" - `O(1)`.",
" - One balance-lock operation.",
" - One storage read (codec `O(1)`) and up to one removal.",
" - One event.",
" - DbWeight: 2 Reads, 2 Writes",
" - Reads: Vesting Storage, Balances Locks, [Sender Account]",
" - Writes: Vesting Storage, Balances Locks, [Sender Account]",
" - Benchmark:",
" - Unlocked: 48.76 + .048 * l µs (min square analysis)",
" - Locked: 44.43 + .284 * l µs (min square analysis)",
" - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.",
" # </weight>"
]
},
@@ -9479,10 +9680,13 @@
"",
" # <weight>",
" - `O(1)`.",
" - Up to one account lookup.",
" - One balance-lock operation.",
" - One storage read (codec `O(1)`) and up to one removal.",
" - One event.",
" - DbWeight: 3 Reads, 3 Writes",
" - Reads: Vesting Storage, Balances Locks, Target Account",
" - Writes: Vesting Storage, Balances Locks, Target Account",
" - Benchmark:",
" - Unlocked: 44.3 + .294 * l µs (min square analysis)",
" - Locked: 48.16 + .103 * l µs (min square analysis)",
" - Using 50 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.",
" # </weight>"
]
},
@@ -9510,8 +9714,12 @@
" Emits `VestingCreated`.",
"",
" # <weight>",
" - Creates a new storage entry, but is protected by a minimum transfer",
"\t amount needed to succeed.",
" - `O(1)`.",
" - DbWeight: 3 Reads, 3 Writes",
" - Reads: Vesting Storage, Balances Locks, Target Account, [Sender Account]",
" - Writes: Vesting Storage, Balances Locks, Target Account, [Sender Account]",
" - Benchmark: 100.3 + .365 * l µs (min square analysis)",
" - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.",
" # </weight>"
]
}
@@ -9639,8 +9847,7 @@
"CheckEra",
"CheckNonce",
"CheckWeight",
"ChargeTransactionPayment",
"CheckBlockGasLimit"
"ChargeTransactionPayment"
]
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-core",
"version": "1.10.1",
"version": "1.13.1",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -26,15 +26,15 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/metadata": "1.10.1",
"@polkadot/rpc-provider": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/metadata": "1.13.1",
"@polkadot/rpc-provider": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.1"
}
}
+7 -1
View File
@@ -89,6 +89,8 @@ export default class Rpc implements RpcInterface {
public readonly engine!: RpcInterface['engine'];
public readonly grandpa!: RpcInterface['grandpa'];
public readonly offchain!: RpcInterface['offchain'];
public readonly payment!: RpcInterface['payment'];
@@ -336,7 +338,11 @@ export default class Rpc implements RpcInterface {
throw error;
}
} else if (rpc.type === 'StorageChangeSet') {
return this._formatStorageSet(params[0] as Vec<StorageKey>, result.changes);
const keys = params[0] as Vec<StorageKey>;
return keys
? this._formatStorageSet(keys, result.changes)
: this.registry.createType('StorageChangeSet', result);
} else if (rpc.type === 'Vec<StorageChangeSet>') {
const mapped = result.map(({ block, changes }: { block: string; changes: [string, string | null][] }): [Hash, Codec[]] => [
this.registry.createType('Hash', block),
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "1.10.1",
"version": "1.13.1",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
@@ -26,18 +26,18 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/metadata": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@polkadot/util-crypto": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/metadata": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"@polkadot/util-crypto": "^2.9.1",
"bn.js": "^5.1.1",
"eventemitter3": "^4.0.0",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.31"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1",
"@polkadot/keyring": "^2.9.1",
"mock-socket": "^9.0.3",
"nock": "^12.0.3"
}
+29 -16
View File
@@ -65,7 +65,7 @@ const l = logger('api-ws');
export default class WsProvider implements WSProviderInterface {
readonly #coder: Coder;
readonly #endpoint: string;
readonly #endpoints: string[];
readonly #eventemitter: EventEmitter;
@@ -75,7 +75,9 @@ export default class WsProvider implements WSProviderInterface {
readonly #waitingForId: Record<string, JsonRpcResponse> = {};
#autoConnect: boolean;
#autoConnectMs: number;
#endpointIndex: number;
#isConnected = false;
@@ -84,19 +86,28 @@ export default class WsProvider implements WSProviderInterface {
#websocket: WebSocket | null;
/**
* @param {string} endpoint The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944`
* @param {string | string[]} endpoint The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944`, may provide an array of endpoint strings.
* @param {boolean} autoConnect Whether to connect automatically or not.
*/
constructor (endpoint: string = defaults.WS_URL, autoConnect = true) {
assert(/^(wss|ws):\/\//.test(endpoint), `Endpoint should start with 'ws://', received '${endpoint}'`);
constructor (endpoint: string | string[] = defaults.WS_URL, autoConnectMs: number | false = 1000) {
const endpoints = Array.isArray(endpoint)
? endpoint
: [endpoint];
assert(endpoints.length !== 0, 'WsProvider requires at least one Endpoint');
endpoints.forEach((endpoint) => {
assert(/^(wss|ws):\/\//.test(endpoint), `Endpoint should start with 'ws://', received '${endpoint}'`);
});
this.#eventemitter = new EventEmitter();
this.#autoConnect = autoConnect;
this.#autoConnectMs = autoConnectMs || 0;
this.#coder = new Coder();
this.#endpoint = endpoint;
this.#endpointIndex = -1;
this.#endpoints = endpoints;
this.#websocket = null;
if (autoConnect) {
if (autoConnectMs > 0) {
this.connect();
}
}
@@ -112,7 +123,7 @@ export default class WsProvider implements WSProviderInterface {
* @description Returns a clone of the object
*/
public clone (): WsProvider {
return new WsProvider(this.#endpoint);
return new WsProvider(this.#endpoints);
}
/**
@@ -122,9 +133,11 @@ export default class WsProvider implements WSProviderInterface {
*/
public async connect (): Promise<void> {
try {
this.#endpointIndex = (this.#endpointIndex + 1) % this.#endpoints.length;
const WS = await getWSClass();
this.#websocket = new WS(this.#endpoint);
this.#websocket = new WS(this.#endpoints[this.#endpointIndex]);
this.#websocket.onclose = this.#onSocketClose;
this.#websocket.onerror = this.#onSocketError;
this.#websocket.onmessage = this.#onSocketMessage;
@@ -143,7 +156,7 @@ export default class WsProvider implements WSProviderInterface {
}
// switch off autoConnect, we are in manual mode now
this.#autoConnect = false;
this.#autoConnectMs = 0;
// 1000 - Normal closure; the connection successfully completed
this.#websocket.close(1000);
@@ -267,17 +280,17 @@ export default class WsProvider implements WSProviderInterface {
}
#onSocketClose = (event: CloseEvent): void => {
if (this.#autoConnect) {
l.error(`disconnected from ${this.#endpoint} code: '${event.code}' reason: '${event.reason}'`);
if (this.#autoConnectMs > 0) {
l.error(`disconnected from ${this.#endpoints[this.#endpointIndex]} code: '${event.code}' reason: '${event.reason}'`);
}
this.#isConnected = false;
this.#emit('disconnected');
if (this.#autoConnect) {
if (this.#autoConnectMs > 0) {
setTimeout((): void => {
this.connect();
}, 1000);
}, this.#autoConnectMs);
}
}
@@ -363,7 +376,7 @@ export default class WsProvider implements WSProviderInterface {
#onSocketOpen = (): boolean => {
assert(!isNull(this.#websocket), 'WebSocket cannot be null in onOpen');
l.debug((): any[] => ['connected to', this.#endpoint]);
l.debug((): any[] => ['connected to', this.#endpoints[this.#endpointIndex]]);
this.#isConnected = true;
+103 -12
View File
@@ -6,38 +6,129 @@ import WsProvider from './';
import { Mock } from './../mock/types';
import { mockWs, TEST_WS_URL } from '../../test/mockWs';
function sleepMs (ms = 0): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
describe('onConnect', (): void => {
let mock: Mock;
let mocks: Mock[];
beforeEach((): void => {
mock = mockWs([]);
jest.setTimeout(30000);
mocks = [mockWs([])];
});
afterEach((): void => {
if (mock) {
mock.done();
}
jest.setTimeout(5000);
mocks.forEach((m) => {
if (m) {
m.done();
}
});
});
it('Does not connect when autoConnect is false', (): void => {
const provider: WsProvider = new WsProvider(TEST_WS_URL, false);
const provider: WsProvider = new WsProvider(TEST_WS_URL, 0);
expect(provider.isConnected()).toBe(false);
});
it('Does connect when autoConnect is true', (): void => {
const provider: WsProvider = new WsProvider(TEST_WS_URL, true);
it('Does connect when autoConnect is true', async () => {
const provider: WsProvider = new WsProvider(TEST_WS_URL, 1);
expect(provider.isConnected()).not.toBe(true);
await sleepMs(100); // Hack to give the provider time to connect
expect(provider.isConnected()).toBe(true);
});
it('Creates a new WebSocket instance by calling the connect() method', (): void => {
it('Creates a new WebSocket instance by calling the connect() method', async () => {
const provider: WsProvider = new WsProvider(TEST_WS_URL, false);
expect(provider.isConnected()).toBe(false);
expect(mocks[0].server.clients().length).toBe(0);
provider.connect();
await provider.connect();
await sleepMs(100); // Hack to give the provider time to connect
expect(provider.isConnected()).not.toBe(true);
expect(provider.isConnected()).toBe(true);
expect(mocks[0].server.clients().length).toBe(1);
});
it('Connects to first endpoint when an array is given', async () => {
const provider: WsProvider = new WsProvider([TEST_WS_URL], 1);
await provider.connect();
await sleepMs(100); // Hack to give the provider time to connect
expect(provider.isConnected()).toBe(true);
});
it('Connects to the second endpoint when the first is unreachable', async () => {
/* eslint-disable @typescript-eslint/no-empty-function */
jest.spyOn(console, 'error').mockImplementation((): void => {});
const endpoints: string[] = ['ws://localhost:9956', TEST_WS_URL];
const provider: WsProvider = new WsProvider(endpoints, 1);
await sleepMs(100); // Hack to give the provider time to connect
expect(provider.isConnected()).toBe(true);
});
it('Connects to the second endpoint when the first is dropped', async () => {
const endpoints: string[] = [TEST_WS_URL, 'ws://localhost:9957'];
mocks.push(mockWs([], endpoints[1]));
const provider: WsProvider = new WsProvider(endpoints, 1);
await sleepMs(100); // Hack to give the provider time to connect
// Check that first server is connected
expect(mocks[0].server.clients().length).toBe(1);
expect(mocks[1].server.clients().length).toBe(0);
// Close connection from first server
mocks[0].server.clients()[0].close();
await sleepMs(100);
// Check that second server is connected
expect(mocks[1].server.clients().length).toBe(1);
expect(provider.isConnected()).toBe(true);
});
it('Round-robin of endpoints on WsProvider', async () => {
const rounds = 5;
const endpoints: string[] = [
TEST_WS_URL,
'ws://localhost:9956',
'ws://localhost:9957',
'ws://invalid:9956',
'ws://localhost:9958'
];
mocks.push(mockWs([], endpoints[1]));
mocks.push(mockWs([], endpoints[2]));
mocks.push(mockWs([], endpoints[4]));
const mockNext = [
mocks[1],
mocks[2],
mocks[3],
mocks[0]
];
const provider: WsProvider = new WsProvider(endpoints, 1);
for (let round = 0; round < rounds; round++) {
for (let index = 0; index < mocks.length; index++) {
await sleepMs(100); // Hack to give the provider time to connect
// Check that first server is connected and the next one isn't
expect(mocks[index].server.clients().length).toBe(1);
expect(mockNext[index].server.clients().length).toBe(0);
expect(provider.isConnected()).toBe(true);
// Close connection from first server
mocks[index].server.clients()[0].close();
}
}
});
});
+41 -2
View File
@@ -9,7 +9,7 @@ import { mockWs, TEST_WS_URL } from '../../test/mockWs';
let ws: WsProvider;
let mock: Mock;
function createWs (requests: any[], autoConnect: boolean | undefined): WsProvider {
function createWs (requests: any[], autoConnect: number | undefined = 1000): WsProvider {
mock = mockWs(requests);
ws = new WsProvider(TEST_WS_URL, autoConnect);
@@ -25,7 +25,46 @@ describe('Ws', (): void => {
it('returns the connected state', (): void => {
expect(
createWs([], true).isConnected()
createWs([]).isConnected()
).toEqual(false);
});
});
describe('Endpoint Parsing', (): void => {
it('Succeeds when WsProvider endpoint is a valid string', () => {
/* eslint-disable no-new */
new WsProvider(TEST_WS_URL, 0);
});
it('Throws when WsProvider endpoint is an invalid string', () => {
expect(() => {
/* eslint-disable no-new */
new WsProvider('http://127.0.0.1:9955', 0);
}).toThrowError(/^Endpoint should start with /);
});
it('Succeeds when WsProvider endpoint is a valid array', () => {
const endpoints: string[] = ['ws://127.0.0.1:9955', 'wss://testnet.io:9944', 'ws://mychain.com:9933'];
/* eslint-disable no-new */
new WsProvider(endpoints, 0);
});
it('Throws when WsProvider endpoint is an empty array', () => {
const endpoints: string[] = [];
expect(() => {
/* eslint-disable no-new */
new WsProvider(endpoints, 0);
}).toThrowError('WsProvider requires at least one Endpoint');
});
it('Throws when WsProvider endpoint is an invalid array', () => {
const endpoints: string[] = ['ws://127.0.0.1:9955', 'http://bad.co:9944', 'ws://mychain.com:9933'];
expect(() => {
/* eslint-disable no-new */
new WsProvider(endpoints, 0);
}).toThrowError(/^Endpoint should start with /);
});
});
+2 -2
View File
@@ -9,7 +9,7 @@ import { mockWs, TEST_WS_URL } from '../../test/mockWs';
let ws: WsProvider;
let mock: Mock;
function createWs (requests: any[], autoConnect: boolean | undefined): WsProvider {
function createWs (requests: any[], autoConnect: number | undefined = 1000): WsProvider {
mock = mockWs(requests);
ws = new WsProvider(TEST_WS_URL, autoConnect);
@@ -30,7 +30,7 @@ describe('onOpen', (): void => {
reply: {
result: 'ok'
}
}], false);
}], 0);
const sendPromise = ws.send('test_queue', []);
ws.connect();
+5 -5
View File
@@ -17,7 +17,7 @@ function createMock (requests: any[]): void {
mock = mockWs(requests);
}
function createWs (autoConnect = true): WsProvider {
function createWs (autoConnect = 1000): WsProvider {
provider = new WsProvider(TEST_WS_URL, autoConnect);
return provider;
@@ -47,7 +47,7 @@ describe('send', (): void => {
}
}]);
return createWs(true)
return createWs()
.send('test_encoding', [{ error: 'send error' }])
.catch((error): void => {
expect(error.message).toEqual('send error');
@@ -63,7 +63,7 @@ describe('send', (): void => {
}
}]);
return createWs(true)
return createWs()
.send('test_body', ['param'])
.then((): void => {
expect(
@@ -81,7 +81,7 @@ describe('send', (): void => {
id: 1
}]);
return createWs(true)
return createWs()
.send('test_error', [])
.catch((error): void => {
expect(error.message).toMatch(/666: error/);
@@ -97,7 +97,7 @@ describe('send', (): void => {
}
}]);
return createWs(true)
return createWs()
.send('test_sub', [])
.then((id): void => {
expect(id).toEqual(1);
+2 -2
View File
@@ -7,13 +7,13 @@ import WsProvider from './';
describe('state', (): void => {
it('requires an ws:// prefixed endpoint', (): void => {
expect(
(): WsProvider => new WsProvider('http://', false)
(): WsProvider => new WsProvider('http://', 0)
).toThrow(/with 'ws/);
});
it('allows wss:// endpoints', (): void => {
expect(
(): WsProvider => new WsProvider('wss://', false)
(): WsProvider => new WsProvider('wss://', 0)
).not.toThrow();
});
});
@@ -17,7 +17,7 @@ function createMock (requests: any[]): void {
mock = mockWs(requests);
}
function createWs (autoConnect = true): WsProvider {
function createWs (autoConnect = 1000): WsProvider {
ws = new WsProvider(TEST_WS_URL, autoConnect);
return ws;
@@ -47,7 +47,7 @@ describe('subscribe', (): void => {
}
}]);
return createWs(true)
return createWs()
.subscribe('type', 'test_sub', [], (cb): void => {
expect(cb).toEqual(expect.anything());
})
@@ -17,7 +17,7 @@ function createMock (requests: any): void {
mock = mockWs(requests);
}
function createWs (autoConnect = true): WsProvider {
function createWs (autoConnect = 1000): WsProvider {
ws = new WsProvider(TEST_WS_URL, autoConnect);
return ws;
@@ -56,7 +56,7 @@ describe('subscribe', (): void => {
}
]);
const ws = createWs(true);
const ws = createWs();
return ws
.subscribe('test', 'subscribe_test', [], (cb): void => {
@@ -76,7 +76,7 @@ describe('subscribe', (): void => {
}
}]);
const ws = createWs(true);
const ws = createWs();
return ws
.subscribe('test', 'subscribe_test', [], (cb): void => {
+2 -4
View File
@@ -6,8 +6,6 @@ import { Server } from 'mock-socket';
const TEST_WS_URL = 'ws://localhost:9955';
let server: Server;
interface Scope {
body: { [index: string]: {} };
requests: number;
@@ -52,8 +50,8 @@ function createReply ({ id, reply: { result } }: ReplyDef): any {
}
// scope definition returned
function mockWs (requests: { method: string }[]): Scope {
server = new Server(TEST_WS_URL);
function mockWs (requests: { method: string }[], wsUrl: string = TEST_WS_URL): Scope {
const server = new Server(wsUrl);
let requestCount = 0;
const scope: Scope = {
+9 -8
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "1.10.1",
"version": "1.13.1",
"description": "Type generation scripts",
"main": "index.js",
"bin": {
@@ -33,14 +33,15 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
"dependencies": {
"@babel/core": "^7.9.0",
"@babel/core": "^7.9.6",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@polkadot/api": "1.10.1",
"@polkadot/metadata": "1.10.1",
"@polkadot/rpc-provider": "1.10.1",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/api": "1.13.1",
"@polkadot/metadata": "1.13.1",
"@polkadot/rpc-provider": "1.13.1",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"handlebars": "^4.7.6",
"websocket": "^1.0.31",
"yargs": "^15.3.1"
},
+40 -39
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata';
import Handlebars from 'handlebars';
import staticData from '@polkadot/metadata/Metadata/static';
import Metadata from '@polkadot/metadata/Metadata';
@@ -10,29 +10,10 @@ import { TypeRegistry } from '@polkadot/types/create';
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
import { stringCamelCase } from '@polkadot/util';
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, indent, registerDefinitions, setImports, writeFile } from '../util';
import { createImports, compareName, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
// Generate types for one module
/** @internal */
function generateModule (allDefs: object, { constants, name }: ModuleMetadataLatest, imports: TypeImports, isStrict: boolean): string[] {
if (!constants.length) {
return [];
}
if (!isStrict) {
setImports(allDefs, imports, ['Codec']);
}
return [indent(4)(`${stringCamelCase(name.toString())}: {`)]
.concat(isStrict ? '' : indent(6)('[index: string]: AugmentedConst<object & Codec>;'))
.concat(constants.sort((a, b) => a.name.localeCompare(b.name.toString())).map(({ documentation, name, type }): string => {
setImports(allDefs, imports, [type.toString()]);
return createDocComments(6, documentation) +
indent(6)(`${stringCamelCase(name.toString())}: AugmentedConst<${type}>;`);
}))
.concat([indent(4)('};')]);
}
const template = readTemplate('consts');
const generateForMetaTemplate = Handlebars.compile(template);
/** @internal */
function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<string, Record<string, { types: Record<string, any> }>>, isStrict: boolean): void {
@@ -42,27 +23,47 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<strin
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
}, {});
const body = meta.asLatest.modules.sort((a, b) => a.name.localeCompare(b.name.toString())).reduce((acc, mod): string[] => {
return acc.concat(generateModule(allDefs, mod, imports, isStrict));
}, [] as string[]);
const header = createImportCode(HEADER('chain'), imports, [
const modules = meta.asLatest.modules
.sort(compareName)
.filter((mod) => mod.constants.length > 0)
.map(({ constants, name }) => {
if (!isStrict) {
setImports(allDefs, imports, ['Codec']);
}
const items = constants
.sort(compareName)
.map(({ documentation, name, type }) => {
setImports(allDefs, imports, [type.toString()]);
return {
docs: documentation,
name: stringCamelCase(name.toString()),
type: type.toString()
};
});
return {
items,
name: stringCamelCase(name.toString())
};
});
const types = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
}))
]);
const interfaceStart = [
"declare module '@polkadot/metadata/Decorated/consts/types' {",
indent(2)('export interface Constants {\n')
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n}`;
];
return header
.concat(interfaceStart)
.concat(isStrict ? '' : indent(4)('[index: string]: ModuleConstants;\n'))
.concat(body.join('\n'))
.concat(interfaceEnd)
.concat(FOOTER);
return generateForMetaTemplate({
headerType: 'chain',
imports,
isStrict,
modules,
types
});
});
}
@@ -2,17 +2,22 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Handlebars from 'handlebars';
import Raw from '@polkadot/types/codec/Raw';
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
import * as defaultPrimitives from '@polkadot/types/primitive';
import { FOOTER, HEADER, createImportCode, createImports, getDerivedTypes, indent, setImports, writeFile } from '../util';
import { createImports, getDerivedTypes, readTemplate, setImports, writeFile } from '../util';
const primitiveClasses = {
...defaultPrimitives,
Raw
};
const template = readTemplate('interfaceRegistry');
const generateInterfaceTypesTemplate = Handlebars.compile(template);
/** @internal */
export function generateInterfaceTypes (importDefinitions: { [importPath: string]: object }, dest: string): void {
writeFile(dest, (): string => {
@@ -20,46 +25,44 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string
const imports = createImports(importDefinitions);
const definitions = imports.definitions;
const primitives = Object
const items: string[] = [];
Object
.keys(primitiveClasses)
.filter((name): boolean => !!name.indexOf('Generic'))
.reduce((accumulator, primitiveName): string => {
.forEach((primitiveName) => {
setImports(definitions, imports, [primitiveName]);
return [
accumulator,
getDerivedTypes(definitions, primitiveName, primitiveName, imports).map(indent(4)).join('\n')
].join('\n');
}, '');
items.push(...getDerivedTypes(definitions, primitiveName, primitiveName, imports));
});
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const srml = Object.entries(definitions).reduce((accumulator, [_defName, { types }]): string => {
const existingTypes: Record<string, boolean> = {};
Object.entries(definitions).forEach(([, { types }]) => {
setImports(definitions, imports, Object.keys(types));
return [
accumulator,
...Object.keys(types).map((type): string =>
getDerivedTypes(definitions, type, types[type], imports).map(indent(4)).join('\n')
)
].join('\n');
}, '');
const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]);
const header = createImportCode(HEADER('defs'), imports, [
uniqueTypes.forEach((type) => {
existingTypes[type] = true;
items.push(...getDerivedTypes(definitions, type, types[type], imports));
});
});
const types = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
}))
]);
];
const interfaceStart = "declare module '@polkadot/types/types/registry' {\n export interface InterfaceTypes {";
const interfaceEnd = '\n }\n}';
return header
.concat(interfaceStart)
.concat(primitives)
.concat(srml)
.concat(interfaceEnd)
.concat(FOOTER);
return generateInterfaceTypesTemplate({
headerType: 'defs',
imports,
items,
types
});
});
}
+48 -50
View File
@@ -2,7 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ModuleMetadataLatest, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import Handlebars from 'handlebars';
import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import staticData from '@polkadot/metadata/Metadata/static';
@@ -10,9 +12,9 @@ import Metadata from '@polkadot/metadata/Metadata';
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { TypeRegistry } from '@polkadot/types/create';
import { stringLowerFirst } from '@polkadot/util';
import { stringCamelCase } from '@polkadot/util';
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, formatType, getSimilarTypes, indent, registerDefinitions, setImports, writeFile } from '../util';
import { TypeImports, createImports, compareName, formatType, getSimilarTypes, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
// From a storage entry metadata, we return [args, returnType]
/** @internal */
@@ -60,28 +62,8 @@ function entrySignature (allDefs: object, registry: Registry, storageEntry: Stor
throw new Error(`entryArgs: Cannot parse args of entry ${storageEntry.name}`);
}
// Generate types for one module
/** @internal */
function generateModule (allDefs: object, registry: Registry, { name, storage }: ModuleMetadataLatest, imports: TypeImports, isStrict: boolean): string[] {
if (storage.isNone) {
return [];
}
return [indent(4)(`${stringLowerFirst(name.toString())}: {`)]
.concat(isStrict ? '' : indent(6)('[index: string]: QueryableStorageEntry<ApiType>;'))
.concat(storage.unwrap().items.sort((a, b) => a.name.localeCompare(b.name.toString())).map((storageEntry): string => {
const [args, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
let entryType = 'AugmentedQuery';
if (storageEntry.type.isDoubleMap) {
entryType = `${entryType}DoubleMap`;
}
return createDocComments(6, storageEntry.documentation) +
indent(6)(`${stringLowerFirst(storageEntry.name.toString())}: ${entryType}<ApiType, (${args}) => Observable<${returnType}>>${isStrict ? '' : ' & QueryableStorageEntry<ApiType>'};`);
}))
.concat([indent(4)('};')]);
}
const template = readTemplate('query');
const generateForMetaTemplate = Handlebars.compile(template);
/** @internal */
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: Record<string, Record<string, { types: Record<string, any> }>>, isStrict: boolean): void {
@@ -91,40 +73,56 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
}, {});
const body = meta.asLatest.modules.sort((a, b) => a.name.localeCompare(b.name.toString())).reduce((acc: string[], mod): string[] => {
return acc.concat(generateModule(allDefs, registry, mod, imports, isStrict));
}, []);
const header = createImportCode(HEADER('chain'), imports, [
const modules = meta.asLatest.modules
.sort(compareName)
.filter((mod) => !mod.storage.isNone)
.map(({ name, storage }) => {
const items = storage.unwrap().items
.sort(compareName)
.map((storageEntry) => {
const [args, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
let entryType = 'AugmentedQuery';
if (storageEntry.type.isDoubleMap) {
entryType = `${entryType}DoubleMap`;
}
return {
args,
docs: storageEntry.documentation,
entryType,
name: stringCamelCase(storageEntry.name.toString()),
returnType
};
});
return {
items,
name: stringCamelCase(name.toString())
};
});
imports.typesTypes.Observable = true;
const types = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
})),
{
file: 'rxjs',
types: ['Observable']
},
{
file: '@polkadot/api/types',
types: ['ApiTypes']
}
]);
const interfaceStart = [
"declare module '@polkadot/api/types/storage' {",
indent(2)('export interface AugmentedQueries<ApiType> {\n')
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n\n`;
const queryableStorageInterface = indent(2)('export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {')
.concat('\n')
.concat(isStrict ? '' : indent(4)('[index: string]: QueryableModuleStorage<ApiType>;\n'))
.concat(indent(2)('}\n'));
];
return header
.concat(interfaceStart)
.concat(body.join('\n'))
.concat(interfaceEnd)
.concat(queryableStorageInterface)
.concat('}')
.concat(FOOTER);
return generateForMetaTemplate({
headerType: 'chain',
imports,
isStrict,
modules,
types
});
});
}
+57 -36
View File
@@ -2,13 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Handlebars from 'handlebars';
import { TypeRegistry } from '@polkadot/types/create';
import * as definitions from '@polkadot/types/interfaces/definitions';
import { FOOTER, HEADER, createDocComments, createImportCode, createImports, getSimilarTypes, setImports, writeFile, indent } from '../util';
import { createImports, getSimilarTypes, readTemplate, setImports, writeFile } from '../util';
const StorageKeyTye = 'StorageKey | string | Uint8Array | any';
const template = readTemplate('rpc');
const generateRpcTypesTemplate = Handlebars.compile(template);
/** @internal */
export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.ts'): void {
writeFile(dest, (): string => {
@@ -22,64 +27,80 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t
.keys(definitions)
.filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0)
.sort();
const body = rpcKeys.reduce<string[]>((allSections, section): string[] => {
const allMethods = Object.keys(definitions[section as 'babe'].rpc).sort().map((methodName): string => {
const modules = rpcKeys.map((section) => {
const allMethods = Object.keys(definitions[section as 'babe'].rpc).sort().map((methodName) => {
const def = definitions[section as 'babe'].rpc[methodName];
let args;
let type;
let generic;
// These are too hard to type with generics, do manual overrides
if (section === 'state') {
setImports(allDefs, imports, ['Codec', 'Hash', 'StorageKey', 'Vec']);
if (methodName === 'getStorage') {
return createDocComments(6, [def.description]) + indent(6)(`getStorage: AugmentedRpc<<T = Codec>(key: ${StorageKeyTye}, block?: Hash | Uint8Array | string) => Observable<T>>;`);
generic = 'T = Codec';
args = [`key: ${StorageKeyTye}, block?: Hash | Uint8Array | string`];
type = 'T';
} else if (methodName === 'queryStorage') {
return createDocComments(6, [def.description]) + indent(6)(`queryStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;`);
generic = 'T = Codec[]';
args = [`keys: Vec<StorageKey> | (${StorageKeyTye})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string`];
type = '[Hash, T][]';
} else if (methodName === 'queryStorageAt') {
return createDocComments(6, [def.description]) + indent(6)(`queryStorageAt: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[], at?: Hash | Uint8Array | string) => Observable<T>>;`);
generic = 'T = Codec[]';
args = [`keys: Vec<StorageKey> | (${StorageKeyTye})[], at?: Hash | Uint8Array | string`];
type = 'T';
} else if (methodName === 'subscribeStorage') {
return createDocComments(6, [def.description]) + indent(6)(`subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[]) => Observable<T>>;`);
generic = 'T = Codec[]';
args = [`keys?: Vec<StorageKey> | (${StorageKeyTye})[]`];
type = 'T';
}
}
setImports(allDefs, imports, [def.type]);
if (args === undefined) {
setImports(allDefs, imports, [def.type]);
args = def.params.map((param: any) => {
const similarTypes = getSimilarTypes(definitions, registry, param.type, imports);
const args = def.params.map((param: any): string => {
const similarTypes = getSimilarTypes(definitions, registry, param.type, imports);
setImports(allDefs, imports, [param.type, ...similarTypes]);
setImports(allDefs, imports, [param.type, ...similarTypes]);
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
});
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
});
type = def.type;
generic = '';
}
return createDocComments(6, [def.description]) + indent(6)(`${methodName}: AugmentedRpc<(${args.join(', ')}) => Observable<${def.type}>>;`);
return {
args: args.join(', '),
docs: [def.description],
generic,
name: methodName,
type
};
});
return allSections.concat(
[
` ${section}: {`,
...allMethods,
' };'
].join('\n')
);
}, []).join('\n');
return {
items: allMethods,
name: section
};
});
const header = createImportCode(HEADER('chain'), imports, [
imports.typesTypes.Observable = true;
const types = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
})),
{
file: 'rxjs',
types: ['Observable']
}
]);
const interfaceStart = "declare module '@polkadot/rpc-core/types.jsonrpc' {\n export interface RpcInterface {\n";
const interfaceEnd = '\n }\n}';
}))
];
return header
.concat(interfaceStart)
.concat(body)
.concat(interfaceEnd)
.concat(FOOTER);
return generateRpcTypesTemplate({
headerType: 'chain',
imports,
modules,
types
});
});
}
+30 -15
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Handlebars from 'handlebars';
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
import path from 'path';
@@ -9,7 +11,7 @@ import { getTypeDef } from '@polkadot/types/create';
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
import { isString, stringCamelCase, stringUpperFirst } from '@polkadot/util';
import { FOOTER, HEADER, TypeImports, createImportCode, createImports, exportInterface, exportType, formatType, setImports, writeFile } from '../util';
import { TypeImports, createImports, exportInterface, exportType, readTemplate, formatType, setImports, writeFile } from '../util';
interface Imports extends TypeImports {
interfaces: [string, string][];
@@ -37,6 +39,7 @@ function tsExport (definitions: object, def: TypeDef, imports: TypeImports): str
const tsBTreeMap = tsExport;
const tsBTreeSet = tsExport;
const tsCompact = tsExport;
const tsDoNotConstruct = tsExport;
const tsHashMap = tsExport;
const tsOption = tsExport;
const tsPlain = tsExport;
@@ -156,6 +159,7 @@ function generateInterfaces (definitions: object, { types }: { types: Record<str
[TypeDefInfo.BTreeMap]: tsBTreeMap,
[TypeDefInfo.BTreeSet]: tsBTreeSet,
[TypeDefInfo.Compact]: tsCompact,
[TypeDefInfo.DoNotConstruct]: tsDoNotConstruct,
[TypeDefInfo.Enum]: tsEnum,
[TypeDefInfo.HashMap]: tsHashMap,
[TypeDefInfo.Int]: tsInt,
@@ -179,22 +183,37 @@ function generateInterfaces (definitions: object, { types }: { types: Record<str
});
}
const templateIndex = readTemplate('tsDef/index');
const generateTsDefIndexTemplate = Handlebars.compile(templateIndex);
const templateModuleTypes = readTemplate('tsDef/moduleTypes');
const generateTsDefModuleTypesTemplate = Handlebars.compile(templateModuleTypes);
const templateTypes = readTemplate('tsDef/types');
const generateTsDefTypesTemplate = Handlebars.compile(templateTypes);
/** @internal */
function generateTsDefFor (importDefinitions: { [importPath: string]: object }, defName: string, { types }: { types: Record<string, any> }, outputDir: string): void {
const imports = { ...createImports(importDefinitions, { types }), interfaces: [] } as Imports;
const definitions = imports.definitions;
const interfaces = generateInterfaces(definitions, { types }, imports);
const sortedDefs = interfaces.sort((a, b): number => a[0].localeCompare(b[0])).map(([, definition]): string => definition).join('\n\n');
const items = interfaces.sort((a, b): number => a[0].localeCompare(b[0])).map(([, definition]): string => definition);
const header = createImportCode(HEADER('defs'), imports, [
const importTypes = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
}))
]);
];
writeFile(path.join(outputDir, defName, 'types.ts'), () => header.concat(sortedDefs).concat(`\n\nexport type PHANTOM_${defName.toUpperCase()} = '${defName}';`).concat(FOOTER), true);
writeFile(path.join(outputDir, defName, 'index.ts'), () => HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), true);
writeFile(path.join(outputDir, defName, 'types.ts'), () => generateTsDefModuleTypesTemplate({
headerType: 'defs',
imports,
items,
name: defName,
types: importTypes
}), true);
writeFile(path.join(outputDir, defName, 'index.ts'), () => generateTsDefIndexTemplate({ headerType: 'defs' }), true);
}
/** @internal */
@@ -208,17 +227,13 @@ export function generateTsDef (importDefinitions: { [importPath: string]: object
generateTsDefFor(importDefinitions, defName, obj, outputDir);
});
return HEADER('defs')
.concat(
Object
.keys(definitions)
.map((moduleName): string => `export * from './${moduleName}/types';`)
.join('\n')
)
.concat(FOOTER);
return generateTsDefTypesTemplate({
headerType: 'defs',
items: Object.keys(definitions)
});
});
writeFile(path.join(outputDir, 'index.ts'), () => HEADER('defs').concat('export * from \'./types\';').concat(FOOTER), true);
writeFile(path.join(outputDir, 'index.ts'), () => generateTsDefIndexTemplate({ headerType: 'defs' }), true);
}
/** @internal */
+49 -57
View File
@@ -2,7 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata';
import Handlebars from 'handlebars';
import { Registry } from '@polkadot/types/types';
import staticData from '@polkadot/metadata/Metadata/static';
@@ -12,7 +13,7 @@ import { Text } from '@polkadot/types/primitive';
import { TypeRegistry } from '@polkadot/types/create';
import { stringCamelCase } from '@polkadot/util';
import { FOOTER, HEADER, TypeImports, createDocComments, createImportCode, createImports, formatType, getSimilarTypes, indent, registerDefinitions, setImports, writeFile } from '../util';
import { createImports, compareName, formatType, getSimilarTypes, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
const MAPPED_NAMES: Record<string, string> = {
new: 'updated'
@@ -24,39 +25,8 @@ function mapName (_name: Text): string {
return MAPPED_NAMES[name] || name;
}
// Generate types for one module
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function generateModule (registry: Registry, allDefs: object, { calls, name }: ModuleMetadataLatest, imports: TypeImports, isStrict: boolean): string[] {
const allCalls = calls.unwrapOr(null);
if (!allCalls?.length) {
return [];
}
setImports(allDefs, imports, ['Call', 'Extrinsic', 'SubmittableExtrinsic']);
return [indent(4)(`${stringCamelCase(name.toString())}: {`)]
.concat(isStrict ? '' : indent(6)('[index: string]: SubmittableExtrinsicFunction<ApiType>;'))
.concat(allCalls.sort((a, b) => a.name.localeCompare(b.name.toString())).map(({ args, documentation, name }): string => {
const params = args
.map(({ name, type }): [string, string, string] => {
const typeStr = type.toString();
const similarTypes = getSimilarTypes(allDefs, registry, typeStr, imports).map((type): string => formatType(allDefs, type, imports));
const nameStr = mapName(name);
setImports(allDefs, imports, [...similarTypes.filter((type): boolean => !type.startsWith('(') && !type.startsWith('{')), typeStr]);
return [`${nameStr}: ${similarTypes.join(' | ')}`, nameStr, typeStr];
})
.map(([full]): string => full)
.join(', ');
return createDocComments(6, documentation) +
indent(6)(`${stringCamelCase(name.toString())}: AugmentedSubmittable<(${params}) => SubmittableExtrinsic<ApiType>>;`);
}))
.concat([indent(4)('};')]);
}
const template = readTemplate('tx');
const generateForMetaTemplate = Handlebars.compile(template);
/** @internal */
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: Record<string, Record<string, { types: Record<string, any> }>>, isStrict: boolean): void {
@@ -66,10 +36,42 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
}, {});
const body = meta.asLatest.modules.sort((a, b) => a.name.localeCompare(b.name.toString())).reduce((acc, mod): string[] => {
return acc.concat(generateModule(registry, allDefs, mod, imports, isStrict));
}, [] as string[]);
const header = createImportCode(HEADER('chain'), imports, [
const modules = meta.asLatest.modules
.sort(compareName)
.filter(({ calls }) => calls.unwrapOr([]).length)
.map(({ calls, name }) => {
setImports(allDefs, imports, ['Call', 'Extrinsic', 'SubmittableExtrinsic']);
const items = calls.unwrap()
.sort(compareName)
.map(({ args, documentation, name }) => {
const params = args
.map(({ name, type }) => {
const typeStr = type.toString();
const similarTypes = getSimilarTypes(allDefs, registry, typeStr, imports).map((type): string => formatType(allDefs, type, imports));
const nameStr = mapName(name);
setImports(allDefs, imports, [...similarTypes.filter((type): boolean => !type.startsWith('(') && !type.startsWith('{')), typeStr]);
return `${nameStr}: ${similarTypes.join(' | ')}`;
})
.join(', ');
return {
docs: documentation,
name: stringCamelCase(name.toString()),
params
};
});
return {
items,
name: stringCamelCase(name.toString())
};
});
const types = [
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
file: packagePath,
types: Object.keys(imports.localTypes[packagePath])
@@ -78,25 +80,15 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
file: '@polkadot/api/types',
types: ['ApiTypes', 'SubmittableExtrinsic']
}
]);
const interfaceStart = [
"declare module '@polkadot/api/types/submittable' {",
indent(2)('export interface AugmentedSubmittables<ApiType> {\n')
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n\n`;
const submittableExtrinsicsInterface = indent(2)('export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {')
.concat('\n')
.concat(indent(4)('(extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;\n'))
.concat(isStrict ? '' : indent(4)('[index: string]: SubmittableModuleExtrinsics<ApiType>;\n'))
.concat(indent(2)('}\n'));
];
return header
.concat(interfaceStart)
.concat(body.join('\n'))
.concat(interfaceEnd)
.concat(submittableExtrinsicsInterface)
.concat('}')
.concat(FOOTER);
return generateForMetaTemplate({
headerType: 'chain',
imports,
isStrict,
modules,
types
});
});
}
+23
View File
@@ -0,0 +1,23 @@
{{> header }}
{{{ imports }}}
declare module '@polkadot/metadata/Decorated/consts/types' {
export interface Constants {
{{#unless isStrict}}
[index: string]: ModuleConstants;
{{/unless}}
{{#each modules}}
{{{name}}}: {
{{#unless @root.isStrict}}
[index: string]: AugmentedConst<object & Codec>;
{{/unless}}
{{~#each items}}
{{> docs}}
{{{name}}}: AugmentedConst<{{{type}}}>;
{{/each}}
};
{{/each}}
}
}
{{> footer }}
+7
View File
@@ -0,0 +1,7 @@
{{#if docs.length}}
/**
{{#each docs}}
* {{#trim}}{{{this}}}{{/trim}}
{{/each}}
**/
{{/if}}
@@ -0,0 +1,2 @@
// Auto-generated via `yarn polkadot-types-from-{{headerType}}`, do not edit
/* eslint-disable */
@@ -0,0 +1,12 @@
{{> header }}
{{{ imports }}}
declare module '@polkadot/types/types/registry' {
export interface InterfaceTypes {
{{#each items}}
{{{this}}}
{{/each}}
}
}
{{> footer }}
+26
View File
@@ -0,0 +1,26 @@
{{> header }}
{{{ imports }}}
declare module '@polkadot/api/types/storage' {
export interface AugmentedQueries<ApiType> {
{{#each modules}}
{{{name}}}: {
{{#unless @root.isStrict}}
[index: string]: QueryableStorageEntry<ApiType>;
{{/unless}}
{{~#each items}}
{{> docs}}
{{{name}}}: {{{entryType}}}<ApiType, ({{{args}}}) => Observable<{{{returnType}}}>>{{#unless @root.isStrict}} & QueryableStorageEntry<ApiType>{{/unless}};
{{/each}}
};
{{/each}}
}
export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
{{#unless isStrict}}
[index: string]: QueryableModuleStorage<ApiType>;
{{/unless}}
}
}
{{> footer }}
+17
View File
@@ -0,0 +1,17 @@
{{> header }}
{{{ imports }}}
declare module '@polkadot/rpc-core/types.jsonrpc' {
export interface RpcInterface {
{{#each modules}}
{{{name}}}: {
{{#each items}}
{{> docs}}
{{{name}}}: AugmentedRpc<{{#if generic}}<{{{generic}}}>{{/if}}({{{args}}}) => Observable<{{{type}}}>>;
{{/each}}
};
{{/each}}
}
}
{{> footer }}
@@ -0,0 +1,4 @@
{{> header }}
export * from './types';
{{> footer }}
@@ -0,0 +1,11 @@
{{> header }}
{{{ imports }}}
{{#each items}}
{{{this}}}
{{/each}}
export type PHANTOM_{{#upper}}{{{name}}}{{/upper}} = '{{{name}}}';
{{> footer }}
@@ -0,0 +1,6 @@
{{> header }}
{{#each items}}
export * from './{{{this}}}/types';
{{/each}}
{{> footer }}
+27
View File
@@ -0,0 +1,27 @@
{{> header }}
{{{ imports }}}
declare module '@polkadot/api/types/submittable' {
export interface AugmentedSubmittables<ApiType> {
{{#each modules}}
{{{name}}}: {
{{#unless @root.isStrict}}
[index: string]: SubmittableExtrinsicFunction<ApiType>;
{{/unless}}
{{~#each items}}
{{> docs}}
{{{name}}}: AugmentedSubmittable<({{{params}}}) => SubmittableExtrinsic<ApiType>>;
{{/each}}
};
{{/each}}
}
export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
(extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;
{{#unless isStrict}}
[index: string]: SubmittableModuleExtrinsics<ApiType>;
{{/unless}}
}
}
{{> footer }}
+1 -1
View File
@@ -27,7 +27,7 @@ import { formatType } from './formatting';
import { setImports, TypeImports } from './imports';
function arrayToStrType (arr: string[]): string {
return `(${arr.map((c): string => `'${c}'`).join(' | ')})`;
return `${arr.map((c): string => `'${c}'`).join(' | ')}`;
}
const voteConvictions = arrayToStrType(AllConvictions);
+5 -17
View File
@@ -2,22 +2,10 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Text } from '@polkadot/types';
import Handlebars from 'handlebars';
import { indent } from './formatting';
import { readTemplate } from './file';
type AnyString = Text | string;
type Arg = [AnyString, AnyString];
export function createDocComments (spaces: number, docs: AnyString[], args: Arg[] = []): string {
const contents = [
...docs.map((doc): string => doc.toString().trim()).filter((doc): boolean => !!doc),
...args.map(([name, type]): string => `@param ${name} ${type}`)
].map((d): string => ` * ${d}`);
return contents.length
? ['/**', ...contents, ' **/\n']
.map((s): string => indent(spaces)(s))
.join('\n')
: '';
}
Handlebars.registerPartial({
docs: Handlebars.compile(readTemplate('docs'))
});
+4
View File
@@ -19,3 +19,7 @@ export function writeFile (dest: string, generator: () => string, noLog?: boolea
!noLog && console.log('');
}
export function readTemplate (path: string): string {
return fs.readFileSync(`${__dirname}/../templates/${path}.hbs`).toString();
}
@@ -1,11 +0,0 @@
// Copyright 2017-2020 @polkadot/typegen authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { indent } from './formatting';
describe('formatting', () => {
it('should indent correctly', () => {
expect(indent(2)('foo')).toBe(' foo');
});
});
+73 -54
View File
@@ -2,59 +2,74 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Handlebars from 'handlebars';
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
import { getTypeDef } from '@polkadot/types/create';
import { paramsNotation } from '@polkadot/types/codec/utils';
import { setImports, TypeImports } from './imports';
export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
export const FOOTER = '\n';
import { readTemplate } from './file';
const TYPES_NON_PRIMITIVE = ['Metadata'];
// creates the import lines
/** @internal */
export function createImportCode (header: string, imports: TypeImports, checks: { file: string; types: string[] }[]): string {
return [
{
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
},
{
file: '@polkadot/types/codec',
types: Object
.keys(imports.codecTypes)
.filter((name): boolean => name !== 'Tuple')
},
{
file: '@polkadot/types/extrinsic',
types: Object.keys(imports.extrinsicTypes)
},
{
file: '@polkadot/types/generic',
types: Object.keys(imports.genericTypes)
},
{
file: '@polkadot/types/primitive',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => !TYPES_NON_PRIMITIVE.includes(name))
},
{
file: '@polkadot/types',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => TYPES_NON_PRIMITIVE.includes(name))
},
...checks
].reduce((result, { file, types }): string => {
return types.length
? `${result}import { ${types.sort().join(', ')} } from '${file}';\n`
: result;
}, header) + '\n';
}
export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
Handlebars.registerPartial({
footer: Handlebars.compile(readTemplate('footer')),
header: Handlebars.compile(readTemplate('header'))
});
Handlebars.registerHelper({
imports () {
const { imports, types } = this as any;
return [
{
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
},
{
file: '@polkadot/types/codec',
types: Object
.keys(imports.codecTypes)
.filter((name): boolean => name !== 'Tuple')
},
{
file: '@polkadot/types/extrinsic',
types: Object.keys(imports.extrinsicTypes)
},
{
file: '@polkadot/types/generic',
types: Object.keys(imports.genericTypes)
},
{
file: '@polkadot/types/primitive',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => !TYPES_NON_PRIMITIVE.includes(name))
},
{
file: '@polkadot/types',
types: Object
.keys(imports.primitiveTypes)
.filter((name): boolean => TYPES_NON_PRIMITIVE.includes(name))
},
...types
].reduce((result, { file, types }): string => {
return types.length
? `${result}import { ${types.sort().join(', ')} } from '${file}';\n`
: result;
}, '');
},
trim (options) {
return options.fn(this).trim();
},
upper (options) {
return options.fn(this).toUpperCase();
}
});
// helper to generate a `export interface <Name> extends <Base> {<Body>}
/** @internal */
@@ -97,6 +112,14 @@ function formatCompact (inner: string): string {
return paramsNotation('Compact', inner);
}
/**
* Simple return
*/
/** @internal */
function formatDoNoConstruct (): string {
return 'DoNotConstruct';
}
/**
* Given the inner `K` & `V`, return a `BTreeMap<K, V>` string
*/
@@ -174,6 +197,12 @@ export function formatType (definitions: object, type: string | TypeDef, imports
return formatCompact(formatType(definitions, (typeDef.sub as TypeDef).type, imports));
}
case TypeDefInfo.DoNotConstruct: {
setImports(definitions, imports, ['DoNotConstruct']);
return formatDoNoConstruct();
}
case TypeDefInfo.Option: {
setImports(definitions, imports, ['Option']);
@@ -259,13 +288,3 @@ export function formatType (definitions: object, type: string | TypeDef, imports
}
}
}
/**
* Indent a string with `n` spaces before.
*/
/** @internal */
export function indent (n: number, char = ' '): (str: string) => string {
return function (str: string): string {
return `${char.repeat(n)}${str}`;
};
}
+3
View File
@@ -8,3 +8,6 @@ export * from './file';
export * from './formatting';
export * from './imports';
export * from './register';
export const compareName = (a: { name: { toString(): string } }, b: { name: { toString(): string } }): number =>
a.name.toString().localeCompare(b.name.toString());
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-known",
"version": "1.10.1",
"version": "1.13.1",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -26,9 +26,9 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/types": "1.10.1",
"@polkadot/util": "^2.8.1",
"@babel/runtime": "^7.9.6",
"@polkadot/types": "1.13.1",
"@polkadot/util": "^2.9.1",
"bn.js": "^5.1.1"
},
"devDependencies": {
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
+10 -7
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -12,14 +12,15 @@ import typesChain from './chain';
import typesMeta from './metadata';
import typesModules from './modules';
import typesSpec from './spec';
import warnings from './warnings';
// flatten a VersionedType[] into a Record<string, string>
/** @internal */
function filterVersions (versions: OverrideVersionedType[] = [], version: number): RegistryTypes {
function filterVersions (versions: OverrideVersionedType[] = [], specVersion: number): RegistryTypes {
return versions
.filter(({ minmax: [min, max] }): boolean =>
(isUndefined(min) || version >= min) &&
(isUndefined(max) || version <= max)
.filter(({ minmax: [min, max] }) =>
(isUndefined(min) || specVersion >= min) &&
(isUndefined(max) || specVersion <= max)
)
.reduce((result: RegistryTypes, { types }): RegistryTypes => ({
...result,
@@ -30,8 +31,8 @@ function filterVersions (versions: OverrideVersionedType[] = [], version: number
/**
* @description Based on the metadata version, return the registry types
*/
export function getMetadataTypes (_registry: Registry, version: number): RegistryTypes {
return filterVersions(typesMeta, version);
export function getMetadataTypes (_registry: Registry, specVersion: number): RegistryTypes {
return filterVersions(typesMeta, specVersion);
}
/**
@@ -52,6 +53,8 @@ export function getSpecTypes ({ knownTypes }: Registry, chainName: Text | string
const _specName = specName.toString();
const _specVersion = bnToBn(specVersion).toNumber();
(warnings[_specName] || []).forEach((warning) => console.warn(`*** ${warning}`));
return {
...filterVersions(typesSpec[_specName], _specVersion),
...filterVersions(typesChain[_chainName], _specVersion),
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -6,12 +6,14 @@ import { OverrideVersionedType } from '@polkadot/types/types';
const versioned: OverrideVersionedType[] = [
{
minmax: [1000, undefined],
// most chains started at 1000 (Fulvous at 224)
minmax: [1, undefined],
types: {
Address: 'AccountId',
LookupSource: 'AccountId',
ReferendumInfo: 'ReferendumInfoTo239',
StakingLedger: 'StakingLedgerTo240'
StakingLedger: 'StakingLedgerTo240',
Weight: 'u32'
}
}
];
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
+21 -7
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -17,7 +17,8 @@ const versioned: OverrideVersionedType[] = [
ReferendumInfo: 'ReferendumInfoTo239',
SlashingSpans: 'SlashingSpansTo204',
StakingLedger: 'StakingLedgerTo223',
Votes: 'VotesTo230'
Votes: 'VotesTo230',
Weight: 'u32'
}
},
{
@@ -30,7 +31,8 @@ const versioned: OverrideVersionedType[] = [
ReferendumInfo: 'ReferendumInfoTo239',
SlashingSpans: 'SlashingSpansTo204',
StakingLedger: 'StakingLedgerTo223',
Votes: 'VotesTo230'
Votes: 'VotesTo230',
Weight: 'u32'
}
},
{
@@ -43,7 +45,8 @@ const versioned: OverrideVersionedType[] = [
LookupSource: 'Address',
ReferendumInfo: 'ReferendumInfoTo239',
StakingLedger: 'StakingLedgerTo223',
Votes: 'VotesTo230'
Votes: 'VotesTo230',
Weight: 'u32'
}
},
{
@@ -55,16 +58,27 @@ const versioned: OverrideVersionedType[] = [
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
ReferendumInfo: 'ReferendumInfoTo239',
StakingLedger: 'StakingLedgerTo240'
StakingLedger: 'StakingLedgerTo240',
Weight: 'u32'
}
},
{
minmax: [1055, undefined],
minmax: [1055, 1056],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
StakingLedger: 'StakingLedgerTo240'
StakingLedger: 'StakingLedgerTo240',
Weight: 'u32'
}
},
{
// actual upgrade at 1058
minmax: [1057, undefined],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId'
}
}
];
+25 -5
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -17,7 +17,8 @@ const versioned: OverrideVersionedType[] = [
Keys: 'SessionKeys5',
LookupSource: 'Address',
StakingLedger: 'StakingLedgerTo223',
Votes: 'VotesTo230'
Votes: 'VotesTo230',
Weight: 'u32'
}
},
{
@@ -28,16 +29,35 @@ const versioned: OverrideVersionedType[] = [
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
ReferendumInfo: 'ReferendumInfoTo239',
StakingLedger: 'StakingLedgerTo240'
StakingLedger: 'StakingLedgerTo240',
Weight: 'u32'
}
},
{
minmax: [1005, undefined],
minmax: [1005, 1005],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
StakingLedger: 'StakingLedgerTo240'
StakingLedger: 'StakingLedgerTo240',
Weight: 'u32'
}
},
{
minmax: [1006, 1006],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
Weight: 'u32'
}
},
{
minmax: [1007, undefined],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId'
}
}
];
+11 -2
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// Copyright 2017-2020 @polkadot/types-known authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -6,7 +6,16 @@ import { OverrideVersionedType } from '@polkadot/types/types';
const versioned: OverrideVersionedType[] = [
{
minmax: [1, undefined],
minmax: [1, 2],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',
LookupSource: 'AccountId',
Weight: 'u32'
}
},
{
minmax: [3, undefined],
types: {
Address: 'AccountId',
Keys: 'SessionKeys5',

Some files were not shown because too many files have changed in this diff Show More