Compare commits

...
286 Commits
Author SHA1 Message Date
Github Actions 4fd74a04c8 [CI Skip] 1.6.2
skip-checks: true
2020-03-12 14:03:53 +00:00
Jaco Greeff 421594b0eb Fix .at check, disable (release 1.6.2) (#2034)
* Fix .at check, disable (release 1.6.2)

* Remove isAt (keep at revert only)

* Grrr....

* yarn installl (really need to add this to version bump script)
2020-03-12 14:53:25 +01:00
Github Actions 2e79c25da1 [CI Skip] 1.6.1
skip-checks: true
2020-03-12 09:10:00 +00:00
Jaco Greeff ca2a313aec 1.6 (#2031)
* 1.6 CHANGELOG

* 1.6

* yarn
2020-03-12 09:57:09 +01:00
Github Actions 693315dad3 [CI Skip] 1.6.0-beta.30
skip-checks: true
2020-03-12 08:22:52 +00:00
Jaco Greeff c2f9ef7ca8 Add .keys on storage entries (#2032)
* Add .keys on storage entries

* Pass isOptional to storage type unwrap

* Linked maps TS types
2020-03-12 09:12:11 +01:00
Github Actions fc477b98bd [CI Skip] 1.6.0-beta.29
skip-checks: true
2020-03-12 06:41:19 +00:00
Jaco Greeff b8cdfd226a Validate storage args (#1507)
* Validate storage args

* Fix linting

* Update imports

* Update type extraction

* Move storage extraction to util

* Re-add CHANGELOG entry

* Add DoubleMap tests

* Adjust error for linked

* formatting

* Split map/doublemap

* Cleanups

* Update error sigs

* Just join
2020-03-12 07:29:18 +01:00
Github Actions a5725d7bd6 [CI Skip] 1.6.0-beta.28
skip-checks: true
2020-03-11 16:12:55 +00:00
Jaco Greeff 8995ef6ae2 dedupKeyPrefix as const 2020-03-11 17:01:07 +01:00
Github Actions 742baa3dad [CI Skip] 1.6.0-beta.27
skip-checks: true
2020-03-11 15:10:58 +00:00
Jaco Greeff 3a37bf1e6b Add multi variants for derive staking query & rewards (#2029) 2020-03-11 15:59:36 +01:00
Github Actions f4b51f6311 [CI Skip] 1.6.0-beta.26
skip-checks: true
2020-03-11 11:44:04 +00:00
Jaco Greeff a09fc51693 Add stakerRewards for available reward calcs (#2028) 2020-03-11 12:33:12 +01:00
Jaco Greeff 1d8b6a79ef Rework rpc.queryStorage to return [Hash, Codec[]][] (#2025) 2020-03-11 12:21:09 +01:00
Dylan Galea 164a1b6867 Updated users of the polkadot-js/api (#2027)
* Update README.md

Updated the README.md to include the PANIC for Polkadot, and Polkadot API Server projects as users.

* Update README.md

Fixed links.
2020-03-11 12:20:16 +01:00
Keith Ingram 032f2dc040 Remove parachains.watermark (#2026) 2020-03-11 12:18:47 +01:00
Github Actions 3dbe33378c [CI Skip] 1.6.0-beta.25
skip-checks: true
2020-03-11 08:22:30 +00:00
Jaco Greeff bb08ac4a28 Align CHANGELOG, bump @polkadot/util (#2024) 2020-03-11 09:11:29 +01:00
Github Actions 4656d32e22 [CI Skip] 1.6.0-beta.24
skip-checks: true
2020-03-10 18:55:55 +00:00
Jaco Greeff 60c982ed95 Fix range & entries with Option decoding (#2023) 2020-03-10 19:44:50 +01:00
Github Actions cacafab912 [CI Skip] 1.6.0-beta.23
skip-checks: true
2020-03-10 17:07:44 +00:00
Jaco Greeff 99d4806a0d Enable new indexes queries (#2022)
* Enable new indexes queries

* update mock for state_getKeys
2020-03-10 17:56:20 +01:00
Github Actions 59a194a48d [CI Skip] 1.6.0-beta.22
skip-checks: true
2020-03-10 14:17:03 +00:00
Jaco Greeff d818f61dc8 Support new map nextKeys in derives (#2021)
* Support new map nextKeys in derives

* Update packages/api-derive/src/staking/query.ts
2020-03-10 15:07:02 +01:00
Github Actions f1cbfff5a6 [CI Skip] 1.6.0-beta.21
skip-checks: true
2020-03-10 12:27:53 +00:00
Jaco Greeff 92cdc6c840 Query exposure via clipped (#2020) 2020-03-10 13:16:15 +01:00
Github Actions 1ff864ea2f [CI Skip] 1.6.0-beta.20
skip-checks: true
2020-03-10 11:20:22 +00:00
Jaco Greeff 071b5ba7cb Re-add erasRewards (#2019) 2020-03-10 12:09:18 +01:00
Github Actions 2e6d89a093 [CI Skip] 1.6.0-beta.19
skip-checks: true
2020-03-10 07:32:04 +00:00
Jaco Greeff 049a1a59f5 Rework eras* calls with minimum information (#2018) 2020-03-10 08:20:54 +01:00
Github Actions 201098e9f6 [CI Skip] 1.6.0-beta.18
skip-checks: true
2020-03-09 22:07:14 +00:00
Jaco Greeff 423227d385 Merge branch 'master' of github.com:polkadot-js/api 2020-03-09 22:57:13 +01:00
Jaco Greeff c1facd8b1c memo for range & entries 2020-03-09 22:57:09 +01:00
Github Actions 842d371699 [CI Skip] 1.6.0-beta.17
skip-checks: true
2020-03-09 20:52:41 +00:00
Jaco Greeff bcbd4b8d40 linked maps with getStorage only 2020-03-09 21:42:56 +01:00
Github Actions b526873837 [CI Skip] 1.6.0-beta.16
skip-checks: true
2020-03-09 19:19:28 +00:00
Jaco Greeff 6f85c6783e Update .123trigger 2020-03-09 20:07:29 +01:00
Github Actions 672983f6c1 [CI Skip] 1.6.0-beta.15
skip-checks: true
2020-03-09 19:01:22 +00:00
Jaco Greeff 3ee3fb05cc Use first() for entries and linked maps 2020-03-09 19:50:21 +01:00
Github Actions 8ff32d9c1e [CI Skip] 1.6.0-beta.14
skip-checks: true
2020-03-09 17:54:21 +00:00
Jaco Greeff 8ad3d35dd2 Lock all indeeds locks all 2020-03-09 18:44:30 +01:00
Github Actions cb5fdc9078 [CI Skip] 1.6.0-beta.13
skip-checks: true
2020-03-09 13:32:56 +00:00
Jaco Greeff 77d894dd00 reset identityOf 2020-03-09 14:21:06 +01:00
Jaco Greeff 5b40d95b0f Disbale identity (#2016) 2020-03-09 14:12:52 +01:00
Github Actions 385d157f3f [CI Skip] 1.6.0-beta.12
skip-checks: true
2020-03-09 09:23:23 +00:00
Jaco Greeff 81a2a51610 Expose eraReward on derives (#2015) 2020-03-09 10:14:45 +01:00
Github Actions ff8383c5ed [CI Skip] 1.6.0-beta.11
skip-checks: true
2020-03-09 07:38:29 +00:00
Jaco Greeff ca9f671553 Re-format jsonrpc errors (#2014) 2020-03-09 08:27:00 +01:00
Github Actions eb17de0888 [CI Skip] 1.6.0-beta.10
skip-checks: true
2020-03-08 14:32:37 +00:00
Jaco Greeff 110c9d199d Add 'everything' on balance format with max 2020-03-08 15:22:06 +01:00
Github Actions b5cc8f193e [CI Skip] 1.6.0-beta.9
skip-checks: true
2020-03-08 12:30:09 +00:00
Jaco Greeff abebe9ef43 unwrapOr(undefined) for subs 2020-03-08 13:20:05 +01:00
Github Actions e55f69a009 [CI Skip] 1.6.0-beta.8
skip-checks: true
2020-03-08 12:08:20 +00:00
Jaco Greeff 9bf854445c Fix entries values decoding (#2011)
* Fix entries values decoding

* Linting

* Properly unwrap storage subs
2020-03-08 12:57:03 +01:00
Github Actions 17f7e4b753 [CI Skip] 1.6.0-beta.7
skip-checks: true
2020-03-08 08:39:09 +00:00
Jaco Greeff 0a6c6ec4c5 Combine points into stakerRewards (#2008)
* Combine points into stakerRewards

* Bump dev
2020-03-08 09:26:54 +01:00
Github Actions 7456113cef [CI Skip] 1.6.0-beta.6
skip-checks: true
2020-03-08 08:24:46 +00:00
Jaco Greeff 7051e20d59 StorageKey map decoding test (#2009) 2020-03-08 09:13:18 +01:00
Github Actions 79dba43f0f [CI Skip] 1.6.0-beta.5
skip-checks: true
2020-03-07 09:49:05 +00:00
Jaco Greeff 6bb421dac6 Fix StorageKey args throw 2020-03-07 10:37:28 +01:00
Github Actions 0ce28c519f [CI Skip] 1.6.0-beta.4
skip-checks: true
2020-03-06 21:00:28 +00:00
Jaco Greeff cdde702db7 Cover all hashers in map/doublemap key decoding (#2007) 2020-03-06 21:49:09 +01:00
Github Actions 6b4a76b54b [CI Skip] 1.6.0-beta.3
skip-checks: true
2020-03-06 15:28:04 +00:00
Jaco Greeff 57e2a9dc14 No BalanceLock override for Polkadot 2020-03-06 16:18:18 +01:00
Github Actions 798f1e6e91 [CI Skip] 1.6.0-beta.2
skip-checks: true
2020-03-06 15:10:40 +00:00
Jaco Greeff 0e264a029e Polkadot StakingLedger 2020-03-06 15:58:46 +01:00
Github Actions 8745c059f7 [CI Skip] 1.6.0-beta.1
skip-checks: true
2020-03-06 12:57:58 +00:00
Jaco Greeff adee447cd0 Add .args to decoded StorageKeys (#2004)
* Add .args to decoded StorageKeys

* Small opts

* Formatting
2020-03-06 13:47:40 +01:00
Github Actions 63c22414ce [CI Skip] 1.6.0-beta.0
skip-checks: true
2020-03-06 10:18:07 +00:00
Jaco Greeff 89992ea03e Era exposure cleanups via .entries (#2003) 2020-03-06 11:06:10 +01:00
Github Actions e9d24c3213 [CI Skip] 1.5.1
skip-checks: true
2020-03-06 07:13:38 +00:00
Jaco Greeff 71b33e2e42 1.5 (#2001)
* 1.5

* Util bumps

* Install after bump
2020-03-06 08:03:12 +01:00
Github Actions 023bc5aaa6 [CI Skip] 1.5.0-beta.33
skip-checks: true
2020-03-05 18:47:51 +00:00
Jaco Greeff 30d4d8c3a5 Bump metadata (#2000)
* Bump metadata

* Fix lint & docs
2020-03-05 19:36:48 +01:00
Github Actions 6963e40074 [CI Skip] 1.5.0-beta.32
skip-checks: true
2020-03-05 15:46:12 +00:00
Jaco Greeff 2b6aa7972d Update metadata for current Polkadot/Substrate (#1999)
* Remove old Polkadot metadata (current only, Substrate tests cover)

* Substrate & Polkadot metadata

* VotesTo230
2020-03-05 16:37:27 +01:00
Github Actions 4908c1c82a [CI Skip] 1.5.0-beta.31
skip-checks: true
2020-03-05 14:48:00 +00:00
Jaco Greeff aaf1273794 Additional derives for new staking points & rewards (#1994)
* Additional derives for new staking points & rewards

* Fix method name

* StakingLedger update

* Expand derives

* Cleanups

* Cleanup Compact decode

* Cleanup derives

* Update CHANGELOG

* Split types
2020-03-05 15:37:34 +01:00
Jaco Greeff 62ef032594 Cleanup generic description (#1993) 2020-03-05 15:36:58 +01:00
Github Actions 3652436125 [CI Skip] 1.5.0-beta.30
skip-checks: true
2020-03-05 06:11:38 +00:00
Jaco Greeff e947c638ff Fix remove deprecated api 'Observable.create' (#1998) 2020-03-05 07:00:59 +01:00
Github Actions 6926a30760 [CI Skip] 1.5.0-beta.29
skip-checks: true
2020-03-03 15:24:21 +00:00
Jaco Greeff 4feed1db5d Bump metadata (incl. lazy payouts) (#1995)
* Bump metadata (inl. lazy payouts)

* Fix currentElected via generic

* Update tests for latest metadata
2020-03-03 16:13:28 +01:00
Github Actions d462a1d6c0 [CI Skip] 1.5.0-beta.28
skip-checks: true
2020-03-03 07:59:02 +00:00
Jaco Greeff 0e297c6779 Add rpc.raw interface, convert RPC to Augmented wrappers (#1990)
* Add rpc.raw interface, convert RPC to Augmented

* Augmentaton attempt...

* Failing test

* Fix augmentation

* Cleanup linting

* Expose .raw on decorated RPCs

* .raw into CHANGELOG

* Stray eslint overrides
2020-03-03 08:49:24 +01:00
Github Actions e07636675f [CI Skip] 1.5.0-beta.27
skip-checks: true
2020-03-02 21:44:40 +00:00
Jaco Greeff 69020faaab typos 2020-03-02 22:32:38 +01:00
Github Actions 4059682ec2 [CI Skip] 1.5.0-beta.26
skip-checks: true
2020-03-02 21:06:08 +00:00
Jaco Greeff eaf5216d49 Extrinsic customization cleanups (#1991) 2020-03-02 21:55:29 +01:00
Github Actions 47142448d7 [CI Skip] 1.5.0-beta.25
skip-checks: true
2020-03-02 15:02:40 +00:00
Jaco Greeff 586c90208c Add typeAlias to API construction options (#1989) 2020-03-02 15:52:14 +01:00
Github Actions 7e0283d7c0 [CI Skip] 1.5.0-beta.24
skip-checks: true
2020-03-02 08:22:17 +00:00
Jaco Greeff d9ee39f367 Warn on type override (#1985) 2020-03-02 09:12:25 +01:00
Jaco Greeff af1a3385cc Raise error on parsing errors (#1987) 2020-03-02 09:09:27 +01:00
Github Actions 0d58c77de0 [CI Skip] 1.5.0-beta.23
skip-checks: true
2020-03-01 23:17:36 +00:00
Jaco Greeff b588238836 Handle import module name conflicts (#1983) 2020-03-02 00:07:34 +01:00
Github Actions 3e702b8629 [CI Skip] 1.5.0-beta.22
skip-checks: true
2020-03-01 08:51:46 +00:00
Jaco Greeff 62f46359e2 Update enums with tuple members, regen (#1982) 2020-03-01 09:41:03 +01:00
Github Actions fef349880a [CI Skip] 1.5.0-beta.21
skip-checks: true
2020-03-01 08:22:48 +00:00
Jaco Greeff f59cb12ec7 Add .range([from, to?], ...args) on storage queries (#1979)
* Add .between(from, to) ot storage queries

* between -> range

* CHANGELOG

* checkTypes.manual

* Tested as working
2020-03-01 09:12:17 +01:00
Github Actions 96700eef5d [CI Skip] 1.5.0-beta.20
skip-checks: true
2020-03-01 07:21:45 +00:00
Jeremías Díaz 7316f68cdf Support tuples in enums (#1981)
* fix: support tuples as enum members in typegen

* fix: add tuple case
2020-03-01 08:11:36 +01:00
Github Actions 0078062d33 [CI Skip] 1.5.0-beta.19
skip-checks: true
2020-02-29 13:12:23 +00:00
Jaco Greeff e8cd8c9448 Minify yarn plugins (#1978)
* Minify yarn plugins

* Bump dev
2020-02-29 14:01:23 +01:00
Github Actions 58fa1062eb [CI Skip] 1.5.0-beta.18
skip-checks: true
2020-02-29 09:40:10 +00:00
Jaco Greeff bc2b0d513c Doc links, typos, publish (#1977) 2020-02-29 10:28:47 +01:00
Github Actions 8af58fcea3 [CI Skip] 1.5.0-beta.17
skip-checks: true
2020-02-29 08:48:21 +00:00
Jaco Greeff 180738306b Remove deprecated extrinsic extend docs (confusing) (#1976)
* Remove extrinsic extend

* Example for Address overrides
2020-02-29 09:38:11 +01:00
Github Actions efbe9060de [CI Skip] 1.5.0-beta.16
skip-checks: true
2020-02-28 16:17:19 +00:00
Jaco Greeff 5b9b5586d3 Update signature for Promise queryMulti (#1975) 2020-02-28 17:05:38 +01:00
Github Actions 6c174e6634 [CI Skip] 1.5.0-beta.15
skip-checks: true
2020-02-28 13:03:18 +00:00
Jaco Greeff 1c2c86126c Swap to yarn 2 (#1973)
* Swap to yarn 2

* Bump dev

* "@polkadot/typegen": "workspace:packages/typegen"
2020-02-28 13:52:44 +01:00
Github Actions 01f32f2706 [CI Skip] 1.5.0-beta.14
skip-checks: true
2020-02-28 12:48:06 +00:00
Axel Chalon 94608b0c3f Make Enum/Tuple constructor use value directly if instance (#1954)
* Make Enum/Tuple constructor use value directly if instance

* Lint

* Lint
2020-02-28 13:39:11 +01:00
Github Actions 6f581d6122 [CI Skip] 1.5.0-beta.13
skip-checks: true
2020-02-28 10:48:50 +00:00
Jaco Greeff 9fcb5fe348 FAQ entry for "Could not convert" (#1972)
* FAQ entry for "Could not convert"

* Bump dev

* Extend description, bump dev
2020-02-28 11:39:37 +01:00
Github Actions 43e641f6a1 [CI Skip] 1.5.0-beta.12
skip-checks: true
2020-02-27 20:39:17 +00:00
Luke Schoen b182fd2428 fix: Fixes TypeError: Cannot read property 'vesting' of undefined (#1970)
We're converting our chain from PoA to PoS in this PR https://github.com/DataHighway-DHX/node/pull/52/commits/7c8c96939ab6a2b77dd3a2f4bef427e831dafbda

But when I run the chain with those latest changes I got error `TypeError: Cannot read property 'vesting' of undefined` when I tried to go to the "Accounts", "Transfer", or "Extrinsics" app using polkadot.js.org/apps, as explained here https://matrix.to/#/!XOxcnpiHXHhAjJfRFP:matrix.parity.io/$0oidO-aZvsjMRdskB2nig6P_Y4CjH4Gc6TMrl4V7ZB8?via=matrix.parity.io&via=matrix.org&via=matrix.dapp.org.uk

After cloning https://github.com/polkadot-js/apps and debugging the error, I found that this change resolved the error and the error no longer appears when I access those apps
2020-02-27 21:28:41 +01:00
Github Actions af7c17e4bb [CI Skip] 1.5.0-beta.11
skip-checks: true
2020-02-27 17:17:38 +00:00
Jaco Greeff edff4231ff Dec-clutter UInt & Int (#1969) 2020-02-27 18:08:41 +01:00
Github Actions a66b98fece [CI Skip] 1.5.0-beta.10
skip-checks: true
2020-02-27 17:06:47 +00:00
Keith IngramandJaco Greeff 4e2fb23bdf Nullable api.derive.parachains.info (#1968)
* api.derive.registrar.parachains

* remove api parse

* suggestions

* some

* parachains: overview/info

* rm all

* rm all

* refine

* null parachain info

* isNone

* isNone

* isNone

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-02-27 17:57:26 +01:00
Github Actions 2900ad303c [CI Skip] 1.5.0-beta.9
skip-checks: true
2020-02-27 14:11:02 +00:00
Jaco Greeff 4e756704ea Some minor cleanups (#1966)
* Some minor cleanups

* Small additions

* Cleanup ExtrinsicEra decoding

* Minor adjustments

* Remove support for metadata v0 parsing

* Adjust refCountDelay

* refCountDelay comments

* Adjust Metadata tests

* Metadata default creation

* Funky lines

* Cleanup as AccountIdAndIndex

* Some derive returns

* Try and cleanup info extraction
2020-02-27 15:01:20 +01:00
Github Actions efd6c5331d [CI Skip] 1.5.0-beta.8
skip-checks: true
2020-02-27 13:39:24 +00:00
Jaco Greeff 619ef6f8eb Align Bool isEmpty, true when false is wrapped (#1967) 2020-02-27 14:28:27 +01:00
Github Actions 2823504156 [CI Skip] 1.5.0-beta.7
skip-checks: true
2020-02-27 12:45:56 +00:00
Amaury Martiny 370dc86817 Fix ProviderInterfaceCallback type (#1965) 2020-02-27 13:36:26 +01:00
Github Actions ee5628f856 [CI Skip] 1.5.0-beta.6
skip-checks: true
2020-02-27 12:30:12 +00:00
Jaco Greeff a8f2ba8c30 Restore 1.5.0-beta.5 (#1964)
* Restore 1.5.0-beta.5

* Bump dev
2020-02-27 13:20:25 +01:00
Github Actions 24bd513002 [CI Skip] 1.4.2
skip-checks: true
2020-02-27 10:38:28 +00:00
Jaco Greeff f73609103a Real 1.4.2 (root) 2020-02-27 11:28:43 +01:00
Github Actions 206d399258 [CI Skip] 1.5.0-beta.5
skip-checks: true
2020-02-27 10:26:13 +00:00
Jaco Greeff d531dd374f 1.4.2 (#1963)
* 1.4.2

* Actual version bump

* Rework api.tx decoratation (with tests)
2020-02-27 11:16:23 +01:00
Github Actions e199a9b11a [CI Skip] 1.5.0-beta.5
skip-checks: true
2020-02-26 21:22:25 +00:00
Jaco Greeff 0ad8be71f9 Doc around field rename (#1958) 2020-02-26 22:13:39 +01:00
Github Actions 9be9f59b6a [CI Skip] 1.5.0-beta.4
skip-checks: true
2020-02-26 21:10:44 +00:00
Jaco Greeff 5165ce7caf Rework sanitize aliasing (#1957)
* Rework sanitize aliasing

* Allow special alias override (InherentOfflineReport)
2020-02-26 22:02:19 +01:00
Github Actions b00b84e314 [CI Skip] 1.5.0-beta.3
skip-checks: true
2020-02-26 20:38:03 +00:00
Jaco Greeff 85ae6f949b Allow construction of HashMap (#1955)
* Allow construction of HashMap

* WIP... add Map to codec, extend BTreeMap & HashMap from it

* Rework various map tests

* registry.createClass

* createClass in tests
2020-02-26 21:30:38 +01:00
Github Actions e31966496b [CI Skip] 1.5.0-beta.2
skip-checks: true
2020-02-26 15:26:55 +00:00
Jaco Greeff db2ae1324f Update system.networkState types (#1951) 2020-02-26 16:19:33 +01:00
Github Actions b152a67150 [CI Skip] 1.5.0-beta.1
skip-checks: true
2020-02-26 12:38:14 +00:00
Jaco Greeff bdfc582ba5 Fix link to GH source 2020-02-26 13:30:19 +01:00
Github Actions 7a2754109f [CI Skip] 1.5.0-beta.0
skip-checks: true
2020-02-26 11:44:12 +00:00
Jaco Greeff ca76dc170c Add typegen sample (#1950)
* Add typegen sample

* Link to example from types getting started

* cc skip
2020-02-26 12:38:19 +01:00
Github Actions dbfc15ba88 [CI Skip] 1.4.1
skip-checks: true
2020-02-26 11:00:07 +00:00
Jaco Greeff 2d40d370f9 1.4 (#1949) 2020-02-26 11:52:37 +01:00
Github Actions 0728e40bfb [CI Skip] 1.4.0-beta.52
skip-checks: true
2020-02-26 10:32:30 +00:00
Keith Ingram 1a50298ffe Split parachains.derive calls (#1948)
* api.derive.registrar.parachains

* remove api parse

* suggestions

* some

* parachains: overview/info

* rm all

* rm all

* refine
2020-02-26 11:26:04 +01:00
Github Actions 68f2cb5bb2 [CI Skip] 1.4.0-beta.51
skip-checks: true
2020-02-26 10:23:37 +00:00
Jaco Greeff 8598002801 Swap to registry.createType (#1947) 2020-02-26 11:17:11 +01:00
Github Actions 333ff8528b [CI Skip] 1.4.0-beta.50
skip-checks: true
2020-02-25 16:08:21 +00:00
Jaco Greeff c17f93a3ec Update docs for system.account (#1944) 2020-02-25 17:01:41 +01:00
Github Actions 67841a9212 [CI Skip] 1.4.0-beta.49
skip-checks: true
2020-02-25 15:59:45 +00:00
Jaco Greeff 6be6b027cb More private field -> #field adjustments (#1945)
* More private field -> #field adjustments

* Work-around for set.add failures

* Remove FIXME, it is done
2020-02-25 16:53:04 +01:00
Github Actions 6943c9b36d [CI Skip] 1.4.0-beta.48
skip-checks: true
2020-02-25 14:17:45 +00:00
Jaco Greeff 253e48f7bb Return all additional identity fields (#1943) 2020-02-25 15:10:47 +01:00
Github Actions eeaf6118a5 [CI Skip] 1.4.0-beta.47
skip-checks: true
2020-02-25 13:22:44 +00:00
Jaco Greeff c3c77ffe43 Add Option.unwrapOrDefault (#1942)
* Add Option.unwrapOrDefault

* linting

* metadata createType(registry, ...) -> registry.createType(...)

* Linting

* Cleanup tests
2020-02-25 14:15:25 +01:00
Github Actions 71e82aece8 [CI Skip] 1.4.0-beta.46
skip-checks: true
2020-02-25 09:14:49 +00:00
Jaco Greeff a7132b4e9c Fix HEADER(...) in fromChain typegen (#1941) 2020-02-25 10:08:31 +01:00
Github Actions 8acb65931e [CI Skip] 1.4.0-beta.45
skip-checks: true
2020-02-25 08:50:07 +00:00
Jaco Greeff dcf053633b CHANGELOG & small strict adjustments (#1940) 2020-02-25 09:44:13 +01:00
Github Actions 015ade79e6 [CI Skip] 1.4.0-beta.44
skip-checks: true
2020-02-25 08:29:18 +00:00
Jaco Greeff a4f56d3d38 Remove deprecated types (up to metadata V5) (#1939) 2020-02-25 09:22:38 +01:00
Github Actions 73d10a55f1 [CI Skip] 1.4.0-beta.43
skip-checks: true
2020-02-25 07:47:12 +00:00
Jeremías Díaz 2d0ce2ddff Make Strict Mode Strict Again (#1938)
* fix: don't format "unorthodox" query input types

Also add support for tuples in `getSimilarTypes`

* fix: refactor type ignore logic into `formatType`

Had to use a regexp solution because types like `([AccountId | string | Uint8Array, Data | { none: any } | { raw: any } | { blakeTwo256: any } | { sha256: any } | { keccak256: any } | { shaThree256: any } | string | Uint8Array])[]` were not being ignored with the current logic, so they were passed to `getTypeDef` and causing delimiter errors.

* refactor: remove superfluous "FirstKeyType" param

* fix: ignore tuples with structs when formatting

* feat: eliminate all index signatures with --strict

* docs: fix doc generation
2020-02-25 08:40:07 +01:00
Github Actions 775697f51e [CI Skip] 1.4.0-beta.42
skip-checks: true
2020-02-24 21:48:03 +00:00
Jaco Greeff 9690777acb Update .123trigger 2020-02-24 22:41:22 +01:00
Jaco Greeff e7d38a5e59 Update CHANGELOG (#1936) 2020-02-24 22:34:54 +01:00
Jeremías Díaz c6355fb147 fix: don't format "unorthodox" query input types (#1934)
* fix: don't format "unorthodox" query input types

Also add support for tuples in `getSimilarTypes`

* fix: refactor type ignore logic into `formatType`

Had to use a regexp solution because types like `([AccountId | string | Uint8Array, Data | { none: any } | { raw: any } | { blakeTwo256: any } | { sha256: any } | { keccak256: any } | { shaThree256: any } | string | Uint8Array])[]` were not being ignored with the current logic, so they were passed to `getTypeDef` and causing delimiter errors.

* refactor: remove superfluous "FirstKeyType" param
2020-02-24 22:31:18 +01:00
Github Actions d85d9ca930 [CI Skip] 1.4.0-beta.41
skip-checks: true
2020-02-24 19:10:00 +00:00
Jaco Greeff af643401b8 Remove metadata index hack... and add another one (#1935)
* Remove metadata index hack

* Parse v9 and V10 upon failure
2020-02-24 20:03:35 +01:00
Github Actions fcea797c8a [CI Skip] 1.4.0-beta.40
skip-checks: true
2020-02-24 15:59:31 +00:00
Jaco Greeff cbc14cc291 Add new staking types, support derives (#1828)
* Add new staking types

* StakingLedgerTo213 - StakingLedgerTo223

* StakingLedgerTo223 in polkadot (dev)

* Add derive activeEra

* Map Ponts -> RewardPoints

* StakingLedger override CHANGELOG

* Cleanups

* Apparent CC dupes (don't see it, but cleanup useul)

* Cleanup result formatting for indexes

* Map nextElected -> validators

* Fix StakingLedger to current

* Merge CHANGELOG

* Mention derive staking updates

* Mark derive changes as breaking
2020-02-24 16:52:48 +01:00
Jaco Greeff 64aa4dcc1c More metadata clarifications (#1933) 2020-02-24 16:52:00 +01:00
Github Actions 429ea4ca99 [CI Skip] 1.4.0-beta.39
skip-checks: true
2020-02-24 14:08:24 +00:00
Jaco Greeff 86ce696808 Update CHANGELOG (#1932)
* Update CHANGELOG

* typos
2020-02-24 15:01:47 +01:00
Github Actions 57ca9a9c32 [CI Skip] 1.4.0-beta.38
skip-checks: true
2020-02-24 12:35:08 +00:00
Jaco Greeff 70a26e33a7 Docs for createType (#1931) 2020-02-24 13:28:08 +01:00
Github Actions c487094aa7 [CI Skip] 1.4.0-beta.37
skip-checks: true
2020-02-24 08:37:14 +00:00
Jaco Greeff bab79b6473 CHANGELOG 3.8 breaking change (#1930) 2020-02-24 09:30:56 +01:00
Github Actions 586e838788 [CI Skip] 1.4.0-beta.36
skip-checks: true
2020-02-23 14:02:59 +00:00
Jaco Greeff 51cb64ade7 Cleanup api.createType d.ts, add createType to registry (#1929)
* Cleanup api.createType d.ts, add createType to registry

* CHANGELOG
2020-02-23 14:57:30 +01:00
Github Actions d09dcb8282 [CI Skip] 1.4.0-beta.35
skip-checks: true
2020-02-23 12:50:23 +00:00
Jaco Greeff 869f9b7af9 InterfaceTypes -> keyof InterfaceRegistry (#1928)
* InterfaceTypes -> keyof InterfaceRegistry

* Renames
2020-02-23 13:43:37 +01:00
Github Actions a938cb545a [CI Skip] 1.4.0-beta.34
skip-checks: true
2020-02-23 11:54:54 +00:00
Jaco Greeff 553b3df0b2 Augment naming 2020-02-23 12:48:01 +01:00
Jaco Greeff 1fd157364b Use allDefs in augment-types 2020-02-23 12:42:05 +01:00
Github Actions fa7ae72c59 [CI Skip] 1.4.0-beta.33
skip-checks: true
2020-02-23 11:33:12 +00:00
Jaco Greeff 443706a6e0 Extract full interfaceRegistry (#1927)
* Extract full interfaceRegistry

* Move augment to top-level in api & types

* Type augment output

* Update with new augmented paths

* Update RPC path
2020-02-23 12:26:10 +01:00
Github Actions ba462aae8b [CI Skip] 1.4.0-beta.32
skip-checks: true
2020-02-23 10:55:21 +00:00
Jaco Greeff a35da085d6 Augment user type registry (#1926)
* Augment user type registry

* Augment InterfaceRegistry

* Addition api.createType test

* Import '@polkadot/types/interfaceAugment'

* Skip CC on generated

* Move augmentation to full path imports

* Output to augment-*
2020-02-23 11:48:40 +01:00
Github Actions 3d8d2e4988 [CI Skip] 1.4.0-beta.31
skip-checks: true
2020-02-23 09:29:30 +00:00
Jaco Greeff 6c5ef6ecd6 Generation scripts register user types (#1925)
* Generation scripts register user types

* Create augment.ts output

* Remove stray package
2020-02-23 10:22:55 +01:00
Github Actions 3bae45a331 [CI Skip] 1.4.0-beta.30
skip-checks: true
2020-02-22 16:08:46 +00:00
Jaco Greeff 196a0891b8 Use isChildClass & isBigInt from @polkadot/util (#1924)
* Use isChildClass & isBigInt from @polkadot/util

* Allow never

* Bumps

* Common 2.5.1

* Fix overrides

* Remove gh-pages script (in dev)
2020-02-22 17:02:03 +01:00
Github Actions 2a16b04420 [CI Skip] 1.4.0-beta.29
skip-checks: true
2020-02-22 14:00:27 +00:00
Jaco Greeff 790deca695 Update docs for isInBlock (rather late than never) (#1923)
* Update docs for isInBlock (rather late than never)

* Only warn on isInBlock filtering
2020-02-22 14:53:46 +01:00
Github Actions 4ec87dc51c [CI Skip] 1.4.0-beta.28
skip-checks: true
2020-02-22 13:03:37 +00:00
Jaco Greeff 51686f0cd4 Don't clobber global space in WS provider (#1922)
* Don't clbber global space in WS provider

* Re-use getWSClass
2020-02-22 13:56:37 +01:00
Github Actions deddc6dc79 [CI Skip] 1.4.0-beta.27
skip-checks: true
2020-02-22 10:37:34 +00:00
Jaco Greeff 3bf4c3fac5 Adjust class privates via #, where applicable (#1921)
* Adjust class priates via #, where applicable

* Remove stray log

* Cleanup rpc-provider

* Small adjustments

* No private access in tests

* Submittable privates

* Use derive for nonce derivation

* Tweak observers

* Alphabetical privates
2020-02-22 11:29:50 +01:00
Github Actions ccf32a6289 [CI Skip] 1.4.0-beta.26
skip-checks: true
2020-02-21 16:32:43 +00:00
Jaco Greeff 4540495a44 BigInt support (& some TS typing cleanups) (#1919)
* Some TS typing cleanups

* docs building again

* yarn.lock rewrite

* tweaks

* BigInt support

* Checktypes with BigInt

* AccountIndex support for BigInt

* Fix ApiPromise signAsync
2020-02-21 17:26:05 +01:00
Github Actions 429b797b23 [CI Skip] 1.4.0-beta.25
skip-checks: true
2020-02-21 13:20:47 +00:00
Jaco Greeff a3d5ef790c Move StorageData to interface (#1918)
* Move StorageDate to interface

* Move extrinsics interfaces

* Update interface imports
2020-02-21 14:13:23 +01:00
Github Actions b548277c05 [CI Skip] 1.4.0-beta.24
skip-checks: true
2020-02-21 12:40:24 +00:00
Jaco Greeff 2de9317b30 Cleanup CompactAssignments (alignment) (#1917)
* Cleanup CompactAssignments (alignment)

* Remove CompactAssignment

* Add CompactScore
2020-02-21 13:33:21 +01:00
Github Actions 877aa33efa [CI Skip] 1.4.0-beta.23
skip-checks: true
2020-02-21 12:24:23 +00:00
Jaco Greeff 8a9e523b84 Small type usage updates (#1916) 2020-02-21 13:17:40 +01:00
Github Actions 19743d6634 [CI Skip] 1.4.0-beta.22
skip-checks: true
2020-02-21 11:44:20 +00:00
Jaco Greeff 85ec141b56 Lazy reaping types & updates (#1914)
* Lazy reaping types & updates

* system.account queries

* AccountInfo -> ContractAccountInfo tests
2020-02-21 12:37:17 +01:00
Github Actions cb175b4bde [CI Skip] 1.4.0-beta.21
skip-checks: true
2020-02-21 11:19:43 +00:00
Jaco Greeff 8672a2e30e Move length to TypeDef (regularly used), IdentityFields to interface (#1913)
* Move length to TypeDef (regularly used), IdentityFields to interface

* Update api-contracts tests
2020-02-21 12:12:18 +01:00
Github Actions 17936f849b [CI Skip] 1.4.0-beta.20
skip-checks: true
2020-02-21 09:02:17 +00:00
Jaco Greeff 3b9f348223 Cleanup IdentityFields (re-use Set) (#1912)
* Cleanup IdentityFields

* Small cleanups

* Re-add commented IdentityFields
2020-02-21 09:55:18 +01:00
Github Actions b5ff0434d9 [CI Skip] 1.4.0-beta.19
skip-checks: true
2020-02-21 08:40:26 +00:00
Jaco Greeff 877a339353 Extrinsic toHuman aligns with .method (#1911) 2020-02-21 09:33:34 +01:00
Github Actions 716f473887 [CI Skip] 1.4.0-beta.18
skip-checks: true
2020-02-20 20:42:44 +00:00
Jaco Greeff 1c1bfb295d VecFixed now take sub, align ext with UInt (#1909)
* Allow nested definitions for fixed arrays

* Comment nested test

* Don't import U8aFixed + u8
2020-02-20 21:36:12 +01:00
Github Actions dd0a31803f [CI Skip] 1.4.0-beta.17
skip-checks: true
2020-02-20 15:35:25 +00:00
Jaco Greeff e04e5577ed Types for offchain phragmen (#1908) 2020-02-20 16:27:48 +01:00
Github Actions 09617aad2e [CI Skip] 1.4.0-beta.16
skip-checks: true
2020-02-20 12:33:42 +00:00
Jaco Greeff 3d8a57a7d5 Bump dev (#1907) 2020-02-20 13:27:22 +01:00
Github Actions feff458cbf [CI Skip] 1.4.0-beta.15
skip-checks: true
2020-02-20 12:10:28 +00:00
Jaco Greeff 543b4846f9 Fixed64 to an interface (#1906)
* Fixed64 to an interface

* Cleanups, re-use creation

* Fix Int export from codec

* Fix Int export
2020-02-20 13:03:29 +01:00
Github Actions 09ab373b54 [CI Skip] 1.4.0-beta.14
skip-checks: true
2020-02-20 11:58:08 +00:00
Jaco Greeff bec6dba14a Move primitive/Extrinsic -> extrinsic (#1905)
* Move primitive/Extrinsic -> extrinsic

* mv primitive/Generic -> generic

* Update registry with BitVec

* ove BitVec back to primitive

* Remove unused import

* Rebuild interfaces
2020-02-20 12:51:06 +01:00
Github Actions e80bea6680 [CI Skip] 1.4.0-beta.13
skip-checks: true
2020-02-20 09:20:54 +00:00
Jaco Greeff 9119e791d1 Add V4 extrinsic test (#1904)
* Add V4 extinsic test

* Update test with toHuman

* Remove unused import
2020-02-20 10:14:21 +01:00
Github Actions 46b99ae83d [CI Skip] 1.4.0-beta.12
skip-checks: true
2020-02-20 07:28:44 +00:00
Jaco Greeff 92129746dc Move inter-package deps to fixed (as per release) (#1903) 2020-02-20 08:21:17 +01:00
Github Actions 4a8a36d284 [CI Skip] 1.4.0-beta.11
skip-checks: true
2020-02-20 07:07:16 +00:00
Jaco Greeff 2b8ce1b3b7 Check AbstractInt bitLength on construction (#1902)
* Check AbstractInt bitLength on construction

* Language cleanups
2020-02-20 08:00:41 +01:00
Github Actions 0e1e0c0d37 [CI Skip] 1.4.0-beta.10
skip-checks: true
2020-02-19 19:05:23 +00:00
Jaco Greeff 427f821430 Fix 11 Jan 2019 issue (#1900)
* Fix 11 Jan 2019 issue

* Update SignedBlock tests
2020-02-19 19:57:59 +01:00
Github Actions 07307f8374 [CI Skip] 1.4.0-beta.9
skip-checks: true
2020-02-19 14:52:02 +00:00
Jaco Greeff cc5b5c81c9 Subscribe to runtime updates (#1896)
* Subscribe to runtime updates

* console.log -> l.log

* Add l.warn to api augment

* Expand logs with added & removed

* Re-do everything when genesis has changed

* augmentObject complexity

* Dedup [string[], strings[]]

* Update CHANGELOG
2020-02-19 15:45:03 +01:00
Jakub Pánik efbc017940 All heads subscription (#1899)
* [CI Skip]  1.4.0-beta.8

skip-checks: true

* Added support for all heads subscription
2020-02-19 15:30:24 +01:00
Github Actions 849972f7b0 [CI Skip] 1.4.0-beta.8
skip-checks: true
2020-02-19 05:54:02 +00:00
Axel Chalon 01758229eb Add manual seal RPCs (#1894)
* Add manual seal RPCs

* yarn build:interfaces
2020-02-19 06:48:00 +01:00
Github Actions add9b59402 [CI Skip] 1.4.0-beta.7
skip-checks: true
2020-02-18 20:36:58 +00:00
Jaco Greeff c8af75088a Add injectMetadata to api (with decoration) (#1892)
* Add injectMetadata to api (with decoration)

* warn function

* OCD

* OCD #2

* toHuman entry expansion

* CHANGELOG for injectMetadata
2020-02-18 21:30:43 +01:00
Github Actions d4b45921fd [CI Skip] 1.4.0-beta.6
skip-checks: true
2020-02-18 20:14:31 +00:00
Jaco Greeff 30f5baa906 ExtrinsicEra & Vote toHuman (#1893) 2020-02-18 21:08:18 +01:00
Github Actions 7150bdcbea [CI Skip] 1.4.0-beta.5
skip-checks: true
2020-02-18 15:46:08 +00:00
Jaco Greeff d041c0abb2 Support arbitrary UInt<bitLength> definitions (#1891)
* Support arbitrar UInt

* CHANGELOG

* Fix generation

* Move UInt
2020-02-18 16:39:18 +01:00
Github Actions 524e694b90 [CI Skip] 1.4.0-beta.4
skip-checks: true
2020-02-18 15:04:32 +00:00
Jaco Greeff bdd1e4c917 Move H160, H256 & H512 to interfaces (#1890)
* Move H160, H256 & H512 to interfaces

* Test for Hash -> H256

* Replace IHash & Codec.hash with H256

* [u8; n] extends U8aFixed

* Update formatting.ts
2020-02-18 15:56:50 +01:00
Github Actions 7233d7c754 [CI Skip] 1.4.0-beta.3
skip-checks: true
2020-02-18 14:00:33 +00:00
Jaco Greeff aee09c48b9 Use static with for derived H*, U* & I* primitives (#1889)
* Usestatic with for derived H*, U* & I* primitives

* Add with override tests

* Fix linting
2020-02-18 14:53:43 +01:00
Github Actions 7edbc58129 [CI Skip] 1.4.0-beta.2
skip-checks: true
2020-02-18 12:41:52 +00:00
Jaco Greeff ad2939cc4f Rework Unconstructable type (#1888)
* Rework Unconstructable type

* hasType updates

* Unknown -> Unconstructable (as it was)

* Remove commented test

* class name

* getOrThrow tests

* typo.

* getOrUnknown
2020-02-18 13:35:42 +01:00
Github Actions e984c74ca6 [CI Skip] 1.4.0-beta.1
skip-checks: true
2020-02-18 12:26:54 +00:00
Jaco Greeff a5c8e3c4e1 Convert DigestItem to definition (#1886)
* Convert DigestItem to definition

* Remove GenericDigestItem export

* Update CHANGELOG.md
2020-02-18 13:20:29 +01:00
Github Actions 1e5191d695 [CI Skip] 1.4.0-beta.0
skip-checks: true
2020-02-18 09:12:00 +00:00
Jaco Greeff b46093e5d3 Add .toHuman on SubmittableResult (#1885) 2020-02-18 10:05:48 +01:00
Github Actions 64f0d7b2a6 [CI Skip] 1.3.1
skip-checks: true
2020-02-18 08:40:23 +00:00
Jaco Greeff 4a1e504ca2 1.3 (#1883)
* 1.3

* Pair create update

* CHANGELOG update
2020-02-18 09:34:35 +01:00
Github Actions ebf3f4491e [CI Skip] 1.3.0-beta.11
skip-checks: true
2020-02-17 14:23:11 +00:00
Jaco Greeff 849f519efe Add GH actions yarn cache (#1881) 2020-02-17 15:16:09 +01:00
Github Actions accc2b4f7d [CI Skip] 1.3.0-beta.10
skip-checks: true
2020-02-17 13:15:05 +00:00
Jaco Greeff 01abc030f9 Cleanup stray accountNonce reference (#1880)
* Cleanup stray accountNonce reference

* Comment for system.account upgrades
2020-02-17 14:08:13 +01:00
Github Actions e041946de5 [CI Skip] 1.3.0-beta.9
skip-checks: true
2020-02-17 11:50:02 +00:00
Jaco Greeff 502e54ce5c Bump common (#1879)
* Bump common

* Add documentation to extended call

* TODO for toHuman event

* CHANGELOG
2020-02-17 12:43:03 +01:00
Github Actions 12986f0cda [CI Skip] 1.3.0-beta.8
skip-checks: true
2020-02-17 10:50:00 +00:00
Jaco Greeff 83d780220c Add toHuman with base formatting (#1878)
* Add toHuman with base formatting

* Balance formatting

* Externalize Enum decode
2020-02-17 11:43:08 +01:00
Github Actions ec7848ae92 [CI Skip] 1.3.0-beta.7
skip-checks: true
2020-02-17 07:53:42 +00:00
Jaco Greeff 2b5be7eaab Remove unexported staking.infostash derive (duplicated as .query) (#1877) 2020-02-17 08:46:59 +01:00
Github Actions 21f4e3107a [CI Skip] 1.3.0-beta.6
skip-checks: true
2020-02-17 07:16:52 +00:00
Jaco Greeff 8a152ea4c0 Split generation scripts into @polkadot/typegen (#1875)
* Split generation scripts into @polkadot/typegen

* Remove moved files

* CC overrides

* interfaces typo

* Cleanup imports

* Some import combinations

* Updates

* Generation updates

* Cleanups, split js wrapper & ts logic

* Rename jiggle 1

* Rename jiggle 2

* Style cleanups

* Expose enry function for scripts

* Typo

* Update script copy & include locations

* CC exclude location

* Minor adjustments

* argv parsing into main
2020-02-17 08:09:59 +01:00
Github Actions fd7b38e781 [CI Skip] 1.3.0-beta.5
skip-checks: true
2020-02-17 06:16:35 +00:00
Jeremías Díaz 5df22835f6 fix: make bn.js into a regular dependency (#1876)
Since `AbstractInt` is exposing `toBn(): BN` which uses `bn.js` types,
projects using polkadot are forced to install `@types/bn.js` on their own,
otherwise they get compilation errors
2020-02-17 07:09:30 +01:00
Github Actions 6a828eb11a [CI Skip] 1.3.0-beta.4
skip-checks: true
2020-02-16 16:48:32 +00:00
Jaco Greeff ad2b1abdc9 Move @polakdot/jsonrpc -> packages/jsonrpc (#1874)
* Move @polakdot/jsonrpc -> packages/jsonrpc

* Update links
2020-02-16 17:41:45 +01:00
Github Actions d3dc2cb00a [CI Skip] 1.3.0-beta.3
skip-checks: true
2020-02-16 12:58:16 +00:00
Jaco Greeff 921e55a82e Move types/codec/create -> types/create (#1871)
* Move types/codec/create -> types/create

* Update imports after move

* Cleanups

* Cleanup code circular deps

* Re-add dropped interfaces

* Drop duplicated code

* Fix imports

* Remove whacky comment
2020-02-16 13:51:37 +01:00
Github Actions fde076152a [CI Skip] 1.3.0-beta.2
skip-checks: true
2020-02-16 12:20:24 +00:00
Jaco Greeff 6e535b0502 Don't make types depend on api (dev deps) (#1869)
* Don't make types depend on api (dev deps)

* Naming cleanups

* Remove skipped tests

* Splt types/types into chunks

* Re-add setChainProperties (properties?: ChainProperties): void;
2020-02-16 13:13:56 +01:00
Github Actions 1ddad84d7e [CI Skip] 1.3.0-beta.1
skip-checks: true
2020-02-16 10:16:34 +00:00
Jaco Greeff 1e975c68ee Make chain properties available on registry (#1868)
* Make chain properties available on registry

* Use registry chainSS58 to format address

* CHANGELOG

* CHANGELOG typo

* Fix tests vis setChainProperties

* Cleanup tests via chain property set

* Remove global ss58 format set
2020-02-16 11:09:48 +01:00
Github Actions 5c962cf093 [CI Skip] 1.3.0-beta.0
skip-checks: true
2020-02-16 09:27:50 +00:00
Jaco Greeff 07f55af202 Documentation of ready rejections (#1870) 2020-02-16 10:21:19 +01:00
534 changed files with 35832 additions and 41722 deletions
+3 -1
View File
@@ -1 +1,3 @@
18
20
1.4.2
1.6.2
+5 -2
View File
@@ -4,6 +4,9 @@ exclude_patterns:
- "**/*.test.js"
- "**/*.test.ts"
- "docs/**/*.js"
- "packages/api/src/types/augment/"
- "docs/**/*.ts"
- "packages/api/src/augment/"
- "packages/typegen/scripts"
- "packages/typegen/src"
- "packages/types/src/interfaces/"
- "packages/types/src/scripts/"
- "packages/types/src/augment/"
+1
View File
@@ -1,3 +1,4 @@
**/build/*
**/coverage/*
**/node_modules/*
docs/examples/promise/90_typegen/*
+44 -4
View File
@@ -14,9 +14,19 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: lint
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn lint
test:
@@ -31,9 +41,19 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: test
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn test
build_code:
@@ -48,9 +68,19 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: build
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn build
build_docs:
@@ -65,7 +95,17 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: build
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn docs
+22 -2
View File
@@ -20,6 +20,16 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: build
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
@@ -28,7 +38,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn polkadot-ci-ghact-build
build_docs:
@@ -44,6 +54,16 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Config yarn cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: build
env:
GH_PAT: ${{ secrets.GH_PAT }}
@@ -51,7 +71,7 @@ jobs:
GH_PAGES_SRC: build-docs
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn install --frozen-lockfile
yarn install --immutable | grep -v 'YN0013'
yarn polkadot-ci-ghact-docs
dummy:
+4
View File
@@ -13,6 +13,10 @@ tmp/
.env.production.local
.npmrc
.rpt2_cache
.yarn/*
!.yarn/releases
!.yarn/plugins
.pnp.*
.vscode/
cc-test-reporter
lerna-debug.log*
File diff suppressed because one or more lines are too long
Vendored Executable
+58
View File
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
enableImmutableInstalls: false
enableProgressBars: false
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-berry.js
+85 -9
View File
@@ -1,17 +1,93 @@
# 1.6.2 Feb 27, 2020
- Revert checks for arg, not working on `.at()` queries (proper fix in next version)
# 1.6.1 Mar 12, 2020
- **Breaking change** `api.rpc.state.queryStorage(...)` now fully decodes the `Vec<StorageChangeSet>` and returns a decoded `[Hash, Codec[]][]` when using this RPC.
- `StorageKey` now has an `.args` property, decoded from meta where `twox64_concat` or `blake128_concat` are used on maps
- Fix `api.query.*.*.entries` type conversions to return exact types (not `Option` in some cases)
- Add `api.query.*.*.keys` to retrieve only the storage keys, similar to `.entries`
- Full linked map retrievals will now use direct getStorage queries for faster operation
- Underlying rpc-core interfaces now unwraps `Error("...")` when found in responses
- Added `derive.eras*` interfaces for queries to new Substrate staking interfaces
- Update `derive.account` to cater for new indices module storage (detected with fallbacks)
- Adjust derive queries for session without module prefix (DoubleMap -> Map), detected on use
- Add runtime validation for map arguments to `api.query.*`
- TypeScript interfaces for linked maps now correctly generates as `[Type, Linkage<Next>]`
# 1.5.1 Mar 06, 2020
- **Important** Substrate master has updated staking, on older chains supply `StakingLedger: 'StakingLedgerTo223'`
- **Important** Substrate master has updated collective, on older chains supply `Votes: 'VotesTo230'`
- Add proper support for type generation with an Enum containing an Tuple (Thanks to https://github.com/monitz87)
- Fix storage parsing not resulting in rejected Promises (Fix from https://github.com/aniiantt applied)
- Remove use of deprecated `Observable.create` (Thanks to https://github.com/Himself65)
- Add types & metadata for the latest Polkadot/Substrate runtime versions (master branches)
- Type extraction will now allow the same sub-module name across packages, i.e. `@polkadot/types/interfaces/runtime` & `@mine/interfaces/runtime` will be valid
- Add `.range([from, to]: [Hash, Hash?], ...args: any[]): [Hash, Codec][]` on all storage entries
- Add `.raw(...args: any[]): Promise<Uint8Array & Codec>` to all RPC calls, returning the un-encoded result
- Allow pre-module type aliasing with `typesAlias: { <moduleName>: { <meta-type>: <alias-type> } }` in API construction options
- Allow `BTreeMap` to be initialized with a `Record<string, any>` object (in addition to `Map`)
- Allow for `HashMap<KeyType, ValueType>` definitions
- `Bool` will now correctly return `isEmpty` on false/default values
- Refresh the `NetworkState` types as returned by the `rpc.system.networkState()` call to current
- Expose `registry.createClass(<typeName>)` to allow for creating type classes. If you are using `createClass` or `ClassOf` in your code, it is recommended to swap to this instance.
- Add additional derives to `api.derive.staking` to handle lazy-payout retrievals
- Update `@polkadot/{util, util-crypto, keyring}` to 1.6.1 & `@polkadot/wasm` to 1.2.1
# 1.4.2 Feb 27, 2020
- Fix `api.tx(<extrinsic>): Submittable` decoration (non-working in 1.4.1, now with proper test)
# 1.4.1 Feb 26, 2020
- **Breaking change** (TypeScript only) The `*.d.ts` files now contain TypeScript 3.8 features (specifically `#private`), which is not usable in TS versions < 3.8
- **Breaking change** - `api.derive.staking.*` has updated result types and detects support for lazy payouts queries
- Rework type generation for `api.{query, tx}` to properly handle complex type inputs (Thanks to https://github.com/monitz87)
- Rework metadata `--strict` mode to effectively decorate chain metadata (Thanks to https://github.com/monitz87)
- Add `api.rpc.chain.subscribeAllHeads` (not just best) (Thanks to https://github.com/jak-pan)
- Add `api.rpc.engine.*` for manual seal support
- Add `api.injectMetadata(metadata)` to initialize API with a specific metadata version
- The api now checks for runtime upgrades, augmenting the interfaces with new metadata when found
- Support types & interfaces required for lazy reaping, lazy payouts & offchain phragmen
- `Option` types now has an `.unwrapOrDefault` as an complement to `.unwrap` & `.unwrapOr`
- Support JS `BigInt` inputs in any derived `UInt` and `Int` object, e.g. `api.tx.balances.transfer(..., 9876543210123456789n)`
- `UInt` & `Int` now does source bitLength checks upon construction
- Registry now exposes `.createType(<type>, ...args)` as an additional helper (like the API)
- Expand `.toHuman` on `ExtrinsicEra`, `SubmittableResult` & `Vote`
- Move `DigestItem`, `Fixed64`, `H160`, `H256` & `H512` to interfaces in `@polkadot/types/interfaces`
- Align construction of unknown types in `registry.get` consistently warn on detection, throw on use
- Support for arbitrary `u*`` types via `UInt<bitLength>` type definitions
- Expose static `.with` on `UInt`, `Int` & `U8aFixed` classes with optional type name override
- Remove [11 Jan 2019](https://github.com/polkadot-js/api/issues/574) extrinsic length hack
- Use ES `#field` on private class fields as applicable
- Move `types/primitive/{extrinsics, generic}` to `types/{extrinsics, generic}`
- Cleanup augmentation and generation scripts for type definitions, aligning with api augmentation
- Bump to `@polkadot/{util, util-crypto, keyring}` 2.5.1
# 1.3.1 Feb 18, 2020
- Add `@types/bn.js` as a normal dependency, exposed in `*.d.ts` (Thanks to https://github.com/monitz87)
- Type generation scripts (including `polkadot-types-from-{chain,defs}`) has been moved to the `@polkadot/typegen` package
- The `@polkadot/types/codec/create` has been moved to `@polkadot/types/create`, imports from `@polkadot/types` are unaffected
- Expose chain properties on registry (and use for API type formatting)
- Add `toHuman(isExtended?: boolean)` to all codec types, formatting into a human-readable structure
# 1.2.1 Feb 16, 2020
- **Important** Update RPC status codes (latest Substrate 2), with the `isInBlock` (`isFinalized` now indicates finality)
- Storage `.entries(arg?: any)` now has the correct argument type for DoubleMap (Thanks to https://github.com/monitz87)
- Swap Kusama and Polkadot aliasses for `Address` to `AccountId` (future update)
- Add `LookupSource` and `LookupTarget` types instead of mapping these directly for aliassing
- Swap Kusama and Polkadot aliases for `Address` to `AccountId` (future update)
- Add `LookupSource` and `LookupTarget` types instead of mapping these directly for aliasing
- Add `BitVec` type primitive
- Add support for `system.account` for balance & nonce queries in derives as well as Submittables (Substrate composites)
- Add `rpc.author.hasKey` and `rpc.author.hasSessinKeys` RPCs
- Add `rpc.author.hasKey` and `rpc.author.hasSessionKeys` RPCs
- Add derives for the parachains interfaces
- Applied the latest types for Polkadot parachains
- `registry.findMetaError` now can take in a `DispatchErrorModule` object for error lookups (from `asModule` in `DispatchError`)
- Metadata now correctly serializes to the original input data via `toHex()` & `toU8a()`
- Metadata dcocumentation generation rework, including the output of errors from metadata
- Metadata documentation generation rework, including the output of errors from metadata
- Update all examples and comments to use latest `system.account` queries (instead of `system.accountNonce` and `balances.freeBalance`/`balances.reservedBalance`)
- Cleanup `codec/Date` tests to make it run properly on all timezones
- Add explicit dependencies to all packages and move TypeScript `@types/*` to dev deps
@@ -51,7 +127,7 @@
# 0.100.1 Jan 13, 2020
- **Important** This will the the last API version with Substrate 1.x support. Although you will still be able to use subsequent versions with older chans, dependent libraries such as sr25519 may not be compatible.
- **Important** This will the the last API version with Substrate 1.x support. Although you will still be able to use subsequent versions with older chains, dependent libraries such as sr25519 may not be compatible.
- Add support for the Substrate identity module
- Remove the `codec/Data` type, to remove a conflict with Substrate. This type is now named `Raw`
- Fix for linked maps using `Option`
@@ -65,7 +141,7 @@
- **Breaking change** The `Data` and `U8a` type has been renamed and just replaced with the `Raw` type
- **Breaking change** The `api.derive.staking.info` has been split into 2 - `staking.query` for non-balance related information (more effective) and `staking.account` that enhances query for all the information previously found `.info`
- Cleanup `DoubleMap` hashing to always hash over the full value (in the case of `Vec<T>`, this includes the length)
- Update democracy derives to take care of nextTally and lowestU*nbaked
- Update democracy derives to take care of nextTally and lowestUnbaked
- Add additional derives for both council & treasury
- Alignment with latest Polkadot/Substrate master branch types
@@ -120,7 +196,7 @@
- Adjust API cloning now takes RPC filters from source into account
- Simplification of isPedantic checks and less overhead on StorageData types
- Cleanups and fixes around RPC and derive type definitions
- Fix `derive.imOnline.receivedHeatbeats` to query via indexes
- Fix `derive.imOnline.receivedHeartbeats` to query via indexes
- Adjustment of `api.derive.elections.{approvalsOf|approvalsOfAt}` to allow ss58 address input
- Cleanup `Enum` `.eq` handling to be more exhaustive
- Add documentation for custom extrinsic formats (advanced chains)
@@ -154,7 +230,7 @@
- Redeemed balance calculation if `api.derive` now returns the correct values again (bug fix)
- added the `yarn chain:info [--ws URL]` utility to extract a calls-only metadata version
- Missing types are now logged via a `console.warn`, not via `.error`
- `Extrinsic`, `ExtrinsicPayload` & `SignerPayload` is registered in the type registry and can be overriden now
- `Extrinsic`, `ExtrinsicPayload` & `SignerPayload` is registered in the type registry and can be overridden now
- **Breaking change** `SignerPayload` is renamed to `SignerPayloadJSON`
- **Breaking change** `SignerPayloadJSON`, `SignerPayloadRawBase` and `SignerPayloadRaw` are all moved to `@polkadot/types`
@@ -180,7 +256,7 @@ If you are upgrading form an older version, use the CHANGELOG hand-in-hand with
- Support for substrate 2.x (master) has been extended,
- Additional types have been addedd for the modules
- `api.derive.contract` is now `api.derive.contracts` to align with the substrate 2.x rename. (Feture detection is used so it supports both 1.x and 2.x chains)
- `api.derive.contract` is now `api.derive.contracts` to align with the substrate 2.x rename. (Feature detection is used so it supports both 1.x and 2.x chains)
- Addition of `api.derive.elections`
- Support latest substrate 2 v6 metadata with module constants using `api.consts`.
+1 -1
View File
@@ -27,7 +27,7 @@ The API is split up into a number of internal packages -
Type definitions for interfaces as exposed by Polkadot & Substrate clients -
- [@polkadot/jsonrpc](packages/type-jsonrpc/) Definitions for JSONRPC endpoints
- [@polkadot/jsonrpc](packages/jsonrpc/) Definitions for JSONRPC endpoints
- [@polkadot/types](packages/types/) Codecs for all Polkadot and Substrate primitives
## development
+1 -3
View File
@@ -1,3 +1 @@
module.exports = {
extends: '@polkadot/dev/config/babel'
};
module.exports = require('@polkadot/dev/config/babel');
+10 -9
View File
@@ -2,7 +2,7 @@
function copy_folder () {
SRC="packages/$1/build"
DST="../apps/node_modules/@polkadot/$2"
DST="../apps/node_modules/@polkadot/$1"
echo "** Copying $SRC to $DST"
@@ -12,11 +12,12 @@ function copy_folder () {
yarn polkadot-dev-build-ts
copy_folder "api" "api"
copy_folder "api-contract" "api-contract"
copy_folder "api-derive" "api-derive"
copy_folder "metadata" "metadata"
copy_folder "rpc-core" "rpc-core"
copy_folder "rpc-provider" "rpc-provider"
copy_folder "type-jsonrpc" "jsonrpc"
copy_folder "types" "types"
copy_folder "api"
copy_folder "api-contract"
copy_folder "api-derive"
copy_folder "metadata"
copy_folder "rpc-core"
copy_folder "rpc-provider"
copy_folder "jsonrpc"
copy_folder "types"
copy_folder "typegen"
+3 -2
View File
@@ -43,7 +43,7 @@ module.exports = {
['start/api.tx.wrap.md', 'Complex transactions'],
['start/types.basics.md', 'Type basics'],
['start/types.extend.md', 'Extending types'],
['start/extrinsic.extend.md', 'Extending extrinsics'],
['start/types.create.md', 'Creating types'],
['start/typescript.md', 'TypeScript interfaces'],
['start/typescript.user.md', 'TypeScript user generated'],
['start/FAQ.md', 'FAQ']
@@ -63,7 +63,8 @@ module.exports = {
['examples/promise/06_make_transfer/', 'Make a transfer'],
['examples/promise/08_system_events/', 'Display system events'],
['examples/promise/09_transfer_events/', 'Transaction with events'],
['examples/promise/10_upgrade_chain/', 'Upgrade via sudo']
['examples/promise/10_upgrade_chain/', 'Upgrade via sudo'],
['examples/promise/90_typegen/', 'TypeScript augmentation']
]
},
{
@@ -13,13 +13,13 @@ async function main () {
// Retrieve the initial balance. Since the call has no callback, it is simply a promise
// that resolves to the current on-chain value
let [previousNonce, { free: previousFree }] = await api.query.system.account(Alice);
let { nonce: previousNonce, data: { free: previousFree } } = await api.query.system.account(Alice);
console.log(`${Alice} has a balance of ${previousFree}, nonce ${previousNonce}`);
console.log(`You may leave this example running and start example 06 or transfer any value to ${Alice}`);
// Here we subscribe to any balance changes and update the on-screen value
api.query.system.account(Alice, ([currentNonce, { free: currentFree }]) => {
api.query.system.account(Alice, ({ nonce: currentNonce, data: { free: currentFree } }) => {
// Calculate the delta
const change = currentFree.sub(previousFree);
@@ -16,7 +16,7 @@ async function main () {
// Subscribe and listen to several balance changes
api.query.system.account.multi([ALICE, BOB], (balances) => {
console.log('Change detected, new balances: ', balances.map(([, { free }]) => free));
console.log('Change detected, new balances: ', balances.map(({ data: { free } }) => free));
});
}
@@ -12,7 +12,7 @@ async function main () {
const api = await ApiPromise.create();
// Make our basic chain state/storage queries, all in one go
const [[accountNonce], now, validators] = await Promise.all([
const [{ nonce: accountNonce }, now, validators] = await Promise.all([
api.query.system.account(ALICE),
api.query.timestamp.now(),
api.query.session.validators()
@@ -32,8 +32,8 @@ async function main () {
// Print out the authorityIds and balances of all validators
console.log('validators', validators.map((authorityId, index) => ({
address: authorityId.toString(),
balance: validatorBalances[index][1].free.toString(),
nonce: validatorBalances[index][0].toString()
balance: validatorBalances[index].data.free.toHuman(),
nonce: validatorBalances[index].nonce.toHuman()
})));
}
}
@@ -21,12 +21,12 @@ async function main () {
// the format is always `.at(<blockhash>, ...params)`
const balance = await api.query.system.account.at(parentHash, ALICE);
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance[1].free}`);
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance.data.free}`);
// Now perform a multi query, returning multiple balances at once
const balances = await api.query.system.account.multi([ALICE, BOB]);
console.log(`Current balances for Alice and Bob are ${balances[0][1].free} and ${balances[1][1].free}`);
console.log(`Current balances for Alice and Bob are ${balances[0].data.free} and ${balances[1].data.free}`);
}
main().catch(console.error).finally(() => process.exit());
@@ -19,7 +19,7 @@ async function main () {
const alice = keyring.addFromUri('//Alice');
// Get nonce for account
const [nonce] = await api.query.system.account(alice.address);
const { nonce } = await api.query.system.account(alice.address);
// Get current block
const signedBlock = await api.rpc.chain.getBlock();
@@ -24,7 +24,7 @@ async function main () {
const keyring = testKeyring.default();
// Get the nonce for the admin key
const [nonce] = await api.query.system.account(ALICE);
const { nonce } = await api.query.system.account(ALICE);
// Find the actual keypair in the keyring
const alicePair = keyring.getPair(ALICE);
@@ -40,13 +40,15 @@ async function main () {
.signAndSend(alicePair, { nonce }, ({ events = [], status }) => {
console.log('Transaction status:', status.type);
if (status.isFinalized) {
console.log('Completed at block hash', status.asFinalized.toHex());
if (status.isInBlock) {
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
process.exit(0);
}
@@ -1,5 +1,5 @@
# Chain upgrade
Performs a chain upgrade using the `sudo` module. This may brick your chain, so us it as an educational sample. (use `substrate --dev purge-chain` to remove DB and recover).
Performs a chain upgrade using the `sudo` module. This may brick your chain, so use it as an educational sample. (use `substrate purge-chain --dev` to remove DB and recover).
<<< @/docs/examples/promise/10_upgrade_chain/index.js
@@ -39,15 +39,15 @@ async function main () {
.signAndSend(adminPair, ({ events = [], status }) => {
console.log('Proposal status:', status.type);
if (status.isFinalized) {
if (status.isInBlock) {
console.error('You have just upgraded your chain');
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
console.log(JSON.stringify(events.toHuman(), null, 2));
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
process.exit(0);
}
+248
View File
@@ -0,0 +1,248 @@
# typegen
This is a sample TypeScript project [with full source & config on GithHub](https://github.com/polkadot-js/api/tree/master/docs/examples/promise/90_typegen), that uses `@polkadot/typegen` to generate type definitions that can be used to decorate the `@polkadot/api`. It uses both types defined for the specific chain as well as the chain metadata to generate TypeScript interfaces. This means that interfaces such as `api.query.*`, `api.tx.*` and `api.consts.*` will be decorated based on chain-specific information, instead of an un-augmented catch-all definition.
**NOTE** This is built using the updates in the `1.4.0` api track and as such it uses the latest (at the time of writing) `@polkadot/api 1.4.0`. If you want to play on your own, it is also suggested that you use the `1.4+` series since some generation types have moved around internally, making it easier to augment.
## Packages
For the packages we need from the `@polkadot/*` we have added `@polkadot/api` (we want to do API stuff) and `@polkadot/typegen` (to generate the actual interfaces). So our scripts and dependencies inside `package.json` contain the following -
```json
{
"scripts": {
"build": "yarn generate:defs && yarn generate:meta",
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces",
"lint": "tsc --noEmit --pretty"
},
"dependencies": {
"@polkadot/api": "^1.4.0"
},
"devDependencies": {
"@polkadot/typegen": "^1.4.0",
"ts-node": "^8.6.2",
"typescript": "^3.8.2"
}
}
```
We will delve into the setup and running the scripts and what they do in a short bit, but as of now just notice that we are running the scripts via `ts-node`. Since we supply our definitions as `*.ts` files, this is important otherwise they will not be parsable. `build` will just run both the types and meta generators (in that order, so metadata can use the types) and we have a `lint` that can just check that everything is as it is meant to be.
## Metadata setup
The idea here is to use the actual chain metadata to generate the actual api augmented endpoints. The metadata we are adding here (in addition to the user types), is from the Edgeware Berlin testnet. So this is a real-world example of configuring the API for a specific substrate chain. For the metadata retrieval, we just ran a simple curl command to get it from the node -
`curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933`
And then add the full JSONPC output as received to the `edgeware.json` file as specified by the generation command. A trimmed version would look like -
```json
{"jsonrpc":"2.0","result":"0x6d6574610b6c185379737....","id":29}
```
The generator can also use a `wss://` as an `--endpoint` param as part of the generation, but in most cases you would want a static metadata to work from in development, hence we are actually adding it here.
## Types setup
The types are defined in the `src/interfaces` folder. While this repo contains a number of generated files in there as well, you basically only need to manually add the following -
- `src/interfaces/definitions.ts` - this just exports all the sub-folder definitions in one go
- `src/interfaces/<module>/definitions.ts` - type definitions for a specific module
This structure fully matches what is available in the `@polkadot/type/interfaces` folder, so the structure is setup based on the convention used in the `@polkadot/types` library. The generating scripts will expect something matching this since the same underlying code is actually used inside `@polkadot/types` as well. The top-level `interfaces/` folder can be name anything, however the internal content structure need to match what is defined above.
For the top-level the definition file has the following contents -
```js
export { default as signaling } from './signaling/definitions';
export { default as treasuryRewards } from './treasuryRewards/definitions';
export { default as voting } from './voting/definitions';
```
As explained above, it really is just a re-export of the definitions, so they are all easily accessible to the outside, i.e. we will use this import inside our own code to use the definitions in API initialization. The generation scripts will load this file to determine which types it needs to import. By the `@polkadot/types` convention, match the export names with the folders (preferably your runtime module names), the generation scripts will use these names to find the correct folders to output the generated `types.ts` to.
For each of the folders, `signaling`, `treasuryRewards` and `voting` another `definitions.ts` file is contained within. Looking at the one from `signaling`, it contains this -
```js
export default {
types: {
ProposalRecord: {
index: 'u32',
author: 'AccountId',
stage: 'VoteStage',
transition_time: 'u32',
title: 'Text',
contents: 'Text',
vote_id: 'u64'
},
ProposalContents: 'Vec<u8>',
ProposalTitle: 'Vec<u8>'
}
}
```
Just the type definitions (the structure of which you should be familiar with), nested inside a `types: {...}` container. This allows us future extension points, i.e. there is some work to expose the custom RPC types alongside, so that would become another key on a per-module basis.
In the above, you will note that the `ProposalRecord` references a type for `voting`, i.e. `VoteStage`. The type generation and resolution will determine where the type comes from, and provide the required imports on generation.
Looking at the example in this repo, it also has `augment*`, `index.ts` and `types.ts` files in the interfaces folder. These are all generated, and will be re-generated when the generator is run - so all edits to these files will be lost. The only requirement for user-edits are the `definitions.ts` files.
## Generating
Now that both the metadata nd types setup is completed, we just run the build command via `yarn build` and magically (assuming you didn't have the `augment*` and other generated files), these files will be added. When running this command, the console should display something like -
```
> yarn build
$ yarn generate:defs && yarn generate:meta
$ ts-node --skip-project \
node_modules/.bin/polkadot-types-from-defs \
--package sample-polkadotjs-typegen/interfaces \
--input ./src/interfaces
sample-polkadotjs-typegen/src/interfaces/types.ts
Generating
Extracting interfaces for signaling
...
Writing
sample-polkadotjs-typegen/src/interfaces/augment-types.ts
Generating
Writing
$ ts-node --skip-project \
node_modules/.bin/polkadot-types-from-chain \
--package sample-polkadotjs-typegen/interfaces \
--endpoint ./edgeware.json \
--output ./src/interfaces
Generating from metadata, 81,267 bytes
...
sample-polkadotjs-typegen/src/interfaces/augment-api.ts
Generating
Writing
✨ Done in 4.04s.
```
Now if we check the actual output against the source via `yarn lint`, we would see that valid output has been generated -
```
> yarn lint
$ tsc --noEmit --pretty
✨ Done in 2.28s.
```
## Peering at the output
We are ready to use all these generated types this after some TS config. If you take a look at the generated `src/signaling/types.ts`, you would see generated TS interfaces, such as -
```js
import { Struct } from '@polkadot/types/codec';
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
import { AccountId } from '@polkadot/types/interfaces/runtime';
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
/** @name ProposalContents */
export interface ProposalContents extends Bytes {}
/** @name ProposalRecord */
export interface ProposalRecord extends Struct {
readonly index: u32;
readonly author: AccountId;
readonly stage: VoteStage;
readonly transition_time: u32;
readonly title: Text;
readonly contents: Text;
readonly vote_id: u64;
}
/** @name ProposalTitle */
export interface ProposalTitle extends Bytes {}
```
As mentioned earlier, here you will notice the `import { VoteStage }`, the generator has determined that `voting` exports that interface and has added the required imports.
## TypeScript config
Now that we have files generated, it is time to make TypeScript aware of the types and add an explicit override into out `tsconfig.json`. After some changes, the paths in the config looks as follow (comments are in teh actual config file here) -
```json
{
"compilerOptions": {
"paths": {
"sample-polkadotjs-typegen/*": ["src/*"],
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
}
}
}
```
Effectively what we do above is tell the TypeScript compiler to not use the built-in API augmentation, but rather to replace it with our version. This means that all types from these are injected not by the substrate-latest-master version, but rather with what we have defined above.
## Usage
For simple usage, we have added the `src/index.ts` file that show how the metadata and types actually decorate the API. In addition, we also have setup instructions included here.
```js
// We need to import the augmented definitions "somewhere" in our project, however since we have
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
import './interfaces/augment-api';
import './interfaces/augment-types';
// all type stuff, the only one we are using here
import type { VoteRecord } from './interfaces';
// external imports
import { ApiPromise } from '@polkadot/api';
import { createType } from '@polkadot/types';
// our local stuff
import * as definitions from './interfaces/definitions';
async function main (): Promise<void> {
// extract all types from definitions - fast and dirty approach, flatted on 'types'
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
const api = await ApiPromise.create({
types: {
...types,
// aliases that don't do well as part of interfaces
'voting::VoteType': 'VoteType',
'voting::TallyType': 'TallyType',
// chain-specific overrides
Keys: 'SessionKeys4'
}
});
// get a query
const recordOpt = await api.query.voting.voteRecords(123);
// the types match with what we expect here
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
console.log(firstRecord?.toHuman());
// it even does work for arrays & subscriptions
api.query.signaling.activeProposals((results): void => {
results.forEach(([hash, blockNumber]): void => {
console.log(hash.toHex(), ':', blockNumber.toNumber());
});
});
// even createType works, allowing for our types to be used
console.log(`Balance2 bitLength:`, [
api.createType('Balance2').bitLength(),
api.registry.createType('Balance2').bitLength(),
createType(api.registry, 'Balance2').bitLength()
]);
}
await main();
```
## And that is a ...
... wrap. Just a really simple walk-through to customizing the API TypeScript definitions for your chain.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,24 @@
{
"name": "sample-polkadotjs-typegen",
"version": "0.0.1",
"description": "A sample using @polkadot/typegen to generate type definitions",
"main": "index.js",
"repository": "https://github.com/jacogr/sample-polkadotjs-typegen",
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "The Unlicense",
"private": true,
"scripts": {
"build": "yarn generate:defs && yarn generate:meta",
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces --strict",
"lint": "tsc --noEmit --pretty"
},
"dependencies": {
"@polkadot/api": "^1.4.0"
},
"devDependencies": {
"@polkadot/typegen": "^1.4.0",
"ts-node": "^8.6.2",
"typescript": "^3.8.2"
}
}
@@ -0,0 +1,54 @@
// We need to import the augmented definitions "somewhere" in our project, however since we have
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
import './interfaces/augment-api';
import './interfaces/augment-types';
// all type stuff, the only one we are using here
import type { VoteRecord } from './interfaces';
// external imports
import { ApiPromise } from '@polkadot/api';
import { createType } from '@polkadot/types';
// our local stuff
import * as definitions from './interfaces/definitions';
async function main (): Promise<void> {
// extract all types from definitions - fast and dirty approach, flatted on 'types'
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
const api = await ApiPromise.create({
types: {
...types,
// aliasses that don't do well as part of interfaces
'voting::VoteType': 'VoteType',
'voting::TallyType': 'TallyType',
// chain-specific overrides
Keys: 'SessionKeys4'
}
});
// get a query
const recordOpt = await api.query.voting.voteRecords(123);
// the types match with what we expect here
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
console.log(firstRecord?.toHuman());
// it even does work for arrays & subscriptions
api.query.signaling.activeProposals((results): void => {
results.forEach(([hash, blockNumber]): void => {
console.log(hash.toHex(), ':', blockNumber.toNumber());
});
});
// even createType works, allowing for our types to be used
console.log(`Balance2 bitLength:`, [
api.createType('Balance2').bitLength(),
api.registry.createType('Balance2').bitLength(),
createType(api.registry, 'Balance2').bitLength()
]);
}
await main();
@@ -0,0 +1,253 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Bytes, u32 } from '@polkadot/types/primitive';
import { Gas } from '@polkadot/types/interfaces/contracts';
import { Balance, BalanceOf, BlockNumber, Moment, Percent, Permill } from '@polkadot/types/interfaces/runtime';
import { SessionIndex } from '@polkadot/types/interfaces/session';
import { EraIndex } from '@polkadot/types/interfaces/staking';
declare module '@polkadot/metadata/Decorated/consts/types' {
export interface Constants {
timestamp: {
/**
* The minimum period between blocks. Beware that this is different to the *expected* period
* that the block production apparatus provides. Your chosen consensus system will generally
* work with this to determine a sensible block time. e.g. For Aura, it will be double this
* period on default settings.
**/
minimumPeriod: AugmentedConst<Moment>;
};
balances: {
/**
* The minimum amount required to keep an account open.
**/
existentialDeposit: AugmentedConst<Balance>;
/**
* The fee required to make a transfer.
**/
transferFee: AugmentedConst<Balance>;
/**
* The fee required to create an account.
**/
creationFee: AugmentedConst<Balance>;
};
transactionPayment: {
/**
* 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>;
};
staking: {
/**
* Number of sessions per era.
**/
sessionsPerEra: AugmentedConst<SessionIndex>;
/**
* Number of eras that staked funds must remain bonded for.
**/
bondingDuration: AugmentedConst<EraIndex>;
};
session: {
/**
* Used as first key for `NextKeys` and `KeyOwner` to put all the data into the same branch
* of the trie.
**/
dedupKeyPrefix: AugmentedConst<Bytes>;
};
democracy: {
/**
* The minimum period of locking and the period between a proposal being approved and enacted.
* It should generally be a little more than the unstake period to ensure that
* voting stakers have an opportunity to remove themselves from the system in the case where
* they are on the losing side of a vote.
**/
enactmentPeriod: AugmentedConst<BlockNumber>;
/**
* How often (in blocks) new public referenda are launched.
**/
launchPeriod: AugmentedConst<BlockNumber>;
/**
* How often (in blocks) to check for new votes.
**/
votingPeriod: AugmentedConst<BlockNumber>;
/**
* The minimum amount to be used as a deposit for a public referendum proposal.
**/
minimumDeposit: AugmentedConst<BalanceOf>;
/**
* Minimum voting period allowed for an emergency referendum.
**/
emergencyVotingPeriod: AugmentedConst<BlockNumber>;
/**
* Period in blocks where an external proposal may not be re-submitted after being vetoed.
**/
cooloffPeriod: AugmentedConst<BlockNumber>;
/**
* The amount of balance that must be deposited per byte of preimage stored.
**/
preimageByteDeposit: AugmentedConst<BalanceOf>;
};
elections: {
candidacyBond: AugmentedConst<BalanceOf>;
votingBond: AugmentedConst<BalanceOf>;
desiredMembers: AugmentedConst<u32>;
desiredRunnersUp: AugmentedConst<u32>;
termDuration: AugmentedConst<BlockNumber>;
};
finalityTracker: {
/**
* The number of recent samples to keep from this chain. Default is 101.
**/
windowSize: AugmentedConst<BlockNumber>;
/**
* The delay after which point things become suspicious. Default is 1000.
**/
reportLatency: AugmentedConst<BlockNumber>;
};
treasury: {
/**
* 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.
**/
proposalBond: AugmentedConst<Permill>;
/**
* Minimum amount of funds that should be placed in a deposit for making a proposal.
**/
proposalBondMinimum: AugmentedConst<BalanceOf>;
/**
* Period between successive spends.
**/
spendPeriod: AugmentedConst<BlockNumber>;
/**
* Percentage of spare funds (if any) that are burnt per spend period.
**/
burn: AugmentedConst<Permill>;
/**
* The period for which a tip remains open after is has achieved threshold tippers.
**/
tipCountdown: AugmentedConst<BlockNumber>;
/**
* The amount of the final tip which goes to the original reporter of the tip.
**/
tipFindersFee: AugmentedConst<Percent>;
/**
* The amount held on deposit for placing a tip report.
**/
tipReportDepositBase: AugmentedConst<BalanceOf>;
/**
* The amount held on deposit per byte within the tip report reason.
**/
tipReportDepositPerByte: AugmentedConst<BalanceOf>;
};
contracts: {
/**
* Number of block delay an extrinsic claim surcharge has.
* When claim surcharge is called by an extrinsic the rent is checked
* for current_block - delay
**/
signedClaimHandicap: AugmentedConst<BlockNumber>;
/**
* The minimum amount required to generate a tombstone.
**/
tombstoneDeposit: AugmentedConst<BalanceOf>;
/**
* Size of a contract at the time of instantiaion. This is a simple way to ensure that
* empty contracts eventually gets deleted.
**/
storageSizeOffset: AugmentedConst<u32>;
/**
* Price of a byte of storage per one block interval. Should be greater than 0.
**/
rentByteFee: AugmentedConst<BalanceOf>;
/**
* The amount of funds a contract should deposit in order to offset
* the cost of one byte.
* Let's suppose the deposit is 1,000 BU (balance units)/byte and the rent is 1 BU/byte/day,
* then a contract with 1,000,000 BU that uses 1,000 bytes of storage would pay no rent.
* But if the balance reduced to 500,000 BU and the storage stayed the same at 1,000,
* then it would pay 500 BU/day.
**/
rentDepositOffset: AugmentedConst<BalanceOf>;
/**
* Reward that is received by the party whose touch has led
* to removal of a contract.
**/
surchargeReward: AugmentedConst<BalanceOf>;
/**
* The fee required to make a transfer.
**/
transferFee: AugmentedConst<BalanceOf>;
/**
* The fee required to create an account.
**/
creationFee: 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>;
/**
* The fee required to instantiate a contract instance. A reasonable default value
* is 21.
**/
contractFee: AugmentedConst<BalanceOf>;
/**
* The base fee charged for calling into a contract. A reasonable default
* value is 135.
**/
callBaseFee: AugmentedConst<Gas>;
/**
* 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.
**/
maxDepth: AugmentedConst<u32>;
/**
* The maximum size of a storage value in bytes. A reasonable default is 16 KiB.
**/
maxValueSize: AugmentedConst<u32>;
/**
* The maximum amount of gas that could be expended per block. A reasonable
* default value is 10_000_000.
**/
blockGasLimit: AugmentedConst<Gas>;
};
nicks: {
/**
* Reservation fee.
**/
reservationFee: AugmentedConst<BalanceOf>;
/**
* The minimum length a name may be.
**/
minLength: AugmentedConst<u32>;
/**
* The maximum length a name may be.
**/
maxLength: AugmentedConst<u32>;
};
}
}
@@ -0,0 +1,706 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { AnyNumber, ITuple } from '@polkadot/types/types';
import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types/primitive';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
import { ProposalRecord } from 'sample-polkadotjs-typegen/interfaces/signaling';
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig } from '@polkadot/types/interfaces/utility';
import { VoteRecord } from 'sample-polkadotjs-typegen/interfaces/voting';
import { Observable } from 'rxjs';
import { ApiTypes } from '@polkadot/api/types';
declare module '@polkadot/api/types/storage' {
export interface AugmentedQueries<ApiType> {
system: {
/**
* Extrinsics nonce for accounts.
**/
accountNonce: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Index>>;
/**
* Total extrinsics count for the current block.
**/
extrinsicCount: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
/**
* Total weight for all extrinsics put together, for the current block.
**/
allExtrinsicsWeight: AugmentedQuery<ApiType, () => Observable<Option<Weight>>>;
/**
* Total length (in bytes) for all extrinsics put together, for the current block.
**/
allExtrinsicsLen: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
/**
* Map of block numbers to block hashes.
**/
blockHash: AugmentedQuery<ApiType, (arg: BlockNumber | AnyNumber | Uint8Array) => Observable<Hash>>;
/**
* Extrinsics data for the current block (maps an extrinsic's index to its data).
**/
extrinsicData: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Bytes>>;
/**
* The current block number being processed. Set by `execute_block`.
**/
number: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
/**
* Hash of the previous block.
**/
parentHash: AugmentedQuery<ApiType, () => Observable<Hash>>;
/**
* Extrinsics root of the current block, also part of the block header.
**/
extrinsicsRoot: AugmentedQuery<ApiType, () => Observable<Hash>>;
/**
* Digest of the current block, also part of the block header.
**/
digest: AugmentedQuery<ApiType, () => Observable<DigestOf>>;
/**
* Events deposited for the current block.
**/
events: AugmentedQuery<ApiType, () => Observable<Vec<EventRecord>>>;
/**
* The number of events in the `Events<T>` list.
**/
eventCount: AugmentedQuery<ApiType, () => Observable<EventIndex>>;
/**
* Mapping between a topic (represented by T::Hash) and a vector of indexes
* of events in the `<Events<T>>` list.
* All topic vectors have deterministic storage locations depending on the topic. This
* allows light-clients to leverage the changes trie storage tracking mechanism and
* in case of changes fetch the list of events of interest.
* The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
* the `EventIndex` then in case if the topic has the same contents on the next block
* no notification will be triggered thus the event might be lost.
**/
eventTopics: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>>;
};
utility: {
/**
* The set of open multisig operations.
**/
multisigs: AugmentedQueryDoubleMap<ApiType, (key1: AccountId | string | Uint8Array, key2: U8aFixed | string | Uint8Array) => Observable<Option<Multisig>>>;
};
timestamp: {
/**
* Current time for the current block.
**/
now: AugmentedQuery<ApiType, () => Observable<Moment>>;
/**
* Did the timestamp get updated in this block?
**/
didUpdate: AugmentedQuery<ApiType, () => Observable<bool>>;
};
authorship: {
/**
* Uncles
**/
uncles: AugmentedQuery<ApiType, () => Observable<Vec<UncleEntryItem>>>;
/**
* Author of current block.
**/
author: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>>;
/**
* Whether uncles were already set in this block.
**/
didSetUncles: AugmentedQuery<ApiType, () => Observable<bool>>;
};
indices: {
/**
* The next free enumeration set.
**/
nextEnumSet: AugmentedQuery<ApiType, () => Observable<AccountIndex>>;
/**
* The enumeration sets.
**/
enumSet: AugmentedQuery<ApiType, (arg: AccountIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
};
balances: {
/**
* The total units issued in the system.
**/
totalIssuance: AugmentedQuery<ApiType, () => Observable<Balance>>;
/**
* Information regarding the vesting of a given account.
**/
vesting: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<VestingSchedule>>>;
/**
* The 'free' balance of a given account.
* This is the only balance that matters in terms of most operations on tokens. It
* alone is used to determine the balance when in the contract execution environment. When this
* balance falls below the value of `ExistentialDeposit`, then the 'current account' is
* deleted: specifically `FreeBalance`. Further, the `OnFreeBalanceZero` callback
* is invoked, giving a chance to external modules to clean up data associated with
* the deleted account.
* `frame_system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.
**/
freeBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
/**
* The amount of the balance of a given account that is externally reserved; this can still get
* slashed, but gets slashed last of all.
* This balance is a 'reserve' balance that other subsystems use in order to set aside tokens
* that are still 'owned' by the account holder, but which are suspendable.
* When this balance falls below the value of `ExistentialDeposit`, then this 'reserve account'
* is deleted: specifically, `ReservedBalance`.
* `frame_system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.)
**/
reservedBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
/**
* Any liquidity locks on some account balances.
**/
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>>;
};
transactionPayment: {
nextFeeMultiplier: AugmentedQuery<ApiType, () => Observable<Multiplier>>;
};
staking: {
/**
* The ideal number of staking participants.
**/
validatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
/**
* Minimum number of staking participants before emergency conditions are imposed.
**/
minimumValidatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
/**
* Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
* easy to initialize and the performance hit is minimal (we expect no more than four
* invulnerables) and restricted to testnets.
**/
invulnerables: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
/**
* Map from all locked "stash" accounts to the controller account.
**/
bonded: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
/**
* Map from all (unlocked) "controller" accounts to the info regarding the staking.
**/
ledger: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<StakingLedger>>>;
/**
* Where the reward payment should be made. Keyed by stash.
**/
payee: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<RewardDestination>>;
/**
* The map from (wannabe) validator stash key to the preferences of that validator.
**/
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>>;
/**
* The map from nominator stash key to the set of stash keys of all validators to nominate.
* NOTE: is private so that we can ensure upgraded before all typical accesses.
* Direct storage APIs can still bypass this protection.
**/
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Nominations>>>;
/**
* Nominators for a particular account that is in action right now. You can't iterate
* through validators here, but you can find them in the Session module.
* This is keyed by the stash account.
**/
stakers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Exposure>>;
/**
* The currently elected validator set keyed by stash account ID.
**/
currentElected: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
/**
* The current era index.
**/
currentEra: AugmentedQuery<ApiType, () => Observable<EraIndex>>;
/**
* The start of the current era.
**/
currentEraStart: AugmentedQuery<ApiType, () => Observable<MomentOf>>;
/**
* The session index at which the current era started.
**/
currentEraStartSessionIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
/**
* Rewards for the current era. Using indices of current elected set.
**/
currentEraPointsEarned: AugmentedQuery<ApiType, () => Observable<EraPoints>>;
/**
* The amount of balance actively at stake for each validator slot, currently.
* This is used to derive rewards and punishments.
**/
slotStake: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
/**
* True if the next session change will be a new era regardless of index.
**/
forceEra: AugmentedQuery<ApiType, () => Observable<Forcing>>;
/**
* The percentage of the slash that is distributed to reporters.
* The rest of the slashed value is handled by the `Slash`.
**/
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>>;
/**
* The amount of currency given to reporters of a slash event which was
* canceled by extraordinary circumstances (e.g. governance).
**/
canceledSlashPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
/**
* All unapplied slashes that are queued for later.
**/
unappliedSlashes: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Vec<UnappliedSlash>>>;
/**
* A mapping from still-bonded eras to the first session index of that era.
**/
bondedEras: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>>;
/**
* All slashing events on validators, mapped by era to the highest slash proportion
* and slash value of the era.
**/
validatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Perbill, BalanceOf]>>>>;
/**
* All slashing events on nominators, mapped by era to the highest slash value of the era.
**/
nominatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<BalanceOf>>>;
/**
* Slashing spans for stash accounts.
**/
slashingSpans: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SlashingSpans>>>;
/**
* Records information about the maximum slash of a stash within a slashing span,
* as well as how much reward has been paid out.
**/
spanSlash: AugmentedQuery<ApiType, (arg: ITuple<[AccountId, SpanIndex]> | [AccountId | string | Uint8Array, SpanIndex | AnyNumber | Uint8Array]) => Observable<SpanRecord>>;
/**
* The earliest era for which we have a pending, unapplied slash.
**/
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>>;
/**
* The version of storage for upgrade.
**/
storageVersion: AugmentedQuery<ApiType, () => Observable<u32>>;
};
session: {
/**
* The current set of validators.
**/
validators: AugmentedQuery<ApiType, () => Observable<Vec<ValidatorId>>>;
/**
* Current index of the session.
**/
currentIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
/**
* True if the underlying economic identities or weighting behind the validators
* has changed in the queued validator set.
**/
queuedChanged: AugmentedQuery<ApiType, () => Observable<bool>>;
/**
* The queued keys for the next session. When the next session begins, these keys
* will be used to determine the validator's session keys.
**/
queuedKeys: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[ValidatorId, Keys]>>>>;
/**
* Indices of disabled validators.
* The set is cleared when `on_session_ending` returns a new set of identities.
**/
disabledValidators: AugmentedQuery<ApiType, () => Observable<Vec<u32>>>;
/**
* The next session keys for a validator.
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
* the trie. Having all data in the same branch should prevent slowing down other queries.
**/
nextKeys: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<Option<Keys>>>;
/**
* The owner of a key. The second key is the `KeyTypeId` + the encoded key.
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
* the trie. Having all data in the same branch should prevent slowing down other queries.
**/
keyOwner: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ITuple<[KeyTypeId, Bytes]> | [KeyTypeId | AnyNumber | Uint8Array, Bytes | string | Uint8Array]) => Observable<Option<ValidatorId>>>;
};
democracy: {
/**
* The number of (public) proposals that have been made so far.
**/
publicPropCount: AugmentedQuery<ApiType, () => Observable<PropIndex>>;
/**
* The public proposals. Unsorted. The second item is the proposal's hash.
**/
publicProps: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[PropIndex, Hash, AccountId]>>>>;
/**
* Map of hashes to the proposal preimage, along with who registered it and their deposit.
* The block number is the block at which it was deposited.
**/
preimages: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[Bytes, AccountId, BalanceOf, BlockNumber]>>>>;
/**
* Those who have locked a deposit.
**/
depositOf: AugmentedQuery<ApiType, (arg: PropIndex | AnyNumber | Uint8Array) => Observable<Option<ITuple<[BalanceOf, Vec<AccountId>]>>>>;
/**
* The next free referendum index, aka the number of referenda started so far.
**/
referendumCount: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
/**
* The lowest referendum index representing an unbaked referendum. Equal to
* `ReferendumCount` if there isn't a unbaked referendum.
**/
lowestUnbaked: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
/**
* Information concerning any given referendum.
**/
referendumInfoOf: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Option<ReferendumInfo>>>;
/**
* Queue of successful referenda to be dispatched. Stored ordered by block number.
**/
dispatchQueue: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>>;
/**
* Get the voters for the current proposal.
**/
votersFor: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
/**
* Get the vote in a given referendum of a particular voter. The result is meaningful only
* if `voters_for` includes the voter when called with the referendum (you'll get the
* default `Vote` value otherwise). If you don't want to check `voters_for`, then you can
* also check for simple existence with `VoteOf::exists` first.
**/
voteOf: AugmentedQuery<ApiType, (arg: ITuple<[ReferendumIndex, AccountId]> | [ReferendumIndex | AnyNumber | Uint8Array, AccountId | string | Uint8Array]) => Observable<Vote>>;
/**
* Who is able to vote for whom. Value is the fund-holding account, key is the
* vote-transaction-sending account.
**/
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
/**
* Get the account (and lock periods) to which another account is delegating vote.
**/
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[AccountId, Conviction]>>>;
/**
* True if the last referendum tabled was submitted externally. False if it was a public
* proposal.
**/
lastTabledWasExternal: AugmentedQuery<ApiType, () => Observable<bool>>;
/**
* The referendum to be tabled whenever it would be valid to table an external proposal.
* This happens when a referendum needs to be tabled and one of two conditions are met:
* - `LastTabledWasExternal` is `false`; or
* - `PublicProps` is empty.
**/
nextExternal: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[Hash, VoteThreshold]>>>>;
/**
* A record of who vetoed what. Maps proposal hash to a possible existent block number
* (until when it may not be resubmitted) and who vetoed it.
**/
blacklist: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[BlockNumber, Vec<AccountId>]>>>>;
/**
* Record of all proposals that have been subject to emergency cancellation.
**/
cancellations: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<bool>>;
};
council: {
/**
* The hashes of the active proposals.
**/
proposals: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
/**
* Actual proposal for a given hash, if it's current.
**/
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Proposal>>>;
/**
* Votes on a given proposal, if it is ongoing.
**/
voting: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Votes>>>;
/**
* Proposals so far.
**/
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
/**
* The current members of the collective. This is stored sorted (just by value).
**/
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
};
elections: {
/**
* The current elected membership. Sorted based on account id.
**/
members: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
/**
* The current runners_up. Sorted based on low to high merit (worse to best runner).
**/
runnersUp: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
/**
* The total number of vote rounds that have happened, excluding the upcoming one.
**/
electionRounds: AugmentedQuery<ApiType, () => Observable<u32>>;
/**
* Votes of a particular voter, with the round index of the votes.
**/
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<AccountId>>>;
/**
* Locked stake of a voter.
**/
stakeOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<BalanceOf>>;
/**
* The present candidate list. Sorted based on account-id. A current member or a runner can
* never enter this vector and is always implicitly assumed to be a candidate.
**/
candidates: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
};
grandpa: {
/**
* DEPRECATED
* This used to store the current authority set, which has been migrated to the well-known
* GRANDPA_AUTHORITES_KEY unhashed key.
**/
authorities: AugmentedQuery<ApiType, () => Observable<AuthorityList>>;
/**
* State of the current authority set.
**/
state: AugmentedQuery<ApiType, () => Observable<StoredState>>;
/**
* Pending change: (signaled at, scheduled change).
**/
pendingChange: AugmentedQuery<ApiType, () => Observable<Option<StoredPendingChange>>>;
/**
* next block number where we can force a change.
**/
nextForced: AugmentedQuery<ApiType, () => Observable<Option<BlockNumber>>>;
/**
* `true` if we are currently stalled.
**/
stalled: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[BlockNumber, BlockNumber]>>>>;
/**
* The number of changes (both in terms of keys and underlying economic responsibilities)
* in the "set" of Grandpa validators from genesis.
**/
currentSetId: AugmentedQuery<ApiType, () => Observable<SetId>>;
/**
* A mapping from grandpa set ID to the index of the *most recent* session for which its members were responsible.
**/
setIdSession: AugmentedQuery<ApiType, (arg: SetId | AnyNumber | Uint8Array) => Observable<Option<SessionIndex>>>;
};
treasury: {
/**
* Number of proposals that have been made.
**/
proposalCount: AugmentedQuery<ApiType, () => Observable<ProposalIndex>>;
/**
* Proposals that have been made.
**/
proposals: AugmentedQuery<ApiType, (arg: ProposalIndex | AnyNumber | Uint8Array) => Observable<Option<TreasuryProposal>>>;
/**
* Proposal indices that have been approved but not yet awarded.
**/
approvals: AugmentedQuery<ApiType, () => Observable<Vec<ProposalIndex>>>;
/**
* Tips that are not yet completed. Keyed by the hash of `(reason, who)` from the value.
* This has the insecure enumerable hash function since the key itself is already
* guaranteed to be a secure hash.
**/
tips: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<OpenTip>>>;
/**
* Simple preimage lookup from the reason's hash to the original data. Again, has an
* insecure enumerable hash since the key is guaranteed to be the result of a secure hash.
**/
reasons: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Bytes>>>;
};
contracts: {
/**
* Gas spent so far in this block.
**/
gasSpent: AugmentedQuery<ApiType, () => Observable<Gas>>;
/**
* Current cost schedule for contracts.
**/
currentSchedule: AugmentedQuery<ApiType, () => Observable<Schedule>>;
/**
* A mapping from an original code hash to the original code, untouched by instrumentation.
**/
pristineCode: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<Bytes>>>;
/**
* A mapping between an original code hash and instrumented wasm code, ready for execution.
**/
codeStorage: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<PrefabWasmModule>>>;
/**
* The subtrie counter.
**/
accountCounter: AugmentedQuery<ApiType, () => Observable<u64>>;
/**
* The code associated with a given account.
**/
contractInfoOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ContractInfo>>>;
/**
* The price of one unit of gas.
**/
gasPrice: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
};
identity: {
/**
* Information that is pertinent to identify the entity behind an account.
**/
identityOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Registration>>>;
/**
* The super-identity of an alternative "sub" identity together with its name, within that
* context. If the account is not some other account's sub-identity, then just `None`.
**/
superOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[AccountId, Data]>>>>;
/**
* Alternative "sub" identities of this account.
* The first item is the deposit, the second is a vector of the accounts.
**/
subsOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>>;
/**
* The set of registrars. Not expected to get very big as can only be added through a
* special origin (likely a council motion).
* The index into this can be cast to `RegistrarIndex` to get a valid value.
**/
registrars: AugmentedQuery<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>>;
};
imOnline: {
/**
* The block number after which it's ok to send heartbeats in current session.
* At the beginning of each session we set this to a value that should
* fall roughly in the middle of the session duration.
* The idea is to first wait for the validators to produce a block
* in the current session, so that the heartbeat later on will not be necessary.
**/
heartbeatAfter: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
/**
* The current set of keys that may issue a heartbeat.
**/
keys: AugmentedQuery<ApiType, () => Observable<Vec<AuthorityId>>>;
/**
* For each session index, we keep a mapping of `AuthIndex`
* to `offchain::OpaqueNetworkState`.
**/
receivedHeartbeats: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: AuthIndex | AnyNumber | Uint8Array) => Observable<Option<Bytes>>>;
/**
* For each session index, we keep a mapping of `T::ValidatorId` to the
* number of blocks authored by the given authority.
**/
authoredBlocks: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>>;
};
offences: {
/**
* The primary structure that holds all offence records keyed by report identifiers.
**/
reports: AugmentedQuery<ApiType, (arg: ReportIdOf | string | Uint8Array) => Observable<Option<OffenceDetails>>>;
/**
* A vector of reports of the same kind that happened at the same time slot.
**/
concurrentReportsIndex: AugmentedQueryDoubleMap<ApiType, (key1: Kind | string | Uint8Array, key2: OpaqueTimeSlot | string | Uint8Array) => Observable<Vec<ReportIdOf>>>;
/**
* Enumerates all reports of a kind along with the time they happened.
* All reports are sorted by the time of offence.
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
* different types are not supported at the moment so we are doing the manual serialization.
**/
reportsByKindIndex: AugmentedQuery<ApiType, (arg: Kind | string | Uint8Array) => Observable<Bytes>>;
};
randomnessCollectiveFlip: {
/**
* Series of block headers from the last 81 blocks that acts as random seed material. This
* is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
* the oldest hash.
**/
randomMaterial: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
};
nicks: {
/**
* The lookup table for names.
**/
nameOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Bytes, BalanceOf]>>>>;
};
sudo: {
/**
* The `AccountId` of the sudo key.
**/
key: AugmentedQuery<ApiType, () => Observable<AccountId>>;
};
signaling: {
/**
* The total number of proposals created thus far.
**/
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
/**
* A list of all extant proposals.
**/
inactiveProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
/**
* A list of active proposals along with the time at which they complete.
**/
activeProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
/**
* A list of completed proposals, pending deletion
**/
completedProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
/**
* Amount of time a proposal remains in "Voting" stage.
**/
votingLength: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
/**
* Map for retrieving the information about any proposal from its hash.
**/
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ProposalRecord>>>;
/**
* Registration bond
**/
proposalCreationBond: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
};
voting: {
/**
* The map of all vote records indexed by id
**/
voteRecords: AugmentedQuery<ApiType, (arg: u64 | AnyNumber | Uint8Array) => Observable<Option<VoteRecord>>>;
/**
* The number of vote records that have been created
**/
voteRecordCount: AugmentedQuery<ApiType, () => Observable<u64>>;
};
treasuryReward: {
/**
* Interval in number of blocks to reward treasury
**/
mintingInterval: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
/**
* Current payout of module
**/
currentPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
/**
* Current pot
**/
pot: AugmentedQuery<ApiType, () => Observable<Balance>>;
};
}
export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import '@polkadot/api/augment/rpc';
import './augment-api-consts';
import './augment-api-query';
import './augment-api-tx';
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
// order here matches with what is found in (unused removed)
// https://www.npmjs.com/package/edgeware-node-types
// https://github.com/hicommonwealth/edgeware-node-types/tree/master/types
export { default as signaling } from './signaling/definitions';
export { default as treasuryRewards } from './treasuryRewards/definitions';
export { default as voting } from './voting/definitions';
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/camelcase */
export default {
types: {
ProposalRecord: {
index: 'u32',
author: 'AccountId',
stage: 'VoteStage',
transition_time: 'u32',
title: 'Text',
contents: 'Text',
vote_id: 'u64'
},
ProposalContents: 'Vec<u8>',
ProposalTitle: 'Vec<u8>'
}
};
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './types';
@@ -0,0 +1,24 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Struct } from '@polkadot/types/codec';
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
import { AccountId } from '@polkadot/types/interfaces/runtime';
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
/** @name ProposalContents */
export interface ProposalContents extends Bytes {}
/** @name ProposalRecord */
export interface ProposalRecord extends Struct {
readonly index: u32;
readonly author: AccountId;
readonly stage: VoteStage;
readonly transition_time: u32;
readonly title: Text;
readonly contents: Text;
readonly vote_id: u64;
}
/** @name ProposalTitle */
export interface ProposalTitle extends Bytes {}
@@ -0,0 +1,7 @@
/* eslint-disable @typescript-eslint/camelcase */
export default {
types: {
Balance2: 'u128'
}
};
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './types';
@@ -0,0 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { u128 } from '@polkadot/types/primitive';
/** @name Balance2 */
export interface Balance2 extends u128 {}
@@ -0,0 +1,6 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './signaling/types';
export * from './treasuryRewards/types';
export * from './voting/types';
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/camelcase */
export default {
types: {
VoteStage: {
_enum: ['PreVoting', 'Commit', 'Voting', 'Completed']
},
VoteType: {
_enum: ['Binary', 'MultiOption', 'RankedChoice']
},
TallyType: {
_enum: ['OnePerson', 'OneCoin']
},
VoteOutcome: '[u8; 32]',
Tally: 'Option<Vec<(VoteOutcome, u128)>>',
VoteData: {
initiator: 'AccountId',
stage: 'VoteStage',
vote_type: 'VoteType',
tally_type: 'TallyType',
is_commit_reveal: 'bool'
},
Commitments: 'Vec<(AccountId, VoteOutcome)>',
Reveals: 'Vec<(AccountId, Vec<VoteOutcome>)>',
VoteRecord: {
id: 'u64',
commitments: 'Commitments',
reveals: 'Reveals',
data: 'VoteData',
outcomes: 'Vec<VoteOutcome>'
}
}
};
@@ -0,0 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './types';
@@ -0,0 +1,58 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { bool, u128, u64 } from '@polkadot/types/primitive';
import { AccountId } from '@polkadot/types/interfaces/runtime';
/** @name Commitments */
export interface Commitments extends Vec<ITuple<[AccountId, VoteOutcome]>> {}
/** @name Reveals */
export interface Reveals extends Vec<ITuple<[AccountId, Vec<VoteOutcome>]>> {}
/** @name Tally */
export interface Tally extends Option<Vec<ITuple<[VoteOutcome, u128]>>> {}
/** @name TallyType */
export interface TallyType extends Enum {
readonly isOnePerson: boolean;
readonly isOneCoin: boolean;
}
/** @name VoteData */
export interface VoteData extends Struct {
readonly initiator: AccountId;
readonly stage: VoteStage;
readonly vote_type: VoteType;
readonly tally_type: TallyType;
readonly is_commit_reveal: bool;
}
/** @name VoteOutcome */
export interface VoteOutcome extends U8aFixed {}
/** @name VoteRecord */
export interface VoteRecord extends Struct {
readonly id: u64;
readonly commitments: Commitments;
readonly reveals: Reveals;
readonly data: VoteData;
readonly outcomes: Vec<VoteOutcome>;
}
/** @name VoteStage */
export interface VoteStage extends Enum {
readonly isPreVoting: boolean;
readonly isCommit: boolean;
readonly isVoting: boolean;
readonly isCompleted: boolean;
}
/** @name VoteType */
export interface VoteType extends Enum {
readonly isBinary: boolean;
readonly isMultiOption: boolean;
readonly isRankedChoice: boolean;
}
@@ -0,0 +1,34 @@
{
"compilerOptions": {
// this is specific with augmented overrides
"paths": {
// this is the package name we use (in the interface imports, --package for generators)
"sample-polkadotjs-typegen/*": ["src/*"],
// here we replace the @polkadot/api augmentation with our own, generated from chain
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
// replace the augmented types with our own, as generated from definitions
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
},
// some other options, whatever you want for your environment
"target": "esnext",
"module": "esnext",
"jsx": "preserve",
"declaration": true,
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"baseUrl": ".",
"skipLibCheck": true,
"typeRoots": [
"./node_modules/@types"
]
},
"exclude": [
"build/**/*",
"node_modules"
]
}
@@ -25,12 +25,12 @@ async function main () {
if (balance[0] === 'first') {
// Now we know that if the previous value emitted as balance[0] is `first`,
// then balance[1] is the initial value of Alice account.
console.log(`Alice ${Alice} has a balance of ${balance[1][1].free}`);
console.log(`Alice ${Alice} has a balance of ${balance[1].data.free}`);
console.log('You may leave this example running and start the "Make a transfer" example or transfer any value to Alice address');
return;
}
const change = balance[1][1].free.sub(balance[0][1].free);
const change = balance[1].data.free.sub(balance[0].date.free);
// Only display value changes
if (!change.isZero()) {
+4 -4
View File
@@ -36,16 +36,16 @@ function main () {
})
)
// Then we're subscribing to the emitted results
.subscribe(([[accountNonce], blockPeriod, validators, validatorBalances]) => {
console.log(`accountNonce(${Alice}) ${accountNonce}`);
.subscribe(([{ nonce }, blockPeriod, validators, validatorBalances]) => {
console.log(`accountNonce(${Alice}) ${nonce}`);
console.log(`blockPeriod ${blockPeriod.toNumber()} seconds`);
if (validatorBalances) {
// And lastly we print out the authorityIds and balances of all validators
console.log('validators', validators.map((authorityId, index) => ({
address: authorityId.toString(),
balance: validatorBalances[index][1].free.toString(),
nonce: validatorBalances[index][0].toString()
balance: validatorBalances[index].data.free.toString(),
nonce: validatorBalances[index].data.toString()
})));
}
});
+7 -2
View File
@@ -25,9 +25,14 @@ async function main () {
.signAndSend(alice)
// Subscribe to the status updates of the transfer
.subscribe(({ status }) => {
if (status.isFinalized) {
console.log(`Successful transfer of 12345 from Alice to Bob with hash ${status.asFinalized.toHex()}`);
if (status.isInBlock) {
console.log(`Successful transfer of 12345 from Alice to Bob at block ${status.asInBlock.toHex()}`);
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
subscription.unsubscribe();
process.exit(0);
} else {
console.log(`Status of transfer: ${status.type}`);
}
+6 -2
View File
@@ -44,13 +44,17 @@ async function main () {
console.log('Transfer status:', status.type);
// Log system events once the transfer is finalised
if (status.isFinalized) {
console.log('Completed at block hash', status.asFinalized.toHex());
if (status.isInBlock) {
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');
events.forEach(({ phase, event: { data, method, section } }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
process.exit(0);
}
});
}
+5 -5
View File
@@ -40,16 +40,16 @@ async function main () {
// Log transfer events
console.log('Proposal status:', status.type);
if (status.isFinalized) {
if (status.isInBlock) {
console.error('You have just upgraded your chain');
console.log('Completed at block hash', status.asFinalized.toHex());
console.log('Included at block hash', status.asInBlock.toHex());
console.log('Events:');
// Log system events once the chain update is finalised
events.forEach(({ phase, event: { data, method, section } }) => {
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
});
console.log(JSON.stringify(events.toHuman(), null, 2));
} else if (status.isFinalized) {
console.log('Finalized block hash', status.asFinalized.toHex());
process.exit(0);
}
@@ -1,3 +1,5 @@
**NOTE** Removed - in metadata v11 we get the extensions from the chain, we need to be able to specify these. These docs are now outdated.
# Extending extrinsics
On some chains, the need may arise to customize the extrinsic format. In this section we will explain what extrinsics and their payloads contain, explain how signed extensions work and provide a walk through of an advanced use-case where extrinsics are customized for a specific Substrate chain.
@@ -153,6 +155,3 @@ In the above example, should these updates only be made on the node side, withou
(These extensions are not exposed via metadata at all, and would be quite difficult to do as well - since each of these have specific logic as well as data types assigned.)
## Using with TypeScript
The API is built with TypeScript (as are all projects in the [polkadot-js organization](https://github.com/polkadot-js/)) and as such allows developers using TS to have access to all the type interfaces defined on the chain, as well as having access to typings on interacting with the `api.*` namespaces. In the next section we will provide an overview of [what is available in terms of types and TypeScript](typescript.md).
+11 -1
View File
@@ -12,6 +12,14 @@ If however you are running against a master branch of either Polkadot or Substra
Update your version of the API to the [latest version](install.md). Like types, the [metadata interfaces](basics.md) are continuously evolving. For instance with the Polkadot Alexander network, only metadata v3 is available. By the time Kusama launched, this has been bumped to v7. As these versions are added to the Polkadot/Substrate codebase, they are added to the API.
## The node returns a "Could not convert" error on send
The typical error that you would see is `Verification Error: Execution(ApiError("Could not convert parameter 'tx' between node and runtime`. This means that the transaction data serialized from the API cannot be deserialized on the node.
All data transferred between the API and the Node is in a SCALE-encoded binary format, so the [definition of the types](types.extend.md) between the API and the node needs to match 100%. When you find the above, it would mean the definition of the types on the API side does not match what is on the node. Specifically the API encodes against the definition, but since there is a mismatch the Node cannot parse the data correctly.
To fix this, you should look at the specific `api.tx.*` params and adjust the type definitions for those param types to match what is found on the node side. In some rare cases the cause could be extrinsic formatting related, to track these make an `api.tx.system.remark(data: Bytes)` call, if it fails, the API and node cannot agree on [an extrinsic format and adjustments are required](types.extend.md#impact-on-extrinsics).
## I would like to sign transactions offline
The API itself is independent on where the signature comes from and how it is injected. Additionally it implements a signer interface, that can be used for external signing - an example of this is the [polkadot-js/apps](https://github.com/polkadot-js/apps) support for signing via extensions and even the [polkadot-js/extension](https://github.com/polkadot-js/extension) support for tools such as the [Parity Signer](https://github.com/paritytech/parity-signer).
@@ -36,6 +44,8 @@ The length for this transaction validity is set to 50 blocks, which translates t
## My chain does not support system.account queries
The API always tracks the latest Substrate master in terms of examples. This means that nonce & balance queries are done via the `api.query.system.account(<account>)` which returns a Tuple `(Index, AccountData)` where the first is the nonce, the second a struct containing the free and reserved balances. As with all `api.query.*` endpoint, this is decorated based on what the chain you connect to support.
The API always tracks the latest Substrate master in terms of examples. This means that nonce & balance queries are done via the `api.query.system.account(<account>)` which returns a struct `{ nonce: Index, data: AccountData }` where the `data` is struct containing the free and reserved balances. As with all `api.query.*` endpoints, this is decorated based on what the chain you connect to support, via the metadata exchange.
It is possible that you are connecting to an older chain that has not been upgraded yet. For these chains, this storage entry won't be available (yet). To query the nonce on older chains, you can do a query to `api.query.system.accountNonce(<account>)` and balances can be retrieved via `api.query.balances.freeBalance(<account>)`.
Likewise, if your chain has been upgraded recently and you are still using the old `system.accountNonce` or `balances.freeBalance` queries in your code (which is now not available in the chain metadata), you need to update it to query the new location.
+2 -2
View File
@@ -17,7 +17,7 @@ const ADDR = '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE';
const now = await api.query.timestamp.now();
// Retrieve the account balance & nonce via the system module
const [nonce, balance] = await api.query.system.account(ADDR);
const { nonce, data: balance } = await api.query.system.account(ADDR);
console.log(`${now}: balance of ${balance.free} and a nonce of ${nonce}`);
```
@@ -27,7 +27,7 @@ There have been some additions in the code above comparing with retrieving runti
```js
...
// Retrieve last block timestamp, account nonce & balances
const [now, [nonce, balances]] = await Promise.all([
const [now, { nonce, data: balances }] = await Promise.all([
api.query.timestamp.now(),
api.query.system.account(ADDR)
]);
+2 -2
View File
@@ -11,7 +11,7 @@ Where possible, the use of multi queries are encouraged since it tracks a number
// Subscribe to balance changes for 2 accounts, ADDR1 & ADDR2 (already defined)
const unsub = await api.query.system.account.multi([ADDR1, ADDR2], (balances) => {
const [[, balance1], [, balance2]] = balances;
const [{ data: balance1 }, { data: balance2 }] = balances;
console.log(`The balances are ${balance1.free} and ${balance2.free}`);
});
@@ -44,7 +44,7 @@ The previous `.multi` examples assumes that we do queries for the same types, i.
const unsub = await api.queryMulti([
api.query.timestamp.now,
[api.query.system.account, ADDR]
], ([now, [nonce, balance]]) => {
], ([now, { nonce, data: balance }]) => {
console.log(`${now}: balance of ${balance.free} and a nonce of ${nonce}`);
});
```
+1 -1
View File
@@ -13,7 +13,7 @@ Quite often is is useful (taking pruning into account, more on this later) to re
const lastHdr = await api.rpc.chain.getHeader();
// Retrieve the balance at both the current and the parent hashes
const [[, balanceNow], [, balancePrev]] = await Promise.all([
const [{ data: balanceNow }, { data: balancePrev }] = await Promise.all([
api.query.system.account.at(lastHdr.hash, ADDR),
api.query.system.account.at(lastHdr.parentHash, ADDR)
]);
+1 -1
View File
@@ -25,7 +25,7 @@ If we had a query with parameters, i.e. where we wish to perform a query for a s
...
// Subscribe to balance changes for our account
const unsub = await api.query.system.account(ADDR, ([nonce, balance]) => {
const unsub = await api.query.system.account(ADDR, ({ nonce, data: balance }) => {
console.log(`free balance is ${balance.freee} with ${balance.reserved} reserved and a nonce of ${nonce}`);
});
```
+1 -1
View File
@@ -28,7 +28,7 @@ The result for this call (we will deal with subscriptions in a short while), is
Despite the single-line format of `signAndSend`, there is a lot happening under the hood (and all of this can be manually provided) -
- Based on the sender, the API will retrieve the `system.accountNonce` to determine the next nonce to use
- Based on the sender, the API will query `system.account` (or `system.accountNonce` on older chains) to determine the next nonce to use
- The API will retrieve the current block hash and use it to create a mortal transaction, i.e. the transaction will only be valid for a limited number of blocks (by default this is 5 mins at 6s block times)
- It will construct a payload and sign this, this includes the `genesisHash`, the `blockHash` for the start of the mortal era as well as the current chain `specVersion`
- The transaction is submitted to the node
+5 -3
View File
@@ -18,8 +18,10 @@ const unsub = await api.tx.balances
.signAndSend(alice, (result) => {
console.log(`Current status is ${result.status}`);
if (result.status.isFinalized) {
console.log(`Transaction included at blockHash ${result.status.asFinalized}`);
if (result.status.isInBlock) {
console.log(`Transaction included at blockHash ${result.status.asInBlock}`);
} else if (result.status.isFinalized) {
console.log(`Transaction finalized at blockHash ${result.status.asFinalized}`);
unsub();
}
});
@@ -27,7 +29,7 @@ const unsub = await api.tx.balances
As per all previous subscriptions, the transaction subscription returns in `unsub()` and the actual method has a subscription callback. The `result` object has 2 parts, `events` (to to covered in the next section) and the `status` enum.
When the `status` enum is in `Finalized` state (checked via `isFinalized`), the underlying value contains the block hash of the block where the transaction has been included. This does not mean the block is finalized, but rather applies to the transaction state, as no further updates will be received for this subscription.
When the `status` enum is in `Finalized` state (checked via `isFinalized`), the underlying value contains the block hash of the block where the transaction has been finalized. `Finalized` will follow `InBlock`, which is the block where the transaction has been included. `InBlock` does not mean the block is finalized, but rather applies to the transaction state, where `Finalized` means that the transaction cannot be forked off the chain.
## Transaction events
+3 -1
View File
@@ -6,7 +6,7 @@ To unpack this, we will start with the Metadata and explain what it actually pro
## Metadata
When the API connects to a node, one of the first things it does is to retrieve the metadata. The metadata, effectively provides data in the form of `api.<type>.<module>.<section>` that fits into one of the following categories -
When the API connects to a node, one of the first things it does is to retrieve the metadata and decorate the API based on the metadata information. The metadata effectively provides data in the form of `api.<type>.<module>.<section>` that fits into one of the following categories -
- [consts](../substrate/constants.md) - All runtime constants, e.g. `api.consts.balances.existentialDeposit`. These are not functions, rather accessing the endpoint immediately yields the result as defined.
- [query](../substrate/storage.md) - All chain state, e.g. `api.query.system.account(<accountId>)`.
@@ -14,6 +14,8 @@ When the API connects to a node, one of the first things it does is to retrieve
Additionally the metadata also provides information on [events](../substrate/events.md), these are query-able via the `api.query.system.events()` interface and also appear on transactions... both these cases are detailed later.
None of the information contained within the `api.{consts, query, tx}.<module>.<method>` endpoints are hard coded in the API. Rather everything is fully decorated by what the metadata exposes and is therefore completely dynamic. This means that when you connect to different chains, the metadata and API decoration will change and the API interfaces will reflect what is available on the chain you are connected to.
## Types
The metadata defines the calls with all the type names used in the various interfaces. At the moment (this is undergoing investigations and could improve in future versions of metadata), this also means that the types between the API and the node need to be aligned. For instance, by default Substrate defines a `BlockNumber` type as a `u32` and the API follows the Substrate defaults - if a chain has a different definitions, the API needs to be aware of this so it can actually decode (and encode) the type.
+6
View File
@@ -68,6 +68,12 @@ await api.isReady;
console.log(api.genesisHash.toHex());
```
## Failures
In all cases the API will handle reconnections automatically. This means that when you connect and the endpoint is not (yet) ready, the promise will not resolve immediately, but rather when connected. The same applies to when connection is lost, the API will manage re-connections.
In cases where the API does not support the chain being connected to, such as it using an unknown metadata version, the ready promise will fail to resolve and instead reject.
## Advanced creation
There are more advanced cases where you would prefer to use the longer version, for instance: if you want to explicitly listen to events emitted, you probably want to attach to the API even before connecting to the chain. All API instances implement an `EventEmitter` interface, with `on` handlers, which emit `connected`, `disconnected`, `ready` and `error` events, allowing you to listen to events on the transport layer.
+3 -1
View File
@@ -27,7 +27,7 @@ For example:
```js
const { metadata } = await api.rpc.state.getMetadata();
const modules = metadata.asV3.modules;
const modules = metadata.asLatest.modules;
// This will not work, because `name` is an instance of `Text`, not a string
// const system = modules.find(m => m.name === 'system');
@@ -79,6 +79,8 @@ const [count, accountId] = tuple;
console.log(`${accountId} has ${count.toNumber()} values`);
```
When making a call that expect a `Tuple` input, pass it as an array, so to pass the example above into a call, it would be `.call([123, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'])`
## Extending types
For customized chains, the need exists to register types so the API is aware of how to decode values for those types. The next section will provide a [walk-through for the definition of custom types](types.extend.md) allowing the definition or re-definition of any type the API is aware of.
+56
View File
@@ -0,0 +1,56 @@
# Type creation
Circling back to metadata. There are two important things to remember when using the API to make queries or send transactions.
1. The functionality available, e.g. exposed on `api.query.*` is not hard-coded in the API, rather this is decorated from the chain metadata. So the metadata lets the API know which endpoints are available and what the type for those endpoints are.
2. When you supply a value to the API, internally it will convert that value to the correct type as expected by the chain, i.e. as determined by the metadata. This means that a function such as `balances.transfer(address: Address, value: Balance)` can take at least the following inputs, which are all converted to the correct types -
- `address` can be an `Address`, an `AccountId`, an `Uint8Array` publicKey, a hex publicKey or an ss58 formatted address;
- `value` can be a `Balance`, a value encoded in hex, a `BN` object, a base-10 string, a JS `number`, a JS `BigInt` or even a SCALE-encoded `Uint8Array`
In cases where a value is returned such as storage queries, the response from the chain is always encoded into the correct `Codec` type. This means that while the node may return an encoded block (with encoded extrinsics) via `api.rpc.chain.getBlock()`, this is decoded into a proper `SignedBlock` by the API. Outputting this value via `.toJSON()` will yield an encoding for RPC, so if you are not using TypeScript (which adds code helpers on decoded objects), a representation via `.toHuman()` will be more representative of the actual object fields, re-formatted for human consumption.
## Why create types
With the conversions done in the API, there are limited reasons to create types "manually". However, just because there are not thousands of reasons, does not mean it is not valid. For instance, you may retrieve an `Option` and for the sake of sanity would like to use `.unwrapOr()` on it, returning a `Codec` default value where the value `.isNone`.
```js
// type import for TypeScript
import type { Balance } from '@polkadot/types/interfaces';
...
// unwrap out option into a zero Balance whn not found
// (This can be done via `.unwrapOrDefault()`, which does the same underlying)
const balance: Balance = balanceOpt.unwrapOr(api.createType('Balance'));
```
In the example above, we introduced the `api.createType(<typeName>, [<value>])`. The same format is also exposed by the `TypeRegistry` (more on this in a short while) as well as `createType(...)` from the actual `@polkadot/types` package. All doing exactly the same.
## Choosing how to create
In most cases, you would always want to use the `api.createType` helper. What this does is call the underlying `@polkadot/types` `createType`, passing through the registry that is attached to the API. Registry? Yes, registry.
The registry contains a listing of all internal types and their classes that have been registered. So upon creation of an API instance, a `registry` object is attached to the API and this is passed through to all created types. This allows the type definitions to not pollute the global namespace, but rather be contained and able to reference one another.
As mentioned, the `createType` functions all do exactly the same, and it 99.99% of the cases you would be recommended to just forget about everything and use `api.createType` if and when required. In some cases, you may just have a type object and from that want to create another type instance. For that you can access the `registry` on the type object and call `createType` on it. (If this type object was created from an API instance, the registry on the type and on the API will point to the same instance.)
Basically, this means that we have equivalency in creation for all the items below, all creating on the same registry (containing all injected types), and all wrapping the same value -
```js
import { createType } from '@polkadot/types';
// via API (recommended)
api.createType('Balance', 123);
// via registry (`.registry` is on all API and Codec objects)
api.registry.createType('Balance', 123n);
// via the low-level approach (not recommended)
createType(api.registry, 'Balance', '123');
```
## Using with TypeScript
The API is built with TypeScript (as are all projects in the [polkadot-js organization](https://github.com/polkadot-js/)) and as such allows developers using TS to have access to all the type interfaces defined on the chain, as well as having access to typings on interacting with the `api.*` namespaces. In the next section we will provide an overview of [what is available in terms of types and TypeScript](typescript.md).
+69 -5
View File
@@ -10,7 +10,7 @@ There is a the [recommendation](install.md#betas) to use a `@polkadot/api@beta`
## Extension
As a blockchain toolkit, Substrate makes it easy to add your own modules and types. In most non-trivial implementations, this would mean that developers are adding specific types for their implementation as well. The API will get to know the names of these types via the metadata, however it won't understand what they are, which means it cannot encode or decode them.
As a blockchain toolkit, Substrate makes it easy to add your own modules and types. In most non-trivial implementations, this would mean that developers are adding specific types for their implementation as well. The API will get to know the names of these types via the metadata, however it won't understand what they are, which means it cannot encode or decode them. Additionally, when a type is mismatched between the node and the API, the decoding can fail, yielding issues such as [Could not convert errors](FAQ.md#the-node-returns-a-could-not-convert-error-on-send) when submitting transactions.
To close this gap, the API allows for the injection of types, i.e. you can explicitly define (or override) types for the node/chain you are connecting to. In the simplest example, assuming you have a chain where your `Balance` type is a `u64` (as opposed to the default `u128`), you need to let the API know -
@@ -26,7 +26,7 @@ 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.
## User-defined types
## 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 -
@@ -54,6 +54,30 @@ const api = await ApiPromise.create({
The example above defines non-primitive types (as found in the specific implementation) as structures. Additionally it also shows the user-defined types can depend on other user-defined types with `Transaction` referencing both `TransactionInput` and `TransactionOutput`. Here you can reference any known types, i.e. in the above we have referenced primitives such as `u32` and `Signature` (itself an alias for `H512`).
## Definition clashes
As explained in a previous section, the underlying API Codec types have a [number of built-in properties](type.basics.md) and in some cases it could be that your struct has a field that conflicts. These should be minimal, however it can happen. Take the following example where a defined `hash` property clashes with the same-name Codec property -
```js
Document: {
name: 'Text',
uri: 'Text',
hash: 'Text'
}
```
For this struct the `hash` will not be exposed, but rather be kept as the built-in `hash`. At this point it is important to know that the values "over-the-wire" for calls, queries, events and consts is in binary form, i.e. it is an encoding of the values only. So on the JS side you can apply a rename with no ill-effects. Here we rename the `hash` to `docHash`, which mean the value will be available on `<instance>.docHash`.
```js
Document: {
name: 'Text',
uri: 'Text',
docHash: 'Text'
}
```
## User-defined enum
One form of types that appear regularly is enums, these can be defined as follow -
```js
@@ -109,7 +133,7 @@ In the same way `typesChain` can be used to match on the actual chain name, i.e.
const api = await ApiPromise.create({
...,
typesChain: {
'Kusama CC1': {
Kusama: {
BlockNumber: 'u32',
Index: 'u32'
}
@@ -137,6 +161,46 @@ const api = await ApiPromise.create({
`Balance` would be defined as an `u128` at the end. Effectively based on the flow it is first registered as a `u32`, then overridden as a `u64` and finally overridden once more as a `u128` by the chain types.
## Extending extrinsics
## Impact on extrinsics
On customized chains, it is possible to [extend the format of the extrinsics and extrinsic payload as customized on the chain](extrinsic.extend.md), next up we will look at this advanced use-case.
When configuring your chain, be cognizant of the types you are using, and always ensure that any changes are replicated back to the API. In an earlier example we configured `Balance` as `u64`, in this case the same changes needs to be applied on the API, especially when there are mismatches compared to Substrate master. Not doing so means that failures will occur. The same would happen when your own types have mismatched fields or types are lacking fields on structs or enums.
Mismatches also applies to any other chain-specific configured types and can have impacts on transactions. For instance you can customize `Lookup` and `Address` on your chain, changing the default lookup behavior. A real example of this is the Substrate master node vs the Substrate master node-template -
```rust
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = Indices;
...
/// The address format for describing accounts.
pub type Address = <Indices as StaticLookup>::Source;
```
And this is what is defined on the node-template -
```rust
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = IdentityLookup<AccountId>;
...
/// The address format for describing accounts.
pub type Address = AccountId;
```
Here the template was customized from the Substrate node defaults and the API needs to know how to map these types. Failure to make adjustments means transactions will fail. With this in mind the correct types that needs to be added here would be -
```js
const api = await ApiPromise.create({
...,
types: {
// mapping the actual specified address format
Address: 'AccountId',
// mapping the lookup
LookupSource: 'AccountId'
}
});
```
Always look at customization and understand the impacts, replicating these changes between the node and the API. For the above the `Address` type is used in the construction of the `UncheckedExtrinsic` type, while the lookup type is applicable on transactions such as `balances.transfer(to: LookupSource, value: Balance)`
## Type creation
While the API always converts all the inputs into the underlying type required by the operation, in some cases you may want to [create an instance of a type](types.create.md) yourself.
+8 -13
View File
@@ -23,27 +23,22 @@ In the subscription example, we explicitly define `lastHead: Header`, although t
As indicated, most of the Polkadot/Substrate default types are available via `types/interfaces`. However, for primitives types where there is an actual implementation, these are made available via `@polkadot/types` directly. For instance, `import { u32 } from '@polkadot/types` is valid in this context.
## Metadata injected
## Storage generics
For any interface injected by metadata, the types are not available by default (although it may be in the future for default interfaces), but rather what the API understands is that all results need to comply to the `Codec` interface. (The base of all our types)
For any interface injected by metadata, the types are not fully described but rather names and the API will decode all these into an instance that complies with the `Codec` interface. (The base of all our types)
However, to make this sane from a developer perspective the injected methods are generic, effectively making the following possible -
However, this does allow you to perform overrides via generics, making the following possible -
```js
import { AccountData, Index } from '@polkadot/types/interfaces';
import { Balance } from '@polkadot/types/interfaces';
type Balance2 = Balance;
...
const [nonce, balance] = await api.query.system.account<[Index, AccountData]>(ADDR);
const total = await api.query.balances.totalIssuance<Balance2>();
```
In both these case we can instruct the TypeScript compiler that the type we are expecting in `Index` and `Balance` respectively, not just pure `Codec`. This means that functions like `.toNumber()` is available on both these types - as opposed to just the [general type defaults](types.basics.md#everything-is-a-type) with `.toHex()` and friends.
## Future work
As of this writing, there are still some gray areas to type detection, specifically around the following interfaces -
- `.at` & `.multi` on `api.query` does not (yet) have a `<TypeOverride>` interface. This means `as <TypeOverride>` casts are presently needed for these results
- `api.queryMulti` does not (yet) allow you to provide a hint to the types returned, this ties to the previous point
In this example (although the query does indeed return a `Balance`) we can instruct the TypeScript compiler that we are expecting a `Balance2`, not just the interface as generated. This means that functions like `.toNumber()` is available on both these types - as opposed to just the [general type defaults](types.basics.md#everything-is-a-type) with `.toHex()` and friends.
## Adding user types
+11 -7
View File
@@ -1,25 +1,29 @@
# TypeScript user generated
In the previous section we looked at the TypeScript definitions that are available and is generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your onw defintions and chain types.
In the previous section we looked at the TypeScript definitions that are available and is generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your onw definitions and chain types.
## 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).
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.
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.
- `stuff/interfaces/<module>/definitions.ts` for each module (`types.ts` & `index.ts` will be generated)
- `stuff/interfaces/defnitions.ts` importing all sub-definitions`
- `stuff/interfaces/definitions.ts` importing all sub-definitions`
With this structure setup, you can generate TypeScript defintions.
With this structure setup, you can generate TypeScript definitions.
In the root of your project (with the `@polkadot/api`), you can run `yarn polkadot-types-from-defs --input ./stuff/interfaces --package @MeInc/stuff/interfaces` which will create `types.ts` and `index.ts` files with the generated types. You can use these in exactly the same way as you would use your types from `@polkadot/types/interfaces`.
In the root of your project (with the `@polkadot/typegen` package installed), you can run `yarn polkadot-types-from-defs --input ./stuff/interfaces --package @MeInc/stuff/interfaces` which will create `types.ts` and `index.ts` files with the generated types. You can use these in exactly the same way as you would use your types from `@polkadot/types/interfaces`.
## Chain modules
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from chain from metadata, generate a complete `api.{consts,query}.*` defintion for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript defintions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliassing).
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from chain from metadata, generate a complete `api.{consts,query}.*` definition for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript definitions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliasing).
In the root of your project, you can run `yarn polkadot-types-from-chain --endpoint wss://<url> --output ./stuff` and it will create the required output. (Here you can specify an optional `--package @MeInc/stuff` to read definitions for the targetted output folder with the specified package name.)
In the root of your project, you can run `yarn polkadot-types-from-chain --endpoint wss://<url> --output ./stuff` and it will create the required output. (Here you can specify an optional `--package @MeInc/stuff` to read definitions for the targeted output folder with the specified package name.)
## Example of actual use
The [TypeScript augmentation example](../examples/promise/90_typegen/) example provides a full real-world example of these scripts in action. Additionally it shows all the configurations from a TypeScript as well as an in-use perspective, showing how the types and interfaces are fully augmented based on the provided metadata.
## And that's a wrap
+2 -2
View File
@@ -7,19 +7,19 @@ module.exports = Object.assign({}, config, {
'@polkadot/api-contract(.*)$': '<rootDir>/packages/api-contract/src/$1',
'@polkadot/api-derive(.*)$': '<rootDir>/packages/api-derive/src/$1',
'@polkadot/api(.*)$': '<rootDir>/packages/api/src/$1',
'@polkadot/jsonrpc(.*)$': '<rootDir>/packages/jsonrpc/src/$1',
'@polkadot/metadata(.*)$': '<rootDir>/packages/metadata/src/$1',
'@polkadot/rpc-(core|provider)(.*)$': '<rootDir>/packages/rpc-$1/src/$2',
'@polkadot/jsonrpc(.*)$': '<rootDir>/packages/type-jsonrpc/src/$1',
'@polkadot/types(.*)$': '<rootDir>/packages/types/src/$1'
},
modulePathIgnorePatterns: [
'<rootDir>/packages/api/build',
'<rootDir>/packages/api-derive/build',
'<rootDir>/packages/api-contract/build',
'<rootDir>/packages/jsonrpc/build',
'<rootDir>/packages/metadata/build',
'<rootDir>/packages/rpc-core/build',
'<rootDir>/packages/rpc-provider/build',
'<rootDir>/packages/type-jsonrpc/build',
'<rootDir>/packages/types/build'
],
globals: {
+1 -1
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "1.2.1"
"version": "1.6.2"
}
+12 -12
View File
@@ -1,21 +1,19 @@
{
"version": "1.2.1",
"repository": "https://github.com/polkadot-js/api",
"author": "Jaco Greeff <jacogr@gmail.com>",
"license": "Apache-2",
"private": true,
"engines": {
"yarn": "^1.10.1"
},
"workspaces": [
"packages/*"
],
"resolutions": {
"typescript": "^3.7.5"
"typescript": "^3.8.3"
},
"scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts",
"build:interfaces": "node packages/types/src/scripts/interfacesTsWrapper.js",
"circular": "madge --circular --extensions ts ./",
"docs": "node packages/types/src/scripts/MetadataMdWrapper.js && polkadot-dev-build-docs",
"chain:info": "node packages/types/src/scripts/extractChainWrapper.js",
"build": "yarn build:interfaces && polkadot-dev-build-ts && (cd packages/typegen && copyfiles scripts/* build)",
"build:interfaces": "polkadot-types-internal-interfaces",
"docs": "polkadot-types-internal-metadata && polkadot-dev-build-docs",
"chain:info": "polkadot-types-chain-info",
"lint": "polkadot-dev-run-lint",
"clean": "polkadot-dev-clean-build",
"postinstall": "polkadot-dev-yarn-only",
@@ -27,7 +25,9 @@
"@babel/core": "^7.8.4",
"@babel/register": "^7.8.3",
"@babel/runtime": "^7.8.4",
"@polkadot/dev": "^0.40.16",
"@polkadot/ts": "^0.2.3"
"@polkadot/dev": "^0.50.30",
"@polkadot/ts": "^0.3.7",
"@polkadot/typegen": "workspace:packages/typegen",
"copyfiles": "^2.2.0"
}
}
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "1.2.1",
"version": "1.6.2",
"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.8.4",
"@polkadot/api": "^1.2.1",
"@polkadot/rpc-core": "^1.2.1",
"@polkadot/types": "^1.2.1",
"@polkadot/util": "^2.3.1",
"@polkadot/api": "1.6.2",
"@polkadot/rpc-core": "1.6.2",
"@polkadot/types": "1.6.2",
"@polkadot/util": "^2.6.2",
"bn.js": "^5.1.1",
"rxjs": "^6.5.4"
}
@@ -5,7 +5,7 @@
import { CodecArg, Constructor, Registry, TypeDef } from '@polkadot/types/types';
import { ContractABIArgBasePre, ContractABIContract, ContractABIContractPre, ContractABIEvent, ContractABIEventPre, ContractABIFn, ContractABIFnArg, ContractABIMessage, ContractABIMessageBase, ContractABIMessagePre, ContractABI, ContractABIMessageCommon, ContractABIPre, ContractABIRange, ContractABIRangePre, ContractABIStorage, ContractABIStorageLayout, ContractABIStorageLayoutPre, ContractABIStoragePre, ContractABIStorageStruct, ContractABIStorageStructPre, ContractABITypePre } from './types';
import { Compact, u32, createClass, createType, encodeType } from '@polkadot/types';
import { Compact, u32, createClass, encodeType } from '@polkadot/types';
import { assert, hexToU8a, isNumber, isString, isNull, isObject, isUndefined, stringCamelCase, isHex, hexToNumber } from '@polkadot/util';
import MetaRegistry from './MetaRegistry';
@@ -14,16 +14,16 @@ import MetaRegistry from './MetaRegistry';
// just catch everything (since this is now non-standard for u32 anyway)
function parseSelector (registry: Registry, fnname: string, input: ContractABIMessageCommon['selector']): u32 {
if (isNumber(input)) {
return createType(registry, 'u32', input);
return registry.createType('u32', input);
} else if (isHex(input)) {
return createType(registry, 'u32', hexToU8a(input));
return registry.createType('u32', hexToU8a(input));
} else if (typeof input === 'string') {
try {
const array = JSON.parse(input);
assert(array.length === 4, `${fnname}: Invalid selector length`);
return createType(registry, 'u32', Uint8Array.from(
return registry.createType('u32', Uint8Array.from(
// the as number[] is here to pacify TS, it doesn't quite know how to handle the cb
(array as number[]).map((value: string | number): number =>
isHex(value)
+1 -1
View File
@@ -260,7 +260,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
return {
info: TypeDefInfo.VecFixed,
ext: { length: vecLength, type },
length: vecLength, // ex: { type: type }
type: `[${type};${vecLength}]`,
sub: this.typeDefFromMetaTypeAt(vecTypeIndex)
};
+4 -5
View File
@@ -2,16 +2,15 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiTypes, DecorateMethod, SubmittableResultImpl } from '@polkadot/api/types';
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
import { IKeyringPair } from '@polkadot/types/types';
import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import { ApiObject, ContractABIPre } from '../types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { SubmittableResult } from '@polkadot/api';
import { createType } from '@polkadot/types';
import { assert } from '@polkadot/util';
import Abi from '../Abi';
@@ -27,7 +26,7 @@ export interface BlueprintCreate<ApiType extends ApiTypes> {
class BlueprintCreateResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly contract?: Contract<ApiType>;
constructor (result: SubmittableResultImpl, contract?: Contract<ApiType>) {
constructor (result: ISubmittableResult, contract?: Contract<ApiType>) {
super(result);
this.contract = contract;
@@ -41,7 +40,7 @@ export default class Blueprint<ApiType extends ApiTypes> extends BaseWithTx<ApiT
constructor (api: ApiObject<ApiType>, abi: ContractABIPre | Abi, decorateMethod: DecorateMethod<ApiType>, codeHash: string | Hash) {
super(api, abi, decorateMethod);
this.codeHash = createType(this.registry, 'Hash', codeHash);
this.codeHash = this.registry.createType('Hash', codeHash);
}
public deployContract (constructorIndex = 0, endowment: number | BN, maxGas: number | BN, ...params: any[]): BlueprintCreate<ApiType> {
+9 -8
View File
@@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiTypes, DecorateMethod, SubmittableResultImpl } from '@polkadot/api/types';
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
import { IKeyringPair } from '@polkadot/types/types';
import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import { ApiObject, ContractABIPre } from '../types';
import BN from 'bn.js';
@@ -27,7 +27,7 @@ export interface CodePutCode<ApiType extends ApiTypes> {
class CodePutCodeResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly blueprint?: Blueprint<ApiType>;
constructor (result: SubmittableResultImpl, blueprint?: Blueprint<ApiType>) {
constructor (result: ISubmittableResult, blueprint?: Blueprint<ApiType>) {
super(result);
this.blueprint = blueprint;
@@ -47,15 +47,16 @@ export default class Code<ApiType extends ApiTypes> extends BaseWithTx<ApiType>
public createBlueprint = (maxGas: number | BN): CodePutCode<ApiType> => {
return {
signAndSend: this.decorateMethod(
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> => this.apiContracts
.putCode(maxGas, compactAddLength(this.code))
.signAndSend(account)
.pipe(map(this.createResult))
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> =>
this.apiContracts
.putCode(maxGas, compactAddLength(this.code))
.signAndSend(account)
.pipe(map(this.createResult))
)
};
}
private createResult = (result: SubmittableResultImpl): CodePutCodeResult<ApiType> => {
private createResult = (result: ISubmittableResult): CodePutCodeResult<ApiType> => {
let blueprint: Blueprint<ApiType> | undefined;
if (result.isInBlock) {
+11 -17
View File
@@ -11,7 +11,6 @@ import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { SubmittableResult } from '@polkadot/api';
import { createType } from '@polkadot/types';
import Abi from '../Abi';
import { formatData } from '../util';
import { BaseWithTxAndRpcCall } from './util';
@@ -42,27 +41,22 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
return {
send: this.decorateMethod(
as === 'rpc' && this.hasRpcContractsCall
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> => {
return this.rpcContractsCall(
createType(this.registry, 'ContractCallRequest', {
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> =>
this.rpcContractsCall(
this.registry.createType('ContractCallRequest', {
origin: account,
dest: this.address.toString(),
value,
gasLimit,
inputData: fn(...params)
})
)
.pipe(
map((result: ContractExecResult): ContractCallOutcome =>
this.createOutcome(result, createType(this.registry, 'AccountId', account), def, params)
)
);
}
: (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'tx'> => {
return this.apiContracts
).pipe(map((result: ContractExecResult): ContractCallOutcome =>
this.createOutcome(result, this.registry.createType('AccountId', account), def, params)
))
: (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'tx'> =>
this.apiContracts
.call(this.address, value, gasLimit, fn(...params))
.signAndSend(account);
}
.signAndSend(account)
)
};
}
@@ -75,7 +69,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
output = message.returnType
? formatData(this.registry, data, message.returnType)
: createType(this.registry, 'Raw', data);
: this.registry.createType('Raw', data);
}
return {
@@ -92,6 +86,6 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
constructor (api: ApiObject<ApiType>, abi: ContractABIPre | Abi, decorateMethod: DecorateMethod<ApiType>, address: string | AccountId | Address) {
super(api, abi, decorateMethod);
this.address = createType(this.registry, 'Address', address);
this.address = this.registry.createType('Address', address);
}
}
+8 -8
View File
@@ -29,14 +29,13 @@ export abstract class Base<ApiType extends ApiTypes> implements ContractBase<Api
}
public get messages (): ContractMessage[] {
return this.abi.abi.contract.messages
.map(
(def: ContractABIMessage, index): ContractMessage => ({
index,
def,
fn: this.abi.messages[def.name] || this.abi.messages[stringCamelCase(name)]
})
);
return this.abi.abi.contract.messages.map(
(def: ContractABIMessage, index): ContractMessage => ({
index,
def,
fn: this.abi.messages[def.name] || this.abi.messages[stringCamelCase(name)]
})
);
}
public getMessage (nameOrIndex?: string | number): ContractMessage {
@@ -46,6 +45,7 @@ export abstract class Base<ApiType extends ApiTypes> implements ContractBase<Api
: this.abi.abi.contract.messages.findIndex((message): boolean => nameOrIndex === message.name || nameOrIndex === stringCamelCase(message.name))
: 0;
const def = this.abi.abi.contract.messages[index];
assert(!!def, `Attempted to access a contract message that does not exist: ${typeof nameOrIndex === 'number' ? `index ${nameOrIndex}` : nameOrIndex}`);
const fn = this.abi.messages[def.name] || this.abi.messages[stringCamelCase(def.name)];
+1 -1
View File
@@ -5,7 +5,7 @@
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
import { Codec, CodecArg } from '@polkadot/types/types';
import { MetaRegistryJson, StringIndex, TypeIndex, TypeDef } from '@polkadot/types/codec/create/types';
import { MetaRegistryJson, StringIndex, TypeIndex, TypeDef } from '@polkadot/types/create/types';
// import { Observable } from 'rxjs';
import { ApiPromise, ApiRx } from '@polkadot/api';
+1 -2
View File
@@ -4,8 +4,7 @@
import { Codec, Registry, TypeDefInfo, TypeDef } from '@polkadot/types/types';
import { Option, Raw, createClass } from '@polkadot/types';
import { createTypeUnsafe } from '@polkadot/types/codec';
import { Option, Raw, createClass, createTypeUnsafe } from '@polkadot/types';
export function formatData (registry: Registry, data: Raw, { info, type }: TypeDef): Codec {
if (info === TypeDefInfo.Option) {
@@ -18,10 +18,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -71,10 +68,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -116,10 +110,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -153,10 +144,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -183,10 +171,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -223,10 +208,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -256,10 +238,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -295,10 +274,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -340,10 +316,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -381,10 +354,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -402,10 +372,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -439,10 +406,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -460,10 +424,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -506,10 +467,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -527,10 +485,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -566,10 +521,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -587,10 +539,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -628,10 +577,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -677,10 +623,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -708,10 +651,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -725,10 +665,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -757,10 +694,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -802,10 +736,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -839,10 +770,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -869,10 +797,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -909,10 +834,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -942,10 +864,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -969,10 +888,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -998,10 +914,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1047,10 +960,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1082,10 +992,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1119,10 +1026,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1149,10 +1053,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1189,10 +1090,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1230,10 +1128,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1260,10 +1155,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1300,10 +1192,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1331,10 +1220,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1361,10 +1247,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1400,10 +1283,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1445,10 +1325,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1486,10 +1363,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1507,10 +1381,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1544,10 +1415,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1565,10 +1433,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1611,10 +1476,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1632,10 +1494,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1671,10 +1530,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1692,10 +1548,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1725,10 +1578,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1746,10 +1596,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1773,10 +1620,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1814,10 +1658,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1835,10 +1676,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1872,10 +1710,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1893,10 +1728,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1939,10 +1771,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1960,10 +1789,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2007,10 +1833,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2028,10 +1851,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2065,10 +1885,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2086,10 +1903,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2132,10 +1946,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2153,10 +1964,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2190,10 +1998,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2211,10 +2016,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2248,10 +2050,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2269,10 +2068,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2305,10 +2101,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -2328,10 +2121,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -38,10 +38,7 @@
{
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -89,10 +86,7 @@
{
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -130,10 +124,7 @@
{
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -153,10 +144,7 @@
{
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -168,10 +156,7 @@
{
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -181,4 +166,4 @@
"info": 6,
"type": "u8"
}
]
]
@@ -18,10 +18,7 @@
{
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 7,
"type": "u8"
@@ -71,10 +68,7 @@
{
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 7,
"type": "u8"
@@ -120,10 +114,7 @@
{
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 7,
"type": "u8"
@@ -151,10 +142,7 @@
{
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 7,
"type": "u8"
@@ -168,10 +156,7 @@
{
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 7,
"type": "u8"
@@ -185,4 +170,4 @@
"info": 7,
"type": "bool"
}
]
]
@@ -22,10 +22,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -67,10 +64,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -104,10 +98,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -167,10 +158,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -241,10 +229,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -308,10 +293,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -381,10 +363,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -426,10 +405,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -483,10 +459,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -528,10 +501,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -565,10 +535,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -628,10 +595,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -702,10 +666,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -769,10 +730,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -830,10 +788,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -847,10 +802,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -932,10 +884,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -977,10 +926,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1008,10 +954,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1033,10 +976,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1070,10 +1010,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1133,10 +1070,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1207,10 +1141,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1282,10 +1213,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1345,10 +1273,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1419,10 +1344,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1484,10 +1406,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1547,10 +1466,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1620,10 +1536,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1665,10 +1578,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -1714,10 +1624,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -22,10 +22,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -71,10 +68,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -288,10 +282,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -337,10 +328,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -438,10 +426,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -487,10 +472,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -518,10 +500,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -535,10 +514,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -563,10 +539,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
@@ -714,10 +687,7 @@
{
"info": 12,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"length": 32,
"sub": {
"info": 6,
"type": "u8"
+8 -8
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "1.2.1",
"version": "1.6.2",
"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.8.4",
"@polkadot/api": "^1.2.1",
"@polkadot/rpc-core": "^1.2.1",
"@polkadot/rpc-provider": "^1.2.1",
"@polkadot/types": "^1.2.1",
"@polkadot/util": "^2.3.1",
"@polkadot/util-crypto": "^2.3.1",
"@polkadot/api": "1.6.2",
"@polkadot/rpc-core": "1.6.2",
"@polkadot/rpc-provider": "1.6.2",
"@polkadot/types": "1.6.2",
"@polkadot/util": "^2.6.2",
"@polkadot/util-crypto": "^2.6.2",
"bn.js": "^5.1.1",
"memoizee": "^0.4.14",
"rxjs": "^6.5.4"
},
"devDependencies": {
"@polkadot/keyring": "^2.3.1"
"@polkadot/keyring": "^2.6.2"
}
}
@@ -26,17 +26,17 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
const accountId = createType(api.registry, 'AccountId', decoded);
return api.derive.accounts.idToIndex(accountId).pipe(
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex] as AccountIdAndIndex)
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
);
}
const accountIndex = createType(api.registry, 'AccountIndex', decoded);
return api.derive.accounts.indexToId(accountIndex).pipe(
map((accountId): AccountIdAndIndex => [accountId, accountIndex] as AccountIdAndIndex)
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
);
} catch (error) {
return of([undefined, undefined] as AccountIdAndIndex);
return of([undefined, undefined]);
}
}
@@ -6,7 +6,7 @@ import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import { AccountIndexes } from '../types';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { memo } from '../util';
@@ -28,7 +28,6 @@ import { memo } from '../util';
export function idToIndex (api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> =>
api.derive.accounts.indexes().pipe(
startWith({}),
map((indexes: AccountIndexes): AccountIndex | undefined =>
(indexes || {})[accountId.toString()]
)
@@ -8,13 +8,13 @@ import { ITuple } from '@polkadot/types/types';
import { Observable, of } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { ClassOf, Option, Vec, createType } from '@polkadot/types';
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
import { Option, Vec, createType } from '@polkadot/types';
import { memo } from '../util';
function queryEnumSet (api: ApiInterfaceRx, _accountIndex: AccountIndex | string): Observable<AccountId | undefined> {
const accountIndex = _accountIndex instanceof ClassOf(api.registry, 'AccountIndex')
const accountIndex = _accountIndex instanceof api.registry.createClass('AccountIndex')
? _accountIndex
: createType(api.registry, 'AccountIndex', _accountIndex);
+20 -10
View File
@@ -7,8 +7,8 @@ import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import { AccountIndexes } from '../types';
import { Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { map, startWith, switchMap } from 'rxjs/operators';
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
import { Vec, createType } from '@polkadot/types';
import { memo } from '../util';
@@ -25,24 +25,33 @@ function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
api.query.indices.enumSet.multi<Vec<AccountId>>([...Array(next.toNumber() + 1).keys()])
),
map((all: AccountId[][]): AccountIndexes =>
all.reduce((result: AccountIndexes, list, outerIndex): AccountIndexes => {
all.reduce((indexes: AccountIndexes, list, outerIndex): AccountIndexes => {
(list || []).forEach((accountId, innerIndex): void => {
// re-create the index based on position 0 is [0][0] and likewise
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
const index = (outerIndex * enumsetSize) + innerIndex;
result[accountId.toString()] = createType(api.registry, 'AccountIndex', index);
indexes[accountId.toString()] = createType(api.registry, 'AccountIndex', index);
});
return result;
return indexes;
}, {})
)
);
}
// TODO Reverse lookup (via query keys)
function query (): Observable<AccountIndexes> {
return of({} as AccountIndexes);
function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
return api.query.indices.accounts.entries().pipe(
map((entries): AccountIndexes =>
entries.reduce((indexes: AccountIndexes, [key, idOpt]): AccountIndexes => {
if (idOpt.isSome) {
indexes[idOpt.unwrap()[0].toString()] = key.args[0] as AccountIndex;
}
return indexes;
}, {})
)
);
}
/**
@@ -62,10 +71,11 @@ function query (): Observable<AccountIndexes> {
*/
export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
return memo((): Observable<AccountIndexes> =>
api.query.indices
(api.query.indices
? api.query.indices.accounts
? query()
? queryAccounts(api)
: queryEnumSet(api)
: of({} as AccountIndexes)
).pipe(startWith({}))
);
}
+10
View File
@@ -54,6 +54,16 @@ function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [Accou
email: dataAsString(info.email),
image: dataAsString(info.image),
legal: dataAsString(info.legal),
other: info.additional.reduce((other: Record<string, string>, [_key, _value]): Record<string, string> => {
const key = dataAsString(_key);
const value = dataAsString(_value);
if (key && value) {
other[key] = value;
}
return other;
}, {}),
parent: superOf
? superOf[0]
: undefined,
+11 -5
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountData, AccountIndex, Address, Balance, Index } from '@polkadot/types/interfaces';
import { AccountId, AccountData, AccountIndex, AccountInfo, Address, Balance, Index } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DerivedBalancesAccount } from '../types';
@@ -52,10 +52,16 @@ function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId): Obser
}
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Result> {
return api.query.system.account<ITuple<[Index, AccountData]>>(accountId).pipe(
map(([accountNonce, { free, reserved, miscFrozen, feeFrozen }]): Result =>
[free, reserved, feeFrozen, miscFrozen, accountNonce]
)
// AccountInfo is current, support old, eg. Edgeware
return api.query.system.account<AccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
map((infoOrTuple): Result => {
const { free, reserved, miscFrozen, feeFrozen } = (infoOrTuple as AccountInfo).nonce
? (infoOrTuple as AccountInfo).data
: (infoOrTuple as [Index, AccountData])[1];
const accountNonce = (infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0];
return [free, reserved, feeFrozen, miscFrozen, accountNonce];
})
);
}
+5 -2
View File
@@ -20,6 +20,7 @@ type Result = [DerivedBalancesAccount, BlockNumber, ResultBalance];
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DerivedBalancesAll {
let lockedBalance = createType(api.registry, 'Balance');
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
let allLocked = false;
if (Array.isArray(locks)) {
// only get the locks that are valid until passed the current block
@@ -27,6 +28,8 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
const notAll = lockedBreakdown.filter(({ amount }): boolean => !amount.isMax());
allLocked = lockedBreakdown.some(({ amount }): boolean => amount.isMax());
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
if (notAll.length) {
lockedBalance = createType(api.registry, 'Balance', bnMax(...notAll.map(({ amount }): Balance => amount)));
@@ -50,7 +53,7 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
// ""
const floating = freeBalance.sub(lockedBalance);
const extraReceived = isVesting ? freeBalance.sub(vestingTotal) : new BN(0);
const availableBalance = createType(api.registry, 'Balance', bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
const availableBalance = createType(api.registry, 'Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
return {
accountId,
@@ -92,7 +95,7 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
// current (balances vesting)
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<ResultBalance> {
return (
api.query.vesting.vesting
api.query.vesting?.vesting
? api.queryMulti<[Vec<BalanceLock>, Option<VestingInfo>]>([
[api.query.balances.locks, accountId],
[api.query.vesting.vesting, accountId]
+10 -16
View File
@@ -12,21 +12,6 @@ import { createType } from '@polkadot/types';
import { memo } from '../util';
type Result = [Balance, Balance, Balance, Balance, Balance];
function query (api: ApiInterfaceRx): Observable<Result> {
return of([
// deprecated - remove
(api.consts.balances.creationFee as Balance) || createType(api.registry, 'Balance'),
(api.consts.balances.transferFee as Balance) || createType(api.registry, 'Balance'),
// current
api.consts.balances.existentialDeposit,
api.consts.transactionPayment.transactionBaseFee,
api.consts.transactionPayment.transactionByteFee
]);
}
/**
* @name fees
* @returns An object containing the combined results of the storage queries for
@@ -42,7 +27,16 @@ function query (api: ApiInterfaceRx): Observable<Result> {
*/
export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
return memo((): Observable<DerivedFees> =>
query(api).pipe(
of([
// deprecated - remove
(api.consts.balances?.creationFee as Balance) || createType(api.registry, 'Balance'),
(api.consts.balances?.transferFee as Balance) || createType(api.registry, 'Balance'),
// current
(api.consts.balances?.existentialDeposit as Balance) || createType(api.registry, 'Balance'),
(api.consts.transactionPayment?.transactionBaseFee as Balance) || createType(api.registry, 'Balance'),
(api.consts.transactionPayment?.transactionByteFee as Balance) || createType(api.registry, 'Balance')
]).pipe(
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DerivedFees => ({
creationFee,
existentialDeposit,
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber, Header } from '@polkadot/types/interfaces';
import { BlockNumber } from '@polkadot/types/interfaces';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@@ -25,6 +25,6 @@ import { memo } from '../util';
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo((): Observable<BlockNumber> =>
api.derive.chain.subscribeNewHeads().pipe(
map((header: Header): BlockNumber => header.number.unwrap())
map((header) => header.number.unwrap())
));
}
@@ -26,6 +26,6 @@ import { memo } from '../util';
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo((): Observable<BlockNumber> =>
api.rpc.chain.subscribeFinalizedHeads().pipe(
map((header): BlockNumber => header.number.unwrap())
map((header) => header.number.unwrap())
));
}
+1 -4
View File
@@ -2,14 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId } from '@polkadot/types/interfaces';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Observable, combineLatest, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Vec } from '@polkadot/types';
import { HeaderExtended } from '../type';
import { memo } from '../util';
@@ -32,7 +29,7 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
combineLatest([
api.rpc.chain.getHeader(hash),
api.query.session
? api.query.session.validators.at(hash) as Observable<Vec<AccountId>>
? api.query.session.validators.at(hash)
: of([])
]).pipe(
map(([header, validators]): HeaderExtended =>
+16 -14
View File
@@ -12,9 +12,23 @@ import { Option } from '@polkadot/types';
type Result = [Hash[], Option<Proposal>[], Option<Votes>[]];
function parse ([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] {
return proposals
.map((proposalOpt, index): DerivedCollectiveProposal | null =>
proposalOpt.isSome
? {
hash: hashes[index],
proposal: proposalOpt.unwrap(),
votes: votes[index].unwrapOr(null)
}
: null
)
.filter((proposal): proposal is DerivedCollectiveProposal => !!proposal);
}
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposal[]> {
return (): Observable<DerivedCollectiveProposal[]> =>
api.query[section]
api.query[section]?.proposals
? api.query[section].proposals().pipe(
switchMap((hashes: Hash[]): Observable<Result> =>
hashes.length
@@ -25,19 +39,7 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
])
: of([[], [], []])
),
map(([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] =>
proposals
.map((proposalOpt, index): DerivedCollectiveProposal | null =>
proposalOpt.isSome
? {
hash: hashes[index],
proposal: proposalOpt.unwrap(),
votes: votes[index].unwrapOr(null)
}
: null
)
.filter((proposal): boolean => !!proposal) as DerivedCollectiveProposal[]
)
map(parse)
)
: of([] as DerivedCollectiveProposal[]);
}
@@ -63,7 +63,7 @@ function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Resul
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
return memo((): Observable<DeriveProposal[]> =>
api.query.democracy?.publicProps
api.query.democracy?.publicProps && api.query.democracy?.preimages
? api.query.democracy.publicProps<Proposals>().pipe(
switchMap((proposals) =>
combineLatest([
@@ -44,7 +44,7 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<R
export function retrieveInfo (api: ApiInterfaceRx, index: BN | number, info: Option<ReferendumInfo>): Observable<DerivedReferendum | null> {
return ((
info?.isSome
? api.query.democracy.preimages<PreImage>(info.unwrap().proposalHash)
? api.query.democracy.preimages(info.unwrap().proposalHash)
: of(undefined)
) as Observable<PreImage | undefined>).pipe(
map((preimage?: PreImage): DerivedReferendum | null =>
@@ -29,7 +29,7 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
)
),
map((infos): DerivedReferendum[] =>
infos.filter((referendum): boolean => !!referendum) as DerivedReferendum[]
infos.filter((referendum): referendum is DerivedReferendum => !!referendum)
)
));
}
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, SessionIndex } from '@polkadot/types/interfaces';
import { AccountId } from '@polkadot/types/interfaces';
import { DerivedHeartbeats } from '../types';
import { of, Observable, combineLatest } from 'rxjs';
@@ -23,9 +23,9 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
combineLatest([
of(validators),
api.query.imOnline.receivedHeartbeats.multi<Option<Bytes>>(
validators.map((_address, index): [SessionIndex, number] => [currentIndex, index])),
validators.map((_address, index) => [currentIndex, index])),
api.query.imOnline.authoredBlocks.multi<u32>(
validators.map((address): [SessionIndex, AccountId] => [currentIndex, address]))
validators.map((address) => [currentIndex, address]))
])
),
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
+1
View File
@@ -46,6 +46,7 @@ const deriveAvail: Record<string, string[]> = {
democracy: ['democracy'],
elections: ['electionsPhragmen', 'elections'],
imOnline: ['imOnline'],
parachains: ['parachains', 'registrar'],
session: ['session'],
society: ['society'],
staking: ['staking'],
-120
View File
@@ -1,120 +0,0 @@
// 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 { BlockNumber, CollatorId, ParaId, ParaInfo, Retriable, UpwardMessage } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DeriveParachain, DeriveParachainActive } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Bytes, Option, Vec } from '@polkadot/types';
import { memo } from '../util';
type ParaIds = ParaId[];
type ParaInfoResult = Option<ParaInfo>;
type PendingSwap = Option<ParaId>;
type Active = ITuple<[ParaId, Option<ITuple<[CollatorId, Retriable]>>]>[];
type RetryQueue = ITuple<[ParaId, CollatorId]>[][]
type SelectedThreads = ITuple<[ParaId, CollatorId]>[][];
type Heads = Bytes;
type RelayDispatchQueue = Vec<UpwardMessage>
type Watermarks = Option<BlockNumber>;
type DidUpdate = Option<Vec<ParaId>>;
type Result = [
ParaId[],
[
Active,
RetryQueue,
SelectedThreads,
DidUpdate
],
ParaInfoResult[],
PendingSwap[],
Heads[],
RelayDispatchQueue[],
Watermarks[],
];
function parseActive (id: ParaId, active: Active): DeriveParachainActive | null {
const found = active.find(([paraId]): boolean => paraId === id);
if (found && found[1].isSome) {
const [collatorId, retriable] = found[1].unwrap();
return {
collatorId,
...(
retriable.isWithRetries
? {
isRetriable: true,
retries: retriable.asWithRetries.toNumber()
}
: {
isRetriable: false,
retries: 0
}
)
};
}
return null;
}
function parseCollators (id: ParaId, collatorQueue: SelectedThreads | RetryQueue): (CollatorId | null)[] {
return collatorQueue
.map((queue): CollatorId | null => {
const found = queue.find(([paraId]): boolean => paraId === id);
return found ? found[1] : null;
});
}
function parse ([ids, [active, retryQueue, selectedThreads, didUpdate], infos, pendingSwaps, heads, relayDispatchQueues, watermarks]: Result): DeriveParachain[] {
return ids.map((id, index): DeriveParachain => {
return {
active: parseActive(id, active),
didUpdate: didUpdate.isSome
? didUpdate.unwrap().some((paraId): boolean => paraId === id)
: false,
heads: heads[index],
id,
info: infos[index].unwrapOr(null),
pendingSwapId: pendingSwaps[index].unwrapOr(null),
relayDispatchQueue: relayDispatchQueues[index],
retryCollators: parseCollators(id, retryQueue),
selectedCollators: parseCollators(id, selectedThreads),
watermark: watermarks[index].unwrapOr(null)
};
});
}
export function all (api: ApiInterfaceRx): () => Observable<DeriveParachain[]> {
return memo((): Observable<DeriveParachain[]> =>
api.query.registrar?.parachains && api.query.parachains
? api.query.registrar.parachains<ParaIds>().pipe(
switchMap((paraIds) =>
combineLatest([
of(paraIds),
api.queryMulti([
api.query.registrar.active,
api.query.registrar.retryQueue,
api.query.registrar.selectedThreads,
api.query.parachains.didUpdate
]),
api.query.registrar.paras.multi<ParaInfo>(paraIds),
api.query.registrar.pendingSwap.multi<PendingSwap>(paraIds),
api.query.parachains.heads.multi<Heads>(paraIds),
api.query.parachains.relayDispatchQueue.multi<RelayDispatchQueue>(paraIds),
api.query.parachains.watermarks.multi<Watermarks>(paraIds)
]) as Observable<Result>
),
map((result: Result): DeriveParachain[] =>
parse(result)
)
)
: of([] as DeriveParachain[])
);
}

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