Compare commits

..
112 Commits
Author SHA1 Message Date
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
117 changed files with 1840 additions and 914 deletions
+3 -2
View File
@@ -1,3 +1,4 @@
21
1.4.2
24
1.4.2
1.6.2
1.11.2
+34
View File
@@ -1,3 +1,37 @@
# 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"
+11
View File
@@ -50,6 +50,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/',
+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
+8 -1
View File
@@ -17,6 +17,11 @@ const api = await ApiPromise.create({
{
name: 'index',
type: 'u64'
},
{
name: 'at',
type: 'Hash',
isOptional: true
}
],
type: 'Balance'
@@ -26,7 +31,9 @@ const api = await ApiPromise.create({
});
```
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.12.1"
}
+1 -1
View File
@@ -27,7 +27,7 @@
"@babel/core": "^7.9.0",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@polkadot/dev": "^0.52.9",
"@polkadot/dev": "^0.52.11",
"@polkadot/ts": "^0.3.18",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^25.2.1",
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "1.10.1",
"version": "1.12.1",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
"keywords": [
@@ -27,10 +27,10 @@
"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",
"@polkadot/api": "1.12.1",
"@polkadot/rpc-core": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"bn.js": "^5.1.1",
"rxjs": "^6.5.5"
}
+8 -8
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "1.10.1",
"version": "1.12.1",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
"keywords": [
@@ -28,17 +28,17 @@
"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",
"@polkadot/api": "1.12.1",
"@polkadot/rpc-core": "1.12.1",
"@polkadot/rpc-provider": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"@polkadot/util-crypto": "^2.9.0-beta.3",
"bn.js": "^5.1.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.0-beta.3"
}
}
+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.
+11 -11
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "1.10.1",
"version": "1.12.1",
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
"main": "index.js",
"keywords": [
@@ -27,20 +27,20 @@
"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",
"@polkadot/api-derive": "1.12.1",
"@polkadot/keyring": "^2.9.0-beta.3",
"@polkadot/metadata": "1.12.1",
"@polkadot/rpc-core": "1.12.1",
"@polkadot/rpc-provider": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/types-known": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"@polkadot/util-crypto": "^2.9.0-beta.3",
"bn.js": "^5.1.1",
"eventemitter3": "^4.0.0",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.0-beta.3"
}
}
+64 -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.
@@ -98,14 +77,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>;
@@ -146,6 +117,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 +132,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 +178,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 +207,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 +242,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 +253,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.
+2 -11
View File
@@ -1,7 +1,7 @@
// 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';
@@ -9,7 +9,7 @@ import { BabeAuthorityWeight, MaybeVrf, Randomness } from '@polkadot/types/inter
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 { 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' {
@@ -147,14 +146,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.
**/
+18 -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';
@@ -17,9 +17,8 @@ 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 {
@@ -145,11 +144,11 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
/**
* Get offchain local storage under given key and prefix
**/
localStorageGet: AugmentedRpc<(kind: StorageKind | ('__UNUSED' | 'PERSISTENT' | 'LOCAL') | number | Uint8Array, key: Bytes | string | Uint8Array) => Observable<Option<Bytes>>>;
localStorageGet: AugmentedRpc<(kind: StorageKind | '__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 +196,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 +234,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 +253,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
**/
+116 -29
View File
@@ -33,6 +33,10 @@ declare module '@polkadot/api/types/submittable' {
/**
* Exactly as `transfer`, except the origin must be root and the source account may be
* specified.
* # <weight>
* - Same as transfer, but additional read and write because the source account is
* not assumed to be in the overlay.
* # </weight>
**/
forceTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, dest: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
@@ -110,7 +114,7 @@ declare module '@polkadot/api/types/submittable' {
* Stores the given binary Wasm code into the chain's storage and returns its `codehash`.
* You can instantiate contracts only with stored code.
**/
putCode: AugmentedSubmittable<(gasLimit: Compact<Gas> | AnyNumber | Uint8Array, code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
putCode: AugmentedSubmittable<(code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Updates the schedule for metering contracts.
* The schedule must have a greater version than the stored schedule.
@@ -237,7 +241,7 @@ declare module '@polkadot/api/types/submittable' {
* # <weight>
* # </weight>
**/
delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | 'None'|'Locked1x'|'Locked2x'|'Locked3x'|'Locked4x'|'Locked5x'|'Locked6x' | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Schedule an emergency cancellation of a referendum. Cannot happen twice to the same
* referendum.
@@ -375,7 +379,7 @@ declare module '@polkadot/api/types/submittable' {
* # <weight>
* # </weight>
**/
proxyDelegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
proxyDelegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | 'None'|'Locked1x'|'Locked2x'|'Locked3x'|'Locked4x'|'Locked5x'|'Locked6x' | number | Uint8Array, balance: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Remove a proxied vote for a referendum.
* Exactly equivalent to `remove_vote` except that it operates on the account that the
@@ -630,9 +634,12 @@ declare module '@polkadot/api/types/submittable' {
* - `account`: the account of the registrar.
* 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.
* - Benchmarks:
* - 78.71 + R * 0.965 µs (min squares analysis)
* - 94.28 + R * 0.991 µs (min squares analysis)
* # </weight>
**/
addRegistrar: AugmentedSubmittable<(account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -648,20 +655,29 @@ declare module '@polkadot/api/types/submittable' {
* - One balance-reserve operation.
* - One storage mutation `O(R + X)`.
* - One event.
* - Benchmarks:
* - 135.3 + R * 0.574 + X * 3.394 µs (min squares analysis)
* - 144.3 + R * 0.316 + X * 3.53 µs (min squares analysis)
* # </weight>
**/
cancelRequest: AugmentedSubmittable<(regIndex: RegistrarIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* 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.
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
* identity.
* 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:
* - 152.3 + R * 0.306 + S * 4.967 + X * 1.697 µs (min squares analysis)
* - 139.5 + R * 0.466 + S * 5.304 + X * 1.895 µs (min squares analysis)
* # </weight>
**/
clearIdentity: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
@@ -679,6 +695,7 @@ declare module '@polkadot/api/types/submittable' {
* - One balance-reserve operation.
* - `S + 2` storage mutations.
* - One event.
* - Benchmark: 167.4 + R * 1.107 + S * 5.343 + X * 2.294 µs (min squares analysis)
* # </weight>
**/
killIdentity: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -697,6 +714,7 @@ declare module '@polkadot/api/types/submittable' {
* - Up to one account-lookup operation.
* - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`.
* - One event.
* - Benchmark: 110.7 + R * 1.066 + X * 3.402 µs (min squares analysis)
* # </weight>
**/
provideJudgement: AugmentedSubmittable<(regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, judgement: IdentityJudgement | { Unknown: any } | { FeePaid: any } | { Reasonable: any } | { KnownGood: any } | { OutOfDate: any } | { LowQuality: any } | { Erroneous: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -709,7 +727,7 @@ declare module '@polkadot/api/types/submittable' {
* - `reg_index`: The index of the registrar whose judgement is requested.
* - `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.
* # <weight>
@@ -717,6 +735,9 @@ declare module '@polkadot/api/types/submittable' {
* - One balance-reserve operation.
* - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`.
* - One event.
* - Benchmarks:
* - 154 + R * 0.932 + X * 3.302 µs (min squares analysis)
* - 172.9 + R * 0.69 + X * 3.304 µs (min squares analysis)
* # </weight>
**/
requestJudgement: AugmentedSubmittable<(regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, maxFee: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -729,6 +750,7 @@ declare module '@polkadot/api/types/submittable' {
* # <weight>
* - `O(R)`.
* - One storage mutation `O(R)`.
* - Benchmark: 24.59 + R * 0.832 µs (min squares analysis)
* # </weight>
**/
setAccountId: AugmentedSubmittable<(index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, updated: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -741,6 +763,8 @@ declare module '@polkadot/api/types/submittable' {
* # <weight>
* - `O(R)`.
* - One storage mutation `O(R)`.
* - Benchmarks:
* - 23.81 + R * 0.774 µs (min squares analysis)
* # </weight>
**/
setFee: AugmentedSubmittable<(index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, fee: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -753,6 +777,7 @@ declare module '@polkadot/api/types/submittable' {
* # <weight>
* - `O(R)`.
* - One storage mutation `O(R)`.
* - Benchmark: 22.85 + R * 0.853 µs (min squares analysis)
* # </weight>
**/
setFields: AugmentedSubmittable<(index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, fields: IdentityFields) => SubmittableExtrinsic<ApiType>>;
@@ -760,15 +785,19 @@ declare module '@polkadot/api/types/submittable' {
* Set an account's identity information and reserve the appropriate deposit.
* 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.
* - Benchmarks:
* - 136.6 + R * 0.62 + X * 2.62 µs (min squares analysis)
* - 146.2 + R * 0.372 + X * 2.98 µs (min squares analysis)
* # </weight>
**/
setIdentity: AugmentedSubmittable<(info: IdentityInfo | { additional?: any; display?: any; legal?: any; web?: any; riot?: any; email?: any; pgpFingerprint?: any; image?: any; twitter?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -778,12 +807,20 @@ declare module '@polkadot/api/types/submittable' {
* and an amount `SubAccountDeposit` will be reserved for each item in `subs`.
* 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`).
* - Benchmarks:
* - 115.2 + P * 5.11 + S * 6.67 µs (min squares analysis)
* - 121 + P * 4.852 + S * 7.111 µs (min squares analysis)
* # </weight>
**/
setSubs: AugmentedSubmittable<(subs: Vec<ITuple<[AccountId, Data]>> | ([AccountId | string | Uint8Array, Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array])[]) => SubmittableExtrinsic<ApiType>>;
@@ -1024,9 +1061,11 @@ declare module '@polkadot/api/types/submittable' {
* This doesn't take effect until the next session.
* 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>
**/
purgeKeys: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
@@ -1036,10 +1075,12 @@ declare module '@polkadot/api/types/submittable' {
* This doesn't take effect until the next session.
* 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>
**/
setKeys: AugmentedSubmittable<(keys: Keys, proof: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
@@ -1144,7 +1185,7 @@ declare module '@polkadot/api/types/submittable' {
* Total Complexity: O(M + logM + B + X)
* # </weight>
**/
judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | ('Rebid' | 'Reject' | 'Approve') | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
judgeSuspendedCandidate: AugmentedSubmittable<(who: AccountId | string | Uint8Array, judgement: SocietyJudgement | 'Rebid'|'Reject'|'Approve' | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Allow suspension judgement origin to make judgement on a suspended member.
* If a suspended member is forgiven, we simply add them back as a member, not affecting
@@ -1322,7 +1363,7 @@ declare module '@polkadot/api/types/submittable' {
* unless the `origin` falls below _existential deposit_ and gets removed as dust.
* # </weight>
**/
bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
bond: AugmentedSubmittable<(controller: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Add some extra amount that have appeared in the stash `free_balance` into the balance up
* for staking.
@@ -1506,7 +1547,7 @@ declare module '@polkadot/api/types/submittable' {
* - Writes are limited to the `origin` account key.
* # </weight>
**/
setPayee: AugmentedSubmittable<(payee: RewardDestination | ('Staked' | 'Stash' | 'Controller') | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
setPayee: AugmentedSubmittable<(payee: RewardDestination | 'Staked'|'Stash'|'Controller' | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* The ideal number of validators.
**/
@@ -1558,7 +1599,7 @@ declare module '@polkadot/api/types/submittable' {
* - Storage: O(n) reads `AccountId` to fetch `snapshot_nominators`.
* - 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).
* - Storage: O(e) writes to `QueuedElected`.
@@ -1672,39 +1713,80 @@ declare module '@polkadot/api/types/submittable' {
fillBlock: AugmentedSubmittable<(ratio: Perbill | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* 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>
**/
killPrefix: AugmentedSubmittable<(prefix: Key | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Kill some items from storage.
* # <weight>
* - `O(VK)` where `V` length of `keys` and `K` length of one key
* - `V` storage deletions.
* # </weight>
**/
killStorage: AugmentedSubmittable<(keys: Vec<Key> | (Key | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
/**
* Make some on-chain remark.
* # <weight>
* - `O(1)`
* # </weight>
**/
remark: AugmentedSubmittable<(remark: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* 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>
**/
setChangesTrieConfig: AugmentedSubmittable<(changesTrieConfig: Option<ChangesTrieConfiguration> | null | object | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* 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>
**/
setCode: AugmentedSubmittable<(code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* 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>
**/
setCodeWithoutChecks: AugmentedSubmittable<(code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Set the number of pages in the WebAssembly environment's heap.
* # <weight>
* - `O(1)`
* - 1 storage write.
* # </weight>
**/
setHeapPages: AugmentedSubmittable<(pages: u64 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
/**
* Set some items of storage.
* # <weight>
* - `O(I)` where `I` length of `items`
* - `I` storage writes (`O(1)`).
* # </weight>
**/
setStorage: AugmentedSubmittable<(items: Vec<KeyValue> | (KeyValue)[]) => SubmittableExtrinsic<ApiType>>;
/**
* Kill the sending account, assuming there are no references outstanding and the composite
* data is equal to its default value.
* # <weight>
* - `O(K)` with `K` being complexity of `on_killed_account`
* - 1 storage read and deletion.
* - 1 call to `on_killed_account` callback with unknown complexity `K`
* - 1 event.
* # </weight>
**/
suicide: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
};
@@ -1799,6 +1881,11 @@ declare module '@polkadot/api/types/submittable' {
* The timestamp should be greater than the previous one by the amount specified by
* `MinimumPeriod`.
* The dispatch origin for this call must be `Inherent`.
* # <weight>
* - `O(T)` where `T` complexity of `on_timestamp_set`
* - 2 storage mutations (codec `O(1)`).
* - 1 event handler `on_timestamp_set` `O(T)`.
* # </weight>
**/
set: AugmentedSubmittable<(now: Compact<Moment> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
};
+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
}
+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;
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/metadata",
"version": "1.10.1",
"version": "1.12.1",
"description": "Helpers to extract information from runtime metadata",
"main": "index.js",
"publishConfig": {
@@ -27,13 +27,13 @@
"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",
"@polkadot/types": "1.12.1",
"@polkadot/types-known": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"@polkadot/util-crypto": "^2.9.0-beta.3",
"bn.js": "^5.1.1"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.0-beta.3"
}
}
@@ -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,14 @@
"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(K)` with `K` being complexity of `on_killed_account`",
" - 1 storage read and deletion.",
" - 1 call to `on_killed_account` callback with unknown complexity `K`",
" - 1 event.",
" # </weight>"
]
}
],
@@ -368,7 +418,48 @@
]
}
],
"constants": [],
"constants": [
{
"name": "MaximumBlockWeight",
"type": "Weight",
"value": "0x00204aa9d1010000",
"documentation": [
" The maximum weight of a block."
]
},
{
"name": "DbWeight",
"type": "RuntimeDbWeight",
"value": "0x008793030000000000c2eb0b00000000",
"documentation": [
" The weight of runtime database operations the runtime can invoke."
]
},
{
"name": "BlockExecutionWeight",
"type": "Weight",
"value": "0x0000000000000000",
"documentation": [
" The base weight of executing a block, independent of the transactions in the block."
]
},
{
"name": "ExtrinsicBaseWeight",
"type": "Weight",
"value": "0x8096980000000000",
"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",
@@ -944,7 +1035,7 @@
{
"name": "EpochDuration",
"type": "u64",
"value": "0x1400000000000000",
"value": "0xc800000000000000",
"documentation": [
" The number of **slots** that an epoch takes. We couple sessions to",
" epochs, i.e. we start a new session once the new epoch begins."
@@ -1012,7 +1103,13 @@
" 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`",
" - 2 storage mutations (codec `O(1)`).",
" - 1 event handler `on_timestamp_set` `O(T)`.",
" # </weight>"
]
}
],
@@ -1457,7 +1554,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>"
]
},
{
@@ -1609,7 +1710,7 @@
"type": {
"Plain": "Multiplier"
},
"fallback": "0x0000000000000000",
"fallback": "0x00000000000000000000000000000000",
"documentation": []
}
]
@@ -1617,14 +1718,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 +2847,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 +2889,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 +3286,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 +3305,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>"
]
}
@@ -5548,6 +5657,12 @@
"type": "BlockNumber",
"value": "0x80130300",
"documentation": []
},
{
"name": "ModuleId",
"type": "LockIdentifier",
"value": "0x706872656c656374",
"documentation": []
}
],
"errors": [
@@ -6491,6 +6606,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 +6672,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 +6741,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 +6762,6 @@
{
"name": "put_code",
"args": [
{
"name": "gas_limit",
"type": "Compact<Gas>"
},
{
"name": "code",
"type": "Bytes"
@@ -6917,49 +7014,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 +7030,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": [
@@ -7497,9 +7542,12 @@
" 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.",
" - Benchmarks:",
" - 78.71 + R * 0.965 µs (min squares analysis)",
" - 94.28 + R * 0.991 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7517,18 +7565,22 @@
" 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.",
" - Benchmarks:",
" - 136.6 + R * 0.62 + X * 2.62 µs (min squares analysis)",
" - 146.2 + R * 0.372 + X * 2.98 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7549,13 +7601,21 @@
" 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`).",
" - Benchmarks:",
" - 115.2 + P * 5.11 + S * 6.67 µs (min squares analysis)",
" - 121 + P * 4.852 + S * 7.111 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7563,7 +7623,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 +7633,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:",
" - 152.3 + R * 0.306 + S * 4.967 + X * 1.697 µs (min squares analysis)",
" - 139.5 + R * 0.466 + S * 5.304 + X * 1.895 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7605,7 +7671,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 +7681,9 @@
" - One balance-reserve operation.",
" - Storage: 1 read `O(R)`, 1 mutate `O(X + R)`.",
" - One event.",
" - Benchmarks:",
" - 154 + R * 0.932 + X * 3.302 µs (min squares analysis)",
" - 172.9 + R * 0.69 + X * 3.304 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7643,6 +7712,9 @@
" - One balance-reserve operation.",
" - One storage mutation `O(R + X)`.",
" - One event.",
" - Benchmarks:",
" - 135.3 + R * 0.574 + X * 3.394 µs (min squares analysis)",
" - 144.3 + R * 0.316 + X * 3.53 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7670,6 +7742,8 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmarks:",
" - 23.81 + R * 0.774 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7697,6 +7771,7 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmark: 24.59 + R * 0.832 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7724,6 +7799,7 @@
" # <weight>",
" - `O(R)`.",
" - One storage mutation `O(R)`.",
" - Benchmark: 22.85 + R * 0.853 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7762,6 +7838,7 @@
" - Up to one account-lookup operation.",
" - Storage: 1 read `O(R)`, 1 mutate `O(R + X)`.",
" - One event.",
" - Benchmark: 110.7 + R * 1.066 + X * 3.402 µs (min squares analysis)",
" # </weight>"
]
},
@@ -7792,6 +7869,7 @@
" - One balance-reserve operation.",
" - `S + 2` storage mutations.",
" - One event.",
" - Benchmark: 167.4 + R * 1.107 + S * 5.343 + X * 2.294 µs (min squares analysis)",
" # </weight>"
]
}
@@ -7866,7 +7944,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 +8070,12 @@
"documentation": [
" Too many additional fields."
]
},
{
"name": "TooManyRegistrars",
"documentation": [
" Maximum amount of registrars reached. Cannot add any more."
]
}
]
},
@@ -8793,6 +8930,14 @@
"documentation": [
" The number of blocks between membership challenges."
]
},
{
"name": "ModuleId",
"type": "ModuleId",
"value": "0x70792f736f636965",
"documentation": [
" The societies's module id"
]
}
],
"errors": [
@@ -9639,8 +9784,7 @@
"CheckEra",
"CheckNonce",
"CheckWeight",
"ChargeTransactionPayment",
"CheckBlockGasLimit"
"ChargeTransactionPayment"
]
}
}
File diff suppressed because one or more lines are too long
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-core",
"version": "1.10.1",
"version": "1.12.1",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -27,14 +27,14 @@
"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",
"@polkadot/metadata": "1.12.1",
"@polkadot/rpc-provider": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1"
"@polkadot/keyring": "^2.9.0-beta.3"
}
}
+23 -8
View File
@@ -336,7 +336,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),
@@ -432,13 +436,24 @@ export default class Rpc implements RpcInterface {
this.#storageCache.set(hexKey, value);
if (meta.modifier.isOptional) {
return new Option(
this.registry,
createClass(this.registry, type),
isEmpty
? null
: createTypeUnsafe(this.registry, type, [input], true)
);
try {
return new Option(
this.registry,
createClass(this.registry, type),
isEmpty
? null
: createTypeUnsafe(this.registry, type, [input], true)
);
} catch (error) {
if (type === 'PreimageStatus') {
return new Option(
this.registry,
createClass(this.registry, type)
);
}
throw error;
}
}
return createTypeUnsafe(this.registry, type, [
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "1.10.1",
"version": "1.12.1",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
@@ -27,17 +27,17 @@
"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",
"@polkadot/metadata": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"@polkadot/util-crypto": "^2.9.0-beta.3",
"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.0-beta.3",
"mock-socket": "^9.0.3",
"nock": "^12.0.3"
}
+8 -8
View File
@@ -75,7 +75,7 @@ export default class WsProvider implements WSProviderInterface {
readonly #waitingForId: Record<string, JsonRpcResponse> = {};
#autoConnect: boolean;
#autoConnectMs: number;
#isConnected = false;
@@ -87,16 +87,16 @@ export default class WsProvider implements WSProviderInterface {
* @param {string} endpoint The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944`
* @param {boolean} autoConnect Whether to connect automatically or not.
*/
constructor (endpoint: string = defaults.WS_URL, autoConnect = true) {
constructor (endpoint: string = defaults.WS_URL, autoConnectMs: number | false = 1000) {
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.#websocket = null;
if (autoConnect) {
if (autoConnectMs > 0) {
this.connect();
}
}
@@ -143,7 +143,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 +267,17 @@ export default class WsProvider implements WSProviderInterface {
}
#onSocketClose = (event: CloseEvent): void => {
if (this.#autoConnect) {
if (this.#autoConnectMs > 0) {
l.error(`disconnected from ${this.#endpoint} 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);
}
}
+3 -3
View File
@@ -20,19 +20,19 @@ describe('onConnect', (): void => {
});
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);
const provider: WsProvider = new WsProvider(TEST_WS_URL, 1000);
expect(provider.isConnected()).not.toBe(true);
});
it('Creates a new WebSocket instance by calling the connect() method', (): void => {
const provider: WsProvider = new WsProvider(TEST_WS_URL, false);
const provider: WsProvider = new WsProvider(TEST_WS_URL, 0);
expect(provider.isConnected()).toBe(false);
+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);
@@ -25,7 +25,7 @@ describe('Ws', (): void => {
it('returns the connected state', (): void => {
expect(
createWs([], true).isConnected()
createWs([]).isConnected()
).toEqual(false);
});
});
+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 => {
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "1.10.1",
"version": "1.12.1",
"description": "Type generation scripts",
"main": "index.js",
"bin": {
@@ -36,11 +36,11 @@
"@babel/core": "^7.9.0",
"@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",
"@polkadot/api": "1.12.1",
"@polkadot/metadata": "1.12.1",
"@polkadot/rpc-provider": "1.12.1",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"websocket": "^1.0.31",
"yargs": "^15.3.1"
},
@@ -20,6 +20,7 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string
const imports = createImports(importDefinitions);
const definitions = imports.definitions;
const primitives = Object
.keys(primitiveClasses)
.filter((name): boolean => !!name.indexOf('Generic'))
@@ -32,13 +33,19 @@ export function generateInterfaceTypes (importDefinitions: { [importPath: string
].join('\n');
}, '');
const existingTypes: Record<string, boolean> = {};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const srml = Object.entries(definitions).reduce((accumulator, [_defName, { types }]): string => {
setImports(definitions, imports, Object.keys(types));
const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]);
uniqueTypes.forEach((type) => { existingTypes[type] = true; });
return [
accumulator,
...Object.keys(types).map((type): string =>
...uniqueTypes.map((type): string =>
getDerivedTypes(definitions, type, types[type], imports).map(indent(4)).join('\n')
)
].join('\n');
+6 -7
View File
@@ -10,7 +10,7 @@ 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';
@@ -67,7 +67,7 @@ function generateModule (allDefs: object, registry: Registry, { name, storage }:
return [];
}
return [indent(4)(`${stringLowerFirst(name.toString())}: {`)]
return [indent(4)(`${stringCamelCase(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);
@@ -78,7 +78,7 @@ function generateModule (allDefs: object, registry: Registry, { name, storage }:
}
return createDocComments(6, storageEntry.documentation) +
indent(6)(`${stringLowerFirst(storageEntry.name.toString())}: ${entryType}<ApiType, (${args}) => Observable<${returnType}>>${isStrict ? '' : ' & QueryableStorageEntry<ApiType>'};`);
indent(6)(`${stringCamelCase(storageEntry.name.toString())}: ${entryType}<ApiType, (${args}) => Observable<${returnType}>>${isStrict ? '' : ' & QueryableStorageEntry<ApiType>'};`);
}))
.concat([indent(4)('};')]);
}
@@ -94,15 +94,14 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
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));
}, []);
imports.typesTypes.Observable = true;
const header = createImportCode(HEADER('chain'), imports, [
...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']
+4 -6
View File
@@ -37,7 +37,7 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.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>>;`);
} else if (methodName === 'subscribeStorage') {
return createDocComments(6, [def.description]) + indent(6)(`subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[]) => Observable<T>>;`);
return createDocComments(6, [def.description]) + indent(6)(`subscribeStorage: AugmentedRpc<<T = Codec[]>(keys?: Vec<StorageKey> | (${StorageKeyTye})[]) => Observable<T>>;`);
}
}
@@ -63,15 +63,13 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t
);
}, []).join('\n');
imports.typesTypes.Observable = true;
const header = createImportCode(HEADER('chain'), imports, [
...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}';
+2
View File
@@ -37,6 +37,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 +157,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,
+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);
+14
View File
@@ -97,6 +97,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 +182,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']);
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-known",
"version": "1.10.1",
"version": "1.12.1",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -27,8 +27,8 @@
"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",
"@polkadot/types": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"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.
@@ -11,7 +11,8 @@ const versioned: OverrideVersionedType[] = [
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',
+18
View File
@@ -0,0 +1,18 @@
// 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.
// Type overrides for specific spec types & versions as given in runtimeVersion
const warnings: Record<string, string[]> = {
'node-template': [
'',
'You are using the node-template, depending on your config and age of the template, you may',
'have some unexpected results without applying the correct config for your node type:',
'',
'- If you have trouble sending txs, apply https://polkadot.js.org/api/start/FAQ.html#i-cannot-send-transactions-from-my-node-template-based-chain',
'- If you have trouble parsing events, apply https://polkadot.js.org/api/start/FAQ.html#using-a-non-current-master-node-i-have-issues-parsing-events',
''
]
};
export default warnings;
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types",
"version": "1.10.1",
"version": "1.12.1",
"description": "Implementation of the Parity codec",
"main": "index.js",
"keywords": [
@@ -27,16 +27,16 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.9.2",
"@polkadot/metadata": "1.10.1",
"@polkadot/util": "^2.8.1",
"@polkadot/util-crypto": "^2.8.1",
"@polkadot/metadata": "1.12.1",
"@polkadot/util": "^2.9.0-beta.3",
"@polkadot/util-crypto": "^2.9.0-beta.3",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@polkadot/keyring": "^2.8.1",
"@polkadot/keyring": "^2.9.0-beta.3",
"@types/memoizee": "^0.4.3"
}
}
+55 -8
View File
@@ -2,7 +2,7 @@
/* eslint-disable */
import { Compact, Option, Raw, Vec } from '@polkadot/types/codec';
import { BitVec, Bytes, Data, Null, StorageKey, Text, Type, U256, Unconstructable, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types/primitive';
import { BitVec, Bytes, Data, DoNotConstruct, Null, StorageKey, Text, Type, U256, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types/primitive';
import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
import { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
import { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
@@ -27,16 +27,16 @@ import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetwor
import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV11, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV11, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV11, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV11, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV11, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import { StorageKind } from '@polkadot/types/interfaces/offchain';
import { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
import { AttestedCandidate, AuctionIndex, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
import { AttestedCandidate, AuctionIndex, Bidder, CandidateReceipt, CollatorId, CollatorSignature, DoubleVoteReport, DoubleVoteReportProof, DoubleVoteReportStatement, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaPastCodeMeta, ParaScheduling, ParachainDispatchOrigin, Retriable, SigningContext, SlotRange, Statement, SubId, UpwardMessage, ValidationCode, ValidatorSignature, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, Moment, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, Fixed128, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
import { SchedulePeriod, SchedulePriority, Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, ReleasesStaking, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { ApiId, KeyValueOption, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state';
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, OffchainAccuracy, PerU16, PhragmenScore, Points, ReleasesStaking, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state';
import { AccountInfo, ChainProperties, ChainType, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Health, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, Phase, RefCount } from '@polkadot/types/interfaces/system';
import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
@@ -57,6 +57,9 @@ declare module '@polkadot/types/types/registry' {
Data: Data;
'Option<Data>': Option<Data>;
'Vec<Data>': Vec<Data>;
DoNotConstruct: DoNotConstruct;
'Option<DoNotConstruct>': Option<DoNotConstruct>;
'Vec<DoNotConstruct>': Vec<DoNotConstruct>;
i8: i8;
'Option<i8>': Option<i8>;
'Vec<i8>': Vec<i8>;
@@ -115,9 +118,6 @@ declare module '@polkadot/types/types/registry' {
'Compact<U256>': Compact<U256>;
'Option<U256>': Option<U256>;
'Vec<U256>': Vec<U256>;
Unconstructable: Unconstructable;
'Option<Unconstructable>': Option<Unconstructable>;
'Vec<Unconstructable>': Vec<Unconstructable>;
usize: usize;
'Compact<usize>': Compact<usize>;
'Option<usize>': Option<usize>;
@@ -182,6 +182,9 @@ declare module '@polkadot/types/types/registry' {
Fixed64: Fixed64;
'Option<Fixed64>': Option<Fixed64>;
'Vec<Fixed64>': Vec<Fixed64>;
Fixed128: Fixed128;
'Option<Fixed128>': Option<Fixed128>;
'Vec<Fixed128>': Vec<Fixed128>;
H160: H160;
'Option<H160>': Option<H160>;
'Vec<H160>': Vec<H160>;
@@ -220,6 +223,9 @@ declare module '@polkadot/types/types/registry' {
LookupTarget: LookupTarget;
'Option<LookupTarget>': Option<LookupTarget>;
'Vec<LookupTarget>': Vec<LookupTarget>;
ModuleId: ModuleId;
'Option<ModuleId>': Option<ModuleId>;
'Vec<ModuleId>': Vec<ModuleId>;
Moment: Moment;
'Compact<Moment>': Compact<Moment>;
'Option<Moment>': Option<Moment>;
@@ -249,6 +255,9 @@ declare module '@polkadot/types/types/registry' {
PhantomData: PhantomData;
'Option<PhantomData>': Option<PhantomData>;
'Vec<PhantomData>': Vec<PhantomData>;
RuntimeDbWeight: RuntimeDbWeight;
'Option<RuntimeDbWeight>': Option<RuntimeDbWeight>;
'Vec<RuntimeDbWeight>': Vec<RuntimeDbWeight>;
SignedBlock: SignedBlock;
'Option<SignedBlock>': Option<SignedBlock>;
'Vec<SignedBlock>': Vec<SignedBlock>;
@@ -827,6 +836,17 @@ declare module '@polkadot/types/types/registry' {
Nominations: Nominations;
'Option<Nominations>': Option<Nominations>;
'Vec<Nominations>': Vec<Nominations>;
NominatorIndex: NominatorIndex;
'Compact<NominatorIndex>': Compact<NominatorIndex>;
'Option<NominatorIndex>': Option<NominatorIndex>;
'Vec<NominatorIndex>': Vec<NominatorIndex>;
OffchainAccuracy: OffchainAccuracy;
'Option<OffchainAccuracy>': Option<OffchainAccuracy>;
'Vec<OffchainAccuracy>': Vec<OffchainAccuracy>;
PerU16: PerU16;
'Compact<PerU16>': Compact<PerU16>;
'Option<PerU16>': Option<PerU16>;
'Vec<PerU16>': Vec<PerU16>;
PhragmenScore: PhragmenScore;
'Option<PhragmenScore>': Option<PhragmenScore>;
'Vec<PhragmenScore>': Vec<PhragmenScore>;
@@ -1037,6 +1057,15 @@ declare module '@polkadot/types/types/registry' {
CollatorSignature: CollatorSignature;
'Option<CollatorSignature>': Option<CollatorSignature>;
'Vec<CollatorSignature>': Vec<CollatorSignature>;
DoubleVoteReport: DoubleVoteReport;
'Option<DoubleVoteReport>': Option<DoubleVoteReport>;
'Vec<DoubleVoteReport>': Vec<DoubleVoteReport>;
DoubleVoteReportProof: DoubleVoteReportProof;
'Option<DoubleVoteReportProof>': Option<DoubleVoteReportProof>;
'Vec<DoubleVoteReportProof>': Vec<DoubleVoteReportProof>;
DoubleVoteReportStatement: DoubleVoteReportStatement;
'Option<DoubleVoteReportStatement>': Option<DoubleVoteReportStatement>;
'Vec<DoubleVoteReportStatement>': Vec<DoubleVoteReportStatement>;
EgressQueueRoot: EgressQueueRoot;
'Option<EgressQueueRoot>': Option<EgressQueueRoot>;
'Vec<EgressQueueRoot>': Vec<EgressQueueRoot>;
@@ -1071,6 +1100,9 @@ declare module '@polkadot/types/types/registry' {
ParaInfo: ParaInfo;
'Option<ParaInfo>': Option<ParaInfo>;
'Vec<ParaInfo>': Vec<ParaInfo>;
ParaPastCodeMeta: ParaPastCodeMeta;
'Option<ParaPastCodeMeta>': Option<ParaPastCodeMeta>;
'Vec<ParaPastCodeMeta>': Vec<ParaPastCodeMeta>;
ParachainDispatchOrigin: ParachainDispatchOrigin;
'Option<ParachainDispatchOrigin>': Option<ParachainDispatchOrigin>;
'Vec<ParachainDispatchOrigin>': Vec<ParachainDispatchOrigin>;
@@ -1080,9 +1112,15 @@ declare module '@polkadot/types/types/registry' {
Retriable: Retriable;
'Option<Retriable>': Option<Retriable>;
'Vec<Retriable>': Vec<Retriable>;
SigningContext: SigningContext;
'Option<SigningContext>': Option<SigningContext>;
'Vec<SigningContext>': Vec<SigningContext>;
SlotRange: SlotRange;
'Option<SlotRange>': Option<SlotRange>;
'Vec<SlotRange>': Vec<SlotRange>;
Statement: Statement;
'Option<Statement>': Option<Statement>;
'Vec<Statement>': Vec<Statement>;
SubId: SubId;
'Compact<SubId>': Compact<SubId>;
'Option<SubId>': Option<SubId>;
@@ -1090,9 +1128,15 @@ declare module '@polkadot/types/types/registry' {
UpwardMessage: UpwardMessage;
'Option<UpwardMessage>': Option<UpwardMessage>;
'Vec<UpwardMessage>': Vec<UpwardMessage>;
ValidationCode: ValidationCode;
'Option<ValidationCode>': Option<ValidationCode>;
'Vec<ValidationCode>': Vec<ValidationCode>;
ValidityAttestation: ValidityAttestation;
'Option<ValidityAttestation>': Option<ValidityAttestation>;
'Vec<ValidityAttestation>': Vec<ValidityAttestation>;
ValidatorSignature: ValidatorSignature;
'Option<ValidatorSignature>': Option<ValidatorSignature>;
'Vec<ValidatorSignature>': Vec<ValidatorSignature>;
WinningDataEntry: WinningDataEntry;
'Option<WinningDataEntry>': Option<WinningDataEntry>;
'Vec<WinningDataEntry>': Vec<WinningDataEntry>;
@@ -1651,6 +1695,9 @@ declare module '@polkadot/types/types/registry' {
KeyValueOption: KeyValueOption;
'Option<KeyValueOption>': Option<KeyValueOption>;
'Vec<KeyValueOption>': Vec<KeyValueOption>;
ReadProof: ReadProof;
'Option<ReadProof>': Option<ReadProof>;
'Vec<ReadProof>': Vec<ReadProof>;
RuntimeVersionApi: RuntimeVersionApi;
'Option<RuntimeVersionApi>': Option<RuntimeVersionApi>;
'Vec<RuntimeVersionApi>': Vec<RuntimeVersionApi>;
+42
View File
@@ -0,0 +1,42 @@
// Copyright 2017-2020 @polkadot/types 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 { TypeRegistry } from '../create/registry';
import Linkage from './Linkage';
const registry = new TypeRegistry();
describe('Linkage', (): void => {
it('decodes with ValidatorPrefs', (): void => {
const LINKA = { next: '5GznmRvdi5htUJKnMSWJgJUzSJJXSvWuHRSEdyUbHJZDNcwU', previous: null };
const PREFS = { commission: '100,000,000' };
// prefs sanity check
expect(
registry.createType(
'ValidatorPrefs',
'0x0284d717'
).toHuman()
).toEqual(PREFS);
// linkage sanity checks
expect(
new Linkage(registry, 'AccountId', '0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36').toHuman()
).toEqual(LINKA);
expect(
registry.createType(
'Linkage<AccountId>' as any,
'0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
).toHuman()
).toEqual(LINKA);
// actual check
expect(
registry.createType(
'(ValidatorPrefs, Linkage<AccountId>)' as any,
'0x0284d7170001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
).toHuman()
).toEqual([PREFS, LINKA]);
});
});
+2
View File
@@ -24,6 +24,8 @@ export default class Linkage<T extends Codec> extends Struct {
// eslint-disable-next-line sort-keys
next: Option.with(Type)
}, value);
console.error([...this.entries()]);
}
public static withKey<O extends Codec> (Type: Constructor | keyof InterfaceTypes): Constructor<Linkage<O>> {
+2 -2
View File
@@ -60,7 +60,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
} else if (isU8a(value)) {
return value.length === 0
? []
: decodeSetNumber(setValues, u8aToBn(value.subarray(0, byteLength), { isLe: false }));
: decodeSetNumber(setValues, u8aToBn(value.subarray(0, byteLength), { isLe: true }));
} else if (value instanceof Set || Array.isArray(value)) {
const input = Array.isArray(value)
? value
@@ -230,7 +230,7 @@ export default class CodecSet extends Set<string> implements Codec {
public toU8a (isBare?: boolean): Uint8Array {
return bnToU8a(this.valueEncoded, {
bitLength: this.#byteLength * 8,
isLe: false
isLe: true
});
}
}
@@ -43,6 +43,10 @@ function encodeWithParams (typeDef: Pick<TypeDef, any>, outer = typeDef.displayN
}
}
function encodeDoNotConstruct ({ displayName }: TypeDef): string {
return `DoNotEncode<${displayName}>`;
}
function encodeSubTypes (sub: TypeDef[], asEnum?: boolean): string {
const inner = sub.reduce(
(result: Record<string, string>, type: TypeDef): Record<string, string> => {
@@ -122,6 +126,7 @@ const encoders: Record<TypeDefInfo, (typeDef: TypeDef) => string> = {
[TypeDefInfo.BTreeMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'BTreeMap'),
[TypeDefInfo.BTreeSet]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'BTreeSet'),
[TypeDefInfo.Compact]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Compact'),
[TypeDefInfo.DoNotConstruct]: (typeDef: TypeDef): string => encodeDoNotConstruct(typeDef),
[TypeDefInfo.Enum]: (typeDef: TypeDef): string => encodeEnum(typeDef),
[TypeDefInfo.HashMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'HashMap'),
[TypeDefInfo.Int]: (typeDef: TypeDef): string => encodeUInt(typeDef, 'Int'),
@@ -33,6 +33,6 @@ describe('getTypeClass', (): void => {
getTypeClass(registry, typeDef);
expect(spy).toHaveBeenCalledWith('Unable to resolve type ABC, it will fail on constrution');
expect(spy).toHaveBeenCalledWith('Unable to resolve type ABC, it will fail on construction');
});
});
+6 -1
View File
@@ -23,6 +23,8 @@ import U8aFixed, { BitLength as U8aFixedBitLength } from '../codec/U8aFixed';
import UInt from '../codec/UInt';
import Vec from '../codec/Vec';
import VecFixed from '../codec/VecFixed';
import DoNotConstruct from '../primitive/DoNotConstruct';
import { getTypeDef } from './getTypeDef';
export function createClass<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K): Constructor<FromReg<T, K>> {
@@ -97,6 +99,8 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
[TypeDefInfo.Compact]: (registry: Registry, value: TypeDef): Constructor => Compact.with(getSubType(value)),
[TypeDefInfo.DoNotConstruct]: (registry: Registry, value: TypeDef): Constructor => DoNotConstruct.with(value.displayName),
[TypeDefInfo.Enum]: (registry: Registry, value: TypeDef): Constructor => Enum.with(getTypeClassMap(value)),
[TypeDefInfo.HashMap]: (registry: Registry, value: TypeDef): Constructor => createHashMap(value, HashMap),
@@ -106,7 +110,8 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
// We have circular deps between Linkage & Struct
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => {
const type = `Option<${getSubType(value)}>`;
const Clazz = Struct.with({ next: type, previous: type } as any);
// eslint-disable-next-line sort-keys
const Clazz = Struct.with({ previous: type, next: type } as any);
ClassOf.prototype.toRawType = function (): string {
return `Linkage<${this.next.toRawType(true)}>`;
@@ -95,6 +95,14 @@ describe('createType', (): void => {
).toThrow('UInt<20>: Only support for UInt<bitLength>, where length <= 8192 and a power of 8');
});
it('fails on creation of DoNotConstruct', (): void => {
const Clazz = createClass(registry, 'DoNotConstruct<UnknownSomething>');
expect(
() => new Clazz(registry)
).toThrow('Cannot construct unknown type UnknownSomething');
});
it('allows creation of a [u8; 8]', (): void => {
expect(
createTypeUnsafe(registry, '[u8; 8]', [[0x12, 0x00, 0x23, 0x00, 0x45, 0x00, 0x67, 0x00]]).toHex()
+3 -3
View File
@@ -54,13 +54,13 @@ function initType<T extends Codec = Codec, K extends string = string> (registry:
}
// An unsafe version of the `createType` below. It's unsafe because the `type`
// argument here can be any string, which, if not parseable, will yield a
// argument here can be any string, which, when it cannot parse, will yield a
// runtime error.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createTypeUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K, params: any[] = [], isPedantic?: boolean): T {
try {
// Circle back to isPedenatic when it handles all cases 100% - as of now,
// it provides false wraning which is more hinderance than help
// Circle back to isPedantic when it handles all cases 100% - as of now,
// it provides false warning which is more hinderance than help
return initType(registry, createClass<T, K>(registry, type), params); // , isPedantic);
} catch (error) {
throw new Error(`createType(${type}):: ${error.message}`);
+11 -1
View File
@@ -119,6 +119,15 @@ function _decodeUInt (value: TypeDef, type: string, subType: string): TypeDef {
return _decodeInt(value, type, subType, 'UInt');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function _decodeDoNotConstruct (value: TypeDef, type: string, _: string): TypeDef {
const NAME_LENGTH = 'DoNotConstruct'.length;
value.displayName = type.substr(NAME_LENGTH + 1, type.length - NAME_LENGTH - 1 - 1);
return value;
}
function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, any?]): boolean {
if (type.substr(0, start.length) !== start) {
return false;
@@ -138,7 +147,8 @@ const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: str
['HashMap<', '>', TypeDefInfo.HashMap, _decodeTuple],
['Int<', '>', TypeDefInfo.Int, _decodeInt],
['Result<', '>', TypeDefInfo.Result, _decodeTuple],
['UInt<', '>', TypeDefInfo.UInt, _decodeUInt]
['UInt<', '>', TypeDefInfo.UInt, _decodeUInt],
['DoNotConstruct<', '>', TypeDefInfo.DoNotConstruct, _decodeDoNotConstruct]
];
const wrappedExtraction: [string, string, TypeDefInfo][] = [
+2 -2
View File
@@ -7,9 +7,9 @@ import { Codec, Constructor } from '../types';
import { isChildClass } from '@polkadot/util';
import Struct from '../codec/Struct';
import DoNotConstruct from '../primitive/DoNotConstruct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Unconstructable from '../primitive/Unconstructable';
import { TypeRegistry } from './registry';
describe('TypeRegistry', (): void => {
@@ -29,7 +29,7 @@ describe('TypeRegistry', (): void => {
expect(Type).toBeDefined();
// eslint-disable-next-line no-prototype-builtins
expect(isChildClass(Unconstructable, Type));
expect(isChildClass(DoNotConstruct, Type));
});
it('can register single type', (): void => {
+4 -4
View File
@@ -13,7 +13,7 @@ import { assert, formatBalance, isFunction, isString, isU8a, isUndefined, string
import Raw from '../codec/Raw';
import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '../extrinsic/signedExtensions';
import { EventData } from '../generic/Event';
import Unconstructable from '../primitive/Unconstructable';
import DoNotConstruct from '../primitive/DoNotConstruct';
import { createClass, getTypeClass } from './createClass';
import { createType } from './createType';
import { getTypeDef } from './getTypeDef';
@@ -194,10 +194,10 @@ export class TypeRegistry implements Registry {
if (definition) {
BaseType = createClass(this, definition);
} else if (withUnknown) {
console.warn(`Unable to resolve type ${name}, it will fail on constrution`);
console.warn(`Unable to resolve type ${name}, it will fail on construction`);
this.#unknownTypes.set(name, true);
BaseType = Unconstructable.with(name);
BaseType = DoNotConstruct.with(name);
}
if (BaseType) {
@@ -319,7 +319,7 @@ export class TypeRegistry implements Registry {
const unknown = findUnknownExtensions(this.#metadataExtensions);
if (unknown.length) {
console.warn(`Unknown signed extensions [${unknown.join(', ')}] found, treating them as no-efect`);
console.warn(`Unknown signed extensions ${unknown.join(', ')} found, treating them as no-efect`);
}
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ interface SanitizeOptions {
allowNamespaces?: boolean;
}
const ALLOWED_BOXES = ['BTreeMap', 'BTreeSet', 'Compact', 'HashMap', 'Int', 'Linkage', 'Result', 'Option', 'UInt', 'Vec'];
const ALLOWED_BOXES = ['BTreeMap', 'BTreeSet', 'Compact', 'DoNotConstruct', 'HashMap', 'Int', 'Linkage', 'Result', 'Option', 'UInt', 'Vec'];
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
const mappings: Mapper[] = [
+1
View File
@@ -26,6 +26,7 @@ export enum TypeDefInfo {
HashMap,
Int,
UInt,
DoNotConstruct,
// anything not fully supported (keep this as the last entry)
Null
}
@@ -16,5 +16,9 @@ export default {
RestrictFunctionality: {
extra: {},
types: {}
},
ValidateDoubleVoteReports: {
extra: {},
types: {}
}
} as ExtDef;
-46
View File
@@ -1,46 +0,0 @@
// Copyright 2017-2020 @polkadot/types 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 { TypeRegistry } from '../create';
import json3 from '../json/Header.003.json';
import block1 from '../json/SignedBlock.003.00.json';
import Digest from './Digest';
describe('Digest', (): void => {
const registry = new TypeRegistry();
it('has the correct JSON representation', (): void => {
const digest = new Digest(registry, json3.result.digest);
expect(digest.toJSON()).toEqual(json3.result.digest);
});
it('decodes logs with consensus', (): void => {
const digest = new Digest(registry, json3.result.digest);
expect(digest.logs.length).toEqual(1);
const log = digest.logs[0];
expect(log.type).toBe('Consensus');
expect(log.value.toJSON()).toEqual([
1634891105,
'0x69c97e0f00000000479c09f7ace12ed3e1af2dba6cca6831e257e80feef56c7474d6c69bae6f4e8a6e0045a87afe14296992c38b7d55abcbe617c441cd35e8667abbcb1678f31802'
]);
});
it('filters logs, excluding items', (): void => {
const logs = new Digest(registry, block1.result.block.header.digest).logsWith('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('PreRuntime');
});
it('filters logs, including items', (): void => {
const logs = new Digest(registry, block1.result.block.header.digest).logsWithout('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('Seal');
});
});
-52
View File
@@ -1,52 +0,0 @@
// Copyright 2017-2020 @polkadot/types 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 { DigestItem } from '../interfaces/runtime';
import { AnyJson, Registry } from '../types';
import Struct from '../codec/Struct';
import Vec from '../codec/Vec';
/**
* @name Digest
* @description
* A [[Header]] Digest
*/
export default class Digest extends Struct {
constructor (registry: Registry, value: any) {
super(registry, {
logs: 'Vec<DigestItem>'
}, value);
}
/**
* @description The [[DigestItem]] logs
*/
public get logs (): Vec<DigestItem> {
return this.get('logs') as Vec<DigestItem>;
}
/**
* @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
*/
public logsWith (...include: string[]): Vec<DigestItem> {
return this.logs.filter(({ type }): boolean => include.includes(type)) as Vec<DigestItem>;
}
/**
* @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
*/
public logsWithout (...exclude: string[]): Vec<DigestItem> {
return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vec<DigestItem>;
}
/**
* @desrcript The JSON representation as it goes over RPC
*/
public toJSON (): AnyJson {
return {
logs: this.logs.map((log): string => log.toHex())
};
}
}
-16
View File
@@ -1,16 +0,0 @@
// Copyright 2017-2020 @polkadot/types 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 { TypeRegistry } from '../create';
import Origin from './Origin';
describe('Origin', (): void => {
const registry = new TypeRegistry();
it('does not allow construction', (): void => {
expect(
(): Origin => new Origin(registry)
).toThrow(/placeholder/);
});
});
-21
View File
@@ -1,21 +0,0 @@
// Copyright 2017-2020 @polkadot/types 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 { Registry } from '../types';
import Null from '../primitive/Null';
/**
* @name Origin
* @description
* Where Origin occurs, it should be ignored as an internal-only value, so it should
* never actually be constructed
*/
export default class Origin extends Null {
constructor (registry: Registry) {
super(registry);
throw new Error('Origin should not be constructed, it is only a placeholder for compatibility');
}
}
-2
View File
@@ -8,7 +8,5 @@ export { default as GenericAddress } from './Address';
export { default as GenericBlock } from './Block';
export { default as GenericCall } from './Call';
export { default as GenericConsensusEngineId } from './ConsensusEngineId';
export { default as GenericDigest } from './Digest';
export { default as GenericEvent } from './Event';
export { default as GenericOrigin } from './Origin';
export { default as GenericVote } from './Vote';
+2 -2
View File
@@ -17,8 +17,8 @@ import * as definitions from './interfaces/definitions';
const UNCONSTRUCTABLE = [
'ExtrinsicPayloadUnknown', 'GenericExtrinsicPayloadUnknown',
'ExtrinsicUnknown', 'GenericExtrinsicUnknown',
'GenericOrigin', 'Origin',
'Unconstructable',
'DoNotConstruct',
'Origin',
'usize'
].map((v): string => v.toLowerCase());
@@ -22,12 +22,12 @@ describe('IdentityFields', (): void => {
it('encodes to a valid u8a value', (): void => {
expect(
registry.createType('IdentityFields', ['Display', 'Legal']).toU8a()
).toEqual(new Uint8Array([0, 0, 0, 0, 0, 0, 0, 3]));
).toEqual(new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0]));
});
it('decodes from a u8a', (): void => {
expect(
registry.createType('IdentityFields', new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1 + 2 + 64])).toHuman()
registry.createType('IdentityFields', new Uint8Array([1 + 2 + 64, 0, 0, 0, 0, 0, 0, 0])).toHuman()
).toEqual(['Display', 'Legal', 'Image']);
});
});
@@ -35,6 +35,19 @@ export default {
},
CollatorId: 'H256',
CollatorSignature: 'Signature',
DoubleVoteReport: {
identity: 'ValidatorId',
first: 'DoubleVoteReportStatement',
second: 'DoubleVoteReportStatement',
proof: 'DoubleVoteReportProof',
signingContext: 'SigningContext'
},
// session::historical::Proof
DoubleVoteReportProof: {
session: 'SessionIndex',
trieNodes: 'Vec<Bytes>'
},
DoubleVoteReportStatement: '(Statement, ValidatorSignature)',
EgressQueueRoot: '(ParaId, Hash)',
HeadData: 'Bytes',
IncomingParachainDeploy: {
@@ -63,6 +76,10 @@ export default {
ParaInfo: {
scheduling: 'ParaScheduling'
},
ParaPastCodeMeta: {
upgradeTimes: 'Vec<BlockNumber>',
lastPruned: 'Option<BlockNumber>'
},
ParachainDispatchOrigin: {
_enum: ['Signed', 'Parachain']
},
@@ -75,6 +92,10 @@ export default {
WithRetries: 'u32'
}
},
SigningContext: {
sessionIndex: 'SessionIndex',
parentHash: 'Hash'
},
SlotRange: {
_enum: [
'ZeroZero', // 0
@@ -89,20 +110,30 @@ export default {
'ThreeThree' // 9
]
},
Statement: {
_enum: {
// This Null is not in the original, however indexes start at 1
Never: 'Null',
Candidate: 'Hash',
Valid: 'Hash',
Invalid: 'Hash'
}
},
SubId: 'u32',
UpwardMessage: {
origin: 'ParachainDispatchOrigin',
data: 'Bytes'
},
ValidationCode: 'Bytes',
ValidityAttestation: {
_enum: {
// This Null is not in the original, however indexes start at 1, so add a
// placeholder in the first position (which is basically non-valid)
None: 'Null',
Implicit: 'CollatorSignature', // 1
Explicit: 'CollatorSignature' // 2
// This Null is not in the original, however indexes start at 1
Never: 'Null',
Implicit: 'ValidatorSignature', // 1
Explicit: 'ValidatorSignature' // 2
}
},
ValidatorSignature: 'Signature',
WinningDataEntry: '(AccountId, ParaIdOf, BalanceOf)',
WinningData: '[WinningDataEntry; 10]'
}

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