Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3a57e14bc | ||
|
|
cc926596e5 | ||
|
|
5193e9c6d5 | ||
|
|
d3703c072b | ||
|
|
4dbcf310f3 | ||
|
|
f778bf32e5 | ||
|
|
7027e9f982 | ||
|
|
d13e58fb32 | ||
|
|
8f8e6d542f | ||
|
|
95c4f03bc3 | ||
|
|
45bba3a897 | ||
|
|
d202287889 | ||
|
|
0c338dfbce | ||
|
|
33c161f874 | ||
|
|
34d951d63e | ||
|
|
27c58b930b | ||
|
|
6d2f2affe8 | ||
|
|
e055438c59 | ||
|
|
19bf1a1b59 | ||
|
|
5577723b73 | ||
|
|
ba5f9d1d01 | ||
|
|
9d548f787f | ||
|
|
98c8240457 | ||
|
|
ff59962c56 | ||
|
|
929a2854bd | ||
|
|
d90c0e82b1 | ||
|
|
73ffb034d0 | ||
|
|
bd41406a34 | ||
|
|
8631f68ba7 | ||
|
|
ad9d4d50f5 | ||
|
|
cb93cb34b7 | ||
|
|
f2fbedb407 | ||
|
|
c27e41be3f | ||
|
|
ae17338520 | ||
|
|
19d6165bda | ||
|
|
9a02e0695b | ||
|
|
5ce3524ccd | ||
|
|
dff7243aad | ||
|
|
ee6b6da02b | ||
|
|
dc936cfed4 | ||
|
|
7af9151854 | ||
|
|
10497ddef2 | ||
|
|
7fd45f63df | ||
|
|
82afd93bf6 | ||
|
|
05c0379f43 | ||
|
|
10c7da75d8 | ||
|
|
0c4cc51f74 | ||
|
|
1ba58e3d04 | ||
|
|
c6bc664f80 | ||
|
|
eb9ab67651 | ||
|
|
7070f757c4 | ||
|
|
0d88095cb2 | ||
|
|
6faea13a28 | ||
|
|
4f59866528 | ||
|
|
41f1d8f367 | ||
|
|
a32a1162ff | ||
|
|
0c99064b19 | ||
|
|
77f37f387a | ||
|
|
9f4007bd4b | ||
|
|
ad20decbbc | ||
|
|
820dd3d0fb | ||
|
|
004f9153ab | ||
|
|
3de336fdff | ||
|
|
67e1e07714 | ||
|
|
b4cae14836 | ||
|
|
9bae65864d | ||
|
|
172143f2eb | ||
|
|
3162f15a1d | ||
|
|
af074500b6 | ||
|
|
5e2a1753af | ||
|
|
375dadbe35 | ||
|
|
f799a63610 | ||
|
|
eda5edbd40 | ||
|
|
d0fefb342f | ||
|
|
b56c1a8282 | ||
|
|
cdd6544e20 | ||
|
|
12068a8722 | ||
|
|
4596e434dd | ||
|
|
6c00a5a408 | ||
|
|
c10e4d3fc1 | ||
|
|
597aa3d607 | ||
|
|
2edad85250 | ||
|
|
5f0c6ecd1b | ||
|
|
2a36987140 | ||
|
|
12ea37d1ec | ||
|
|
3dca518cd7 | ||
|
|
5f7057dbbf | ||
|
|
aac6b3bc7b | ||
|
|
7a5a975048 | ||
|
|
46d05dd7af | ||
|
|
177cdb97fd | ||
|
|
2b0bae12c7 | ||
|
|
24d8915005 | ||
|
|
180bfbbf6f | ||
|
|
918bb73547 | ||
|
|
41ffa2bf00 | ||
|
|
e425a38a7c | ||
|
|
c616cd51c5 | ||
|
|
dac3261a16 | ||
|
|
28355424bd | ||
|
|
e7be062522 | ||
|
|
ed5b5eeaa6 | ||
|
|
ad8ad42344 | ||
|
|
f311e5d57f | ||
|
|
065f39ba6d | ||
|
|
64bf72a6d7 | ||
|
|
b59b60ae1f | ||
|
|
e5b7e7f16f | ||
|
|
c2705bdfda | ||
|
|
373eb06713 | ||
|
|
45c2c40a3e | ||
|
|
3b110d7d7f | ||
|
|
0a8d2e5ac1 | ||
|
|
d0bf8b8d82 | ||
|
|
2c3ef10513 | ||
|
|
92022bda94 | ||
|
|
609581430f | ||
|
|
ec083f623d | ||
|
|
395dc79ef7 | ||
|
|
a968fe05b5 | ||
|
|
4b3b853c27 | ||
|
|
ea5843f7c9 | ||
|
|
467ccc5681 | ||
|
|
59922eee8f | ||
|
|
5af98cc89e | ||
|
|
1b7265048d | ||
|
|
3151c08aca | ||
|
|
71332fde1b | ||
|
|
00bc441f0e | ||
|
|
4f4833da74 | ||
|
|
825365bb13 | ||
|
|
48a3a976f9 | ||
|
|
b579b18fad | ||
|
|
27f5547bbf | ||
|
|
4654d15097 | ||
|
|
10574ecc33 | ||
|
|
6ae75ba92e | ||
|
|
5a48a2a3f7 | ||
|
|
40899adf82 | ||
|
|
020effecc8 | ||
|
|
430beb9f25 | ||
|
|
533d6dd441 | ||
|
|
95dd13e218 | ||
|
|
c8cb441a82 | ||
|
|
b6d1be6ee5 | ||
|
|
e13514cd94 | ||
|
|
5a90da5df8 | ||
|
|
8fdc518651 | ||
|
|
eb6b3c5bd4 | ||
|
|
1214572f02 | ||
|
|
df229ffb8a | ||
|
|
334e0bb730 | ||
|
|
f43bc32573 | ||
|
|
bf4a8e28a3 | ||
|
|
9188e29dcc | ||
|
|
7ea89950fe | ||
|
|
7a1089df79 | ||
|
|
f1ca28adcb | ||
|
|
8f675053a4 | ||
|
|
64de91a96b | ||
|
|
6bd10daf43 | ||
|
|
57c54c860a | ||
|
|
0e9a50e020 | ||
|
|
15c35900ac | ||
|
|
6f092a1818 | ||
|
|
c0c6928394 | ||
|
|
391c98c845 | ||
|
|
2e125c5542 | ||
|
|
3d67b75059 | ||
|
|
d958ef8f15 | ||
|
|
97527871d6 | ||
|
|
0317f28e5a | ||
|
|
ebe6d03762 | ||
|
|
59e92fa344 | ||
|
|
cab338e26d | ||
|
|
743ea431b4 | ||
|
|
533f9ce249 | ||
|
|
797ee9c24a | ||
|
|
2f5e2537a3 | ||
|
|
dd52ea4b32 | ||
|
|
5e8ae793c3 | ||
|
|
8713a1f2b6 | ||
|
|
6e6fa4a97c | ||
|
|
ac2a0a34ca | ||
|
|
45fb6d44ad | ||
|
|
6d2265d4ff | ||
|
|
4ec42f1750 | ||
|
|
01166b9684 | ||
|
|
0075dce720 | ||
|
|
7fbb30066e | ||
|
|
637069d723 | ||
|
|
d639a7ee8c | ||
|
|
28ef291c40 | ||
|
|
48ddd0b0d4 | ||
|
|
e88ebf7b2e | ||
|
|
72700e6baf | ||
|
|
f748fcd46d | ||
|
|
7876bb9ced | ||
|
|
a83980b213 | ||
|
|
c4323d5e94 | ||
|
|
11694f1393 | ||
|
|
3989ae67b2 | ||
|
|
b78df57907 | ||
|
|
2f78329738 | ||
|
|
6063054712 | ||
|
|
e42af97928 | ||
|
|
d05ccdb5d7 | ||
|
|
c33334b72b | ||
|
|
94e9fd2b17 | ||
|
|
9c1327ea22 | ||
|
|
9f195e9402 | ||
|
|
3e5e089c68 | ||
|
|
35c37aa66c | ||
|
|
f1aeb564e3 | ||
|
|
c2ff1b32ae | ||
|
|
288427cbb8 | ||
|
|
d099ccedad | ||
|
|
79c7983199 | ||
|
|
80c578fe76 | ||
|
|
de90c048bf | ||
|
|
01a36a994d | ||
|
|
b1ce22d51d | ||
|
|
fe951c2645 | ||
|
|
5a17c542a7 | ||
|
|
59bb5f864f | ||
|
|
abcba20f90 | ||
|
|
014f08c7cc | ||
|
|
7ecd00a4e6 | ||
|
|
6239818c26 | ||
|
|
6af22f41c7 | ||
|
|
77c3a701d0 | ||
|
|
46b17a466c | ||
|
|
e592c6c878 | ||
|
|
ef37586dfc | ||
|
|
5856ce24cc | ||
|
|
8b79056bf9 | ||
|
|
70e0f19ade | ||
|
|
cf1e242c17 | ||
|
|
68856e9692 | ||
|
|
e0626c3dad | ||
|
|
277ea92fda | ||
|
|
aec6694028 | ||
|
|
533abb76f7 | ||
|
|
7660bab86b | ||
|
|
f7c1b6e81b | ||
|
|
b6e9b29570 | ||
|
|
519d9c8fa9 | ||
|
|
ad905db53b | ||
|
|
0a0aa742b4 | ||
|
|
dfbb06a4d6 | ||
|
|
82e71fd51e | ||
|
|
a8b88af97a | ||
|
|
eee36537de | ||
|
|
20a75eafb6 | ||
|
|
00d3a1174b | ||
|
|
e293c7c1cf | ||
|
|
3c8cd499c4 | ||
|
|
cb3816df78 | ||
|
|
fcfcbb2d97 | ||
|
|
321b80ed63 | ||
|
|
73eaa9fe17 | ||
|
|
4d8910f3da | ||
|
|
e6806ed7f9 | ||
|
|
218abf9568 | ||
|
|
a1df864681 | ||
|
|
45640edcff | ||
|
|
53655019b5 | ||
|
|
a1f8bedb6d | ||
|
|
9d1af1eaeb | ||
|
|
38bfd26511 | ||
|
|
1beaf9f208 | ||
|
|
29c29978dd | ||
|
|
a8d1dd0637 | ||
|
|
74571dcd26 | ||
|
|
54b4c2620a | ||
|
|
da05828e74 | ||
|
|
fa935156e1 | ||
|
|
19510c1ede | ||
|
|
97b5c699b1 | ||
|
|
d2befda86e | ||
|
|
740348b48f | ||
|
|
9e2a5cf532 | ||
|
|
6df466d9ea | ||
|
|
e2a2ac2842 | ||
|
|
5adc846e45 | ||
|
|
75aa310837 | ||
|
|
ce0523eb1c | ||
|
|
eb0370bb66 | ||
|
|
5eb491dc67 | ||
|
|
b50294ab0f | ||
|
|
e1cb62d2d2 | ||
|
|
8ed0ef2295 | ||
|
|
956e173323 | ||
|
|
b8a37ba438 | ||
|
|
e7669c2b00 | ||
|
|
6c309a503d | ||
|
|
3cf67c975a | ||
|
|
077914364c | ||
|
|
56e4cbdb27 | ||
|
|
60bfdae734 | ||
|
|
1cf4d6b9b8 | ||
|
|
40cd9ff51f | ||
|
|
c7e6e40030 | ||
|
|
97d0bcbfd4 | ||
|
|
6ca84425d1 | ||
|
|
8481647d2c | ||
|
|
658dda66a4 | ||
|
|
87f18efe72 | ||
|
|
bcdfcce89c | ||
|
|
9418f1de56 | ||
|
|
37c8b8e592 | ||
|
|
4f8db79a40 | ||
|
|
54cf086a89 | ||
|
|
37ddcaa32d | ||
|
|
6a2baf8352 | ||
|
|
ecca91dffd | ||
|
|
42576d74ac | ||
|
|
26a6f20dbf | ||
|
|
c3ee8393b2 | ||
|
|
b6f0b9f262 | ||
|
|
991dc48020 | ||
|
|
e4a82f9a1d | ||
|
|
c8b6012553 | ||
|
|
d0fe862605 | ||
|
|
61a0198695 | ||
|
|
345a97dc9f | ||
|
|
f821ab8ecd | ||
|
|
f9e2bf332d | ||
|
|
ad69430980 | ||
|
|
d25743016c | ||
|
|
ee0a46adc4 | ||
|
|
f516abfc3f | ||
|
|
1a96ca5c0e | ||
|
|
8c73cd7d6e | ||
|
|
36232c0289 | ||
|
|
50d4e0397f | ||
|
|
539a8c4cb5 | ||
|
|
b849976b3b | ||
|
|
2395401a2b | ||
|
|
0e1bbd5cac | ||
|
|
e9489d41cb | ||
|
|
63483b9db7 | ||
|
|
b26c7f9f0a | ||
|
|
a165c9375c | ||
|
|
28631f7180 | ||
|
|
6489251b47 | ||
|
|
66884febea | ||
|
|
8058dc350f | ||
|
|
63096cc238 | ||
|
|
05600c0cd0 | ||
|
|
eed5e23e65 | ||
|
|
cdf5b15673 | ||
|
|
1922676bd7 | ||
|
|
b6c427e985 | ||
|
|
0327aedf8e | ||
|
|
d7035cebb1 | ||
|
|
8b492021af | ||
|
|
6a01fc7c8c | ||
|
|
bbc30ec9dc | ||
|
|
f07c0628bc | ||
|
|
023c7588e5 | ||
|
|
7dfc8625cc | ||
|
|
8643b5da87 | ||
|
|
afa0e63ae8 | ||
|
|
534303ff45 | ||
|
|
f1ebcddec6 | ||
|
|
657a2006dd | ||
|
|
219e928c01 | ||
|
|
43183118d5 | ||
|
|
76e15d465d | ||
|
|
4c0387e1a3 | ||
|
|
bbbd82eb4a | ||
|
|
a34a7450aa | ||
|
|
bf472fdcf4 | ||
|
|
f428a58006 | ||
|
|
fcce2ab340 | ||
|
|
877eb11717 | ||
|
|
4b55f1be93 | ||
|
|
f2a677634e | ||
|
|
eea4c8775e | ||
|
|
792bf0ec36 | ||
|
|
e3d13107a9 | ||
|
|
e5c2c6a228 | ||
|
|
d2be79132c | ||
|
|
76da2638c1 | ||
|
|
daf3912920 | ||
|
|
6dfebbb9fe | ||
|
|
e55c5f77f7 | ||
|
|
c7315ffb74 | ||
|
|
84eb806f07 | ||
|
|
2493442a2e | ||
|
|
77df7907c7 | ||
|
|
f1b6268784 | ||
|
|
9aa9380251 | ||
|
|
b4306cb60a | ||
|
|
1e83daf797 | ||
|
|
d46d32d9bc | ||
|
|
032a0a595c | ||
|
|
34101ec12b | ||
|
|
4e02b982d3 | ||
|
|
5b96d52fa6 | ||
|
|
735f2b835e | ||
|
|
646e64c286 | ||
|
|
fc9060caa8 | ||
|
|
503c2b3c63 | ||
|
|
168abc130f | ||
|
|
5c5db2709b | ||
|
|
5a4ff5420f | ||
|
|
a1655508ba | ||
|
|
64827a6114 | ||
|
|
2eb09374bc | ||
|
|
ddf67d5564 | ||
|
|
ad6b8280a2 | ||
|
|
682c6b6fb2 | ||
|
|
6a281211b4 | ||
|
|
6ef94b3c3b | ||
|
|
e900d1d657 | ||
|
|
7f1a3fa636 | ||
|
|
21802664b8 | ||
|
|
1492df11a7 | ||
|
|
00fed90da2 | ||
|
|
e6beb6554d | ||
|
|
099cf5a351 | ||
|
|
55e762a348 | ||
|
|
0ad146c607 | ||
|
|
4e7f3f5268 | ||
|
|
6a9e3d80f1 | ||
|
|
dee98fae55 | ||
|
|
ff52876920 | ||
|
|
4d01a09c54 | ||
|
|
7310ea825e | ||
|
|
15b80a47c3 | ||
|
|
622682b4ef | ||
|
|
56415df4ab | ||
|
|
8bea5e5a3b | ||
|
|
d6372ade44 | ||
|
|
f501994df8 | ||
|
|
b787a7d5a0 | ||
|
|
11d162a10d | ||
|
|
e2564dea17 | ||
|
|
2b9152871e | ||
|
|
70ecb03d14 | ||
|
|
a2f179acb1 | ||
|
|
c8cb97edef | ||
|
|
69d344c6c3 | ||
|
|
44cdf49b2c | ||
|
|
daaf4654a1 | ||
|
|
f8d4fcaf04 | ||
|
|
eb19a39d82 | ||
|
|
7ed958fb2d | ||
|
|
bbe9b94f26 | ||
|
|
6e83e6aaef | ||
|
|
1545bbf7c5 | ||
|
|
5bfc2cd534 | ||
|
|
b22d0a196f | ||
|
|
b174864804 | ||
|
|
e6834d60c5 | ||
|
|
97438bb2e8 | ||
|
|
f630d43a25 | ||
|
|
0187f1ff19 | ||
|
|
d8db866316 | ||
|
|
28aa9e18a7 | ||
|
|
3eaea97b8f | ||
|
|
ea0e5e4547 | ||
|
|
1256317b65 | ||
|
|
e0c3ed1b96 | ||
|
|
9f2c3016d7 | ||
|
|
938ace2342 | ||
|
|
e5d2607dff | ||
|
|
50b8db2263 | ||
|
|
91766a6885 | ||
|
|
4b1a9ab9e1 | ||
|
|
9a14c65336 | ||
|
|
4aa66fd4c6 | ||
|
|
3d9c62d538 | ||
|
|
4156eb44ab | ||
|
|
4b2d33693c | ||
|
|
e8b127e177 | ||
|
|
b052b03f31 | ||
|
|
6727e12468 | ||
|
|
c130285651 | ||
|
|
47fc4a2b3c | ||
|
|
97cb408f36 | ||
|
|
dde7c8085a | ||
|
|
8b02fafb99 | ||
|
|
393f46ba4a | ||
|
|
455f5ad834 | ||
|
|
674324e7f9 | ||
|
|
b0dc7cf451 | ||
|
|
cbe1b2b1ce | ||
|
|
4bd2f2fc32 | ||
|
|
053112470d | ||
|
|
acdf27a272 | ||
|
|
f70b32ba76 | ||
|
|
67a3376ef8 | ||
|
|
eb06bb6e93 | ||
|
|
f8f7e92da4 | ||
|
|
d0fd3eca25 | ||
|
|
dac1df35de | ||
|
|
597563d2bb | ||
|
|
f825c7f187 | ||
|
|
2e71a6160e | ||
|
|
c076c37119 | ||
|
|
0e18fdbccc | ||
|
|
c3eebd8fbe | ||
|
|
45786b31da |
+4
-2
@@ -1,5 +1,7 @@
|
|||||||
24
|
25
|
||||||
1.4.2
|
1.4.2
|
||||||
1.6.2
|
1.6.2
|
||||||
1.11.2
|
1.11.2
|
||||||
1.12.2
|
1.12.2
|
||||||
|
1.17.2
|
||||||
|
1.31.2
|
||||||
@@ -1 +1,4 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
module.exports = require('./babel.config.js');
|
module.exports = require('./babel.config.js');
|
||||||
|
|||||||
+6
-1
@@ -1,3 +1,6 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
const base = require('@polkadot/dev/config/eslint');
|
const base = require('@polkadot/dev/config/eslint');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@@ -13,6 +16,8 @@ module.exports = {
|
|||||||
// add override for any (a metric ton of them, initial conversion)
|
// add override for any (a metric ton of them, initial conversion)
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
'@typescript-eslint/no-explicit-any': 'off',
|
||||||
// these should be removed, there are 8 of them as errors
|
// these should be removed, there are 8 of them as errors
|
||||||
'@typescript-eslint/no-non-null-assertion': 'off'
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||||
|
// this seems very broken atm, false positives
|
||||||
|
'@typescript-eslint/unbound-method': 'off'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
step: ['build:release', 'docs:release']
|
step: ['build:release', 'docs:release']
|
||||||
name: ${{ matrix.step }}
|
name: ${{ matrix.step }}
|
||||||
if: "! contains(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/api'"
|
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/api'"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
@@ -21,16 +21,13 @@ jobs:
|
|||||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
GH_PAGES_SRC: build-docs
|
GH_PAGES_SRC: build-docs
|
||||||
GH_PAT: ${{ secrets.GH_PAT }}
|
GH_PAT: ${{ secrets.GH_PAT }}
|
||||||
GH_TOKEN: ${{ secrets.GH_PAT }}
|
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
yarn install --immutable | grep -v 'YN0013'
|
yarn install --immutable | grep -v 'YN0013'
|
||||||
yarn ${{ matrix.step }}
|
yarn ${{ matrix.step }}
|
||||||
|
|
||||||
dummy:
|
dummy:
|
||||||
name: Dummy
|
|
||||||
if: "contains(github.event.head_commit.message, '[CI Skip]')"
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: dummy
|
- name: dummy
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+52
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+55
File diff suppressed because one or more lines are too long
Vendored
-56
File diff suppressed because one or more lines are too long
+6
-2
@@ -5,7 +5,11 @@ enableProgressBars: false
|
|||||||
nodeLinker: node-modules
|
nodeLinker: node-modules
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||||
spec: "@yarnpkg/plugin-interactive-tools"
|
spec: "@yarnpkg/plugin-interactive-tools"
|
||||||
|
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
|
||||||
|
spec: "@yarnpkg/plugin-version"
|
||||||
|
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
|
||||||
|
spec: "@yarnpkg/plugin-workspace-tools"
|
||||||
|
|
||||||
yarnPath: .yarn/releases/yarn-rc.js
|
yarnPath: .yarn/releases/yarn-2.2.2.cjs
|
||||||
|
|||||||
+680
-83
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
# @polkadot/api
|
# @polkadot/api
|
||||||
|
|
||||||
This library provides a clean wrapper around all the methods exposed by a Polkadot/Subtrate network client and defines all the types exposed by a node. For complete documentation around the classes, interfaces and their use, visit the [documentation portal](https://polkadot.js.org/api/).
|
This library provides a clean wrapper around all the methods exposed by a Polkadot/Substrate network client and defines all the types exposed by a node. For complete documentation around the classes, interfaces and their use, visit the [documentation portal](https://polkadot.js.org/api/).
|
||||||
|
|
||||||
If you are an existing user, please be sure to track the [CHANGELOG](CHANGELOG.md) and [UPGRADING](UPGRADING.md) guides when changing versions.
|
If you are an existing user, please be sure to track the [CHANGELOG](CHANGELOG.md) and [UPGRADING](UPGRADING.md) guides when changing versions.
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@ The API is split up into a number of internal packages -
|
|||||||
|
|
||||||
Type definitions for interfaces as exposed by Polkadot & Substrate clients -
|
Type definitions for interfaces as exposed by Polkadot & Substrate clients -
|
||||||
|
|
||||||
- [@polkadot/jsonrpc](packages/jsonrpc/) Definitions for JSONRPC endpoints
|
|
||||||
- [@polkadot/types](packages/types/) Codecs for all Polkadot and Substrate primitives
|
- [@polkadot/types](packages/types/) Codecs for all Polkadot and Substrate primitives
|
||||||
|
|
||||||
## development
|
## development
|
||||||
|
|||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
module.exports = require('@polkadot/dev/config/babel');
|
module.exports = require('@polkadot/dev/config/babel');
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
function copy_folder () {
|
function copy_folder () {
|
||||||
SRC="packages/$1/build"
|
SRC="packages/$1/build"
|
||||||
|
|||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
function copy_folder () {
|
||||||
|
SRC="packages/$1/build"
|
||||||
|
DST="../test/js-test/node_modules/@polkadot/$1"
|
||||||
|
|
||||||
|
echo "** Copying $SRC to $DST"
|
||||||
|
|
||||||
|
rm -rf $DST
|
||||||
|
cp -r $SRC $DST
|
||||||
|
}
|
||||||
|
|
||||||
|
yarn polkadot-dev-build-ts
|
||||||
|
|
||||||
|
copy_folder "api"
|
||||||
|
copy_folder "api-contract"
|
||||||
|
copy_folder "api-derive"
|
||||||
|
copy_folder "metadata"
|
||||||
|
copy_folder "rpc-core"
|
||||||
|
copy_folder "rpc-provider"
|
||||||
|
copy_folder "types"
|
||||||
|
copy_folder "types-known"
|
||||||
|
copy_folder "typegen"
|
||||||
+29
-1
@@ -25,7 +25,7 @@ signedBlock.block.extrinsics.forEach((ex, index) => {
|
|||||||
|
|
||||||
## How do I extract the block author?
|
## How do I extract the block author?
|
||||||
|
|
||||||
Th block author is encoded inside the consensus logs for the block. To extract, you need to decode the log (which the API does do) and then map the index of the validator to the list of session validators. This extraction is however available on the api derive for new head subscriptions, which returns an extended header with the author populated (assuming that the digest logs are known).
|
The block author is encoded inside the consensus logs for the block. To extract, you need to decode the log (which the API does do) and then map the index of the validator to the list of session validators. This extraction is however available on the api derive for new head subscriptions, which returns an extended header with the author populated (assuming that the digest logs are known).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// subscribe to all new headers (with extended info)
|
// subscribe to all new headers (with extended info)
|
||||||
@@ -42,3 +42,31 @@ const header = await api.derive.chain.getHeader();
|
|||||||
|
|
||||||
console.log(`#${header.number}: ${header.author}`);
|
console.log(`#${header.number}: ${header.author}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## How do I view block extrinsic information?
|
||||||
|
|
||||||
|
The transactions are included in a signed block as part of the extrinsics - some of these will be unsigned and generated by the block author and some of these may be submitted from external sources and be signed. (Some palettes do use unsigned transactions, so signed/unsigned is not an indication of origin). To retrieve the block and display the transaction information, we can do the following -
|
||||||
|
|
||||||
|
```js
|
||||||
|
// no blockHash is specified, so we retrieve the latest
|
||||||
|
const signedBlock = await this.api.rpc.chain.getBlock();
|
||||||
|
|
||||||
|
// the information for each of the contained extrinsics
|
||||||
|
signedBlock.block.extrinsics.forEach((ex, index) => {
|
||||||
|
// the extrinsics are decoded by the API, human-like view
|
||||||
|
console.log(index, ex.toHuman());
|
||||||
|
|
||||||
|
const { isSigned, meta, method: { args, method, section } } = ex;
|
||||||
|
|
||||||
|
// explicit display of name, args & documentation
|
||||||
|
console.log(`${section}.${method}(${args.map((a) => a.toString()).join(', ')})`);
|
||||||
|
console.log(meta.documentation.map((d) => d.toString()).join('\n'));
|
||||||
|
|
||||||
|
// signer/nonce info
|
||||||
|
if (isSigned) {
|
||||||
|
console.log(`signer=${ex.signer.toString()}, nonce=${ex.nonce.toString()}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
In the above `.toHuman()` is used to format into a human-readable representation. You can inspect/extract specific fields from the decoded extrinsic as required, for instance `ex.method.section` would return the pallete that executed this transaction.
|
||||||
|
|||||||
+6
-6
@@ -16,9 +16,9 @@ const info = await api.tx.balances
|
|||||||
|
|
||||||
// log relevant info, partialFee is Balance, estimated for current
|
// log relevant info, partialFee is Balance, estimated for current
|
||||||
console.log(`
|
console.log(`
|
||||||
class=${class.toString()},
|
class=${info.class.toString()},
|
||||||
weight=${weight.toString()},
|
weight=${info.weight.toString()},
|
||||||
partialFee=${partialFee.toHuman()}
|
partialFee=${info.partialFee.toHuman()}
|
||||||
`);
|
`);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -97,12 +97,12 @@ api.tx.utility
|
|||||||
|
|
||||||
## How do I take the pending tx pool into account in my nonce?
|
## How do I take the pending tx pool into account in my nonce?
|
||||||
|
|
||||||
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signandSend` operation, we can override the nonce, either by manually incrementing it o querying it via `nextNonce`.
|
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signAndSend` operation, we can override the nonce, either by manually incrementing it or querying it via `rpc.system.accountNextIndex`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
// retrieve the nextNonce, taking txs in the pool into account
|
// retrieve sender's next index/nonce, taking txs in the pool into account
|
||||||
const nonce = await api.rpc.account.nextNonce(sender);
|
const nonce = await api.rpc.system.accountNextIndex(sender);
|
||||||
|
|
||||||
// send, just retrieving the hash, not waiting on status
|
// send, just retrieving the hash, not waiting on status
|
||||||
const txhash = await api.tx.balances
|
const txhash = await api.tx.balances
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable header/header */
|
/* eslint-disable header/header */
|
||||||
/* eslint-disable @typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/require-await */
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
|
||||||
// Import the API
|
// Import the API
|
||||||
const { ApiPromise } = require('@polkadot/api');
|
const { ApiPromise } = require('@polkadot/api');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable header/header */
|
/* eslint-disable header/header */
|
||||||
/* eslint-disable @typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/require-await */
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
|
||||||
// Import the API
|
// Import the API
|
||||||
const { ApiPromise } = require('@polkadot/api');
|
const { ApiPromise } = require('@polkadot/api');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable header/header */
|
/* eslint-disable header/header */
|
||||||
/* eslint-disable @typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/require-await */
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
|
||||||
// Import the API
|
// Import the API
|
||||||
const { ApiPromise } = require('@polkadot/api');
|
const { ApiPromise } = require('@polkadot/api');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable header/header */
|
/* eslint-disable header/header */
|
||||||
/* eslint-disable @typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/require-await */
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
|
||||||
// Import the API & Provider and some utility functions
|
// Import the API & Provider and some utility functions
|
||||||
const { ApiPromise } = require('@polkadot/api');
|
const { ApiPromise } = require('@polkadot/api');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable header/header */
|
/* eslint-disable header/header */
|
||||||
/* eslint-disable @typescript-eslint/require-await */
|
/* eslint-disable @typescript-eslint/require-await */
|
||||||
/* eslint-disable @typescript-eslint/unbound-method */
|
/* eslint-disable @typescript-eslint/unbound-method */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
|
||||||
// Import the API & Provider and some utility functions
|
// Import the API & Provider and some utility functions
|
||||||
const { ApiPromise, WsProvider } = require('@polkadot/api');
|
const { ApiPromise, WsProvider } = require('@polkadot/api');
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ Looking at the example in this repo, it also has `augment*`, `index.ts` and `typ
|
|||||||
|
|
||||||
## Generating
|
## 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 -
|
Now that both the metadata and 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 build
|
||||||
@@ -166,7 +166,7 @@ As mentioned earlier, here you will notice the `import { VoteStage }`, the gener
|
|||||||
|
|
||||||
## TypeScript config
|
## 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) -
|
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 the actual config file here) -
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-13
@@ -20,6 +20,8 @@ All data transferred between the API and the Node is in a SCALE-encoded binary f
|
|||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
|
If you are using a node-template based version of substrate and you changed the specName you need to add these typings(In addition to other custom types) `{"Address": "AccountId","LookupSource": "AccountId"}`. This is also the case when you use [polkadot-js/apps](https://github.com/polkadot-js/apps) to connect to your node. When the specName stays node-template the API is smart enough to add the custom typings.
|
||||||
|
|
||||||
## I would like to sign transactions offline
|
## 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).
|
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).
|
||||||
@@ -63,16 +65,3 @@ Due to these customizations and differences that bleed through to the transactio
|
|||||||
Recently Substrate master updated the `Weight` type from `u32` -> `u64`. This type is used in the `DispatchInfo` struct in the `system.ExtrinsicSuccess` events, to return the applied call weights as well as the resulting fees. Since the API master branch tracks Substrate master, this means the change has been applied by default, with the default set to `u64`.
|
Recently Substrate master updated the `Weight` type from `u32` -> `u64`. This type is used in the `DispatchInfo` struct in the `system.ExtrinsicSuccess` events, to return the applied call weights as well as the resulting fees. Since the API master branch tracks Substrate master, this means the change has been applied by default, with the default set to `u64`.
|
||||||
|
|
||||||
If you are on a chain that has not been upgraded yet, you need to add `Weight: 'u32'` to your types to allow for successful parsing of all events. Without this override, parsing will fail. As soon as one event in the `Vec<EventRecord>` structure from `system.events` fails to parse, all subsequent events are affected and the decoding will return an error.
|
If you are on a chain that has not been upgraded yet, you need to add `Weight: 'u32'` to your types to allow for successful parsing of all events. Without this override, parsing will fail. As soon as one event in the `Vec<EventRecord>` structure from `system.events` fails to parse, all subsequent events are affected and the decoding will return an error.
|
||||||
|
|
||||||
## When querying older blocks & events, it fails on parsing
|
|
||||||
|
|
||||||
Upon initialization, the API is decorated with the [current on-chain metadata](basics.md#metadata) and (if [available](https://github.com/polkadot-js/api/tree/master/packages/types-known/src)) the specific types for the runtime version is added. This allows the API to decode all current (as per the on-chain info) state and extrinsics.
|
|
||||||
|
|
||||||
When the chain is upgraded, new metadata (indicating new events, storage and extrinsics) is added on-chain. Additionally this generally goes hand in-hand with changes in types, i.e. fields may be addedd or removed or state that was used could now be migrated to new locations. In most cases, this would mean that the current chain information cannot be used to parse older entries pre-upgrade. A typical consequence of this is that any `.at(...)` or `.range(...)` queries pre-upgrade may fail.
|
|
||||||
|
|
||||||
As of the current time, there is no automatic injection of older metadata (based on the runtime version at a specific block) nor decoration of older types if they are available. It can be emulated with what the API will do to handle these cases when it adds a `.historic(...)` query type -
|
|
||||||
|
|
||||||
- querying the runtime version at the parent of older block you wish to retrieve
|
|
||||||
- retrieving and injecting the metadata from the parent block (if the runtime version has changed)
|
|
||||||
- inject any specific older types for the state at that point
|
|
||||||
- finally retrieve the actual entry via an `.at(...)` query
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
|
|||||||
|
|
||||||
...
|
...
|
||||||
// Construct
|
// Construct
|
||||||
const wsProvider = new WsProvider('wss://poc-3.polkadot.io');
|
const wsProvider = new WsProvider('wss://rpc.polkadot.io');
|
||||||
const api = await ApiPromise.create({ provider: wsProvider });
|
const api = await ApiPromise.create({ provider: wsProvider });
|
||||||
|
|
||||||
// Do something
|
// Do something
|
||||||
@@ -49,7 +49,7 @@ The API creation is done via the `ApiPromise.create` interface which is a shortc
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
ApiPromise
|
ApiPromise
|
||||||
.create({ provider: wsProvider })
|
.create({ provider: wsProvider }).isReady
|
||||||
.then((api) =>
|
.then((api) =>
|
||||||
console.log(api.genesisHash.toHex())
|
console.log(api.genesisHash.toHex())
|
||||||
);
|
);
|
||||||
@@ -70,7 +70,7 @@ console.log(api.genesisHash.toHex());
|
|||||||
|
|
||||||
## Failures
|
## 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 all cases the API will handle reconnecting 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.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Be aware that while defined, the method will only appear on the API if it is in
|
|||||||
|
|
||||||
## Definition breakdown
|
## Definition breakdown
|
||||||
|
|
||||||
While the above example should be self-explanatory, it is important to understand teh structure. The `rpc: { ... }` definitions are keyed first and foremost by the name of the module exposing the RPC. This means that when we have 2 modules `firstModule` & `testModule`, the first-level structure would follow the following pattern,
|
While the above example should be self-explanatory, it is important to understand the structure. The `rpc: { ... }` definitions are keyed first and foremost by the name of the module exposing the RPC. This means that when we have 2 modules `firstModule` & `testModule`, the first-level structure would follow the following pattern,
|
||||||
|
|
||||||
```js
|
```js
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ As a minimum, anything returned by the API, be it a `Vec<...>`, `Option<...>`, `
|
|||||||
|
|
||||||
- `.eq(<other value>)` - checks for equality against the other value. In all cases, it will accept "like" values, i.e. in the case of a number you can pass a primitive (such as `1`), a hex value (such as `0x01`) or even an `Unit8Array`
|
- `.eq(<other value>)` - checks for equality against the other value. In all cases, it will accept "like" values, i.e. in the case of a number you can pass a primitive (such as `1`), a hex value (such as `0x01`) or even an `Unit8Array`
|
||||||
- `toHex()` - returns a hex-base representation of the value, always prefixed by `0x`
|
- `toHex()` - returns a hex-base representation of the value, always prefixed by `0x`
|
||||||
|
- `toHuman()` - returns Human-parsable JSON structure with values formatted as per the settings
|
||||||
- `toJSON()` - returns a JSON-like representation of the value, this is generally used when calling `JSON.stringify(...)` on the value
|
- `toJSON()` - returns a JSON-like representation of the value, this is generally used when calling `JSON.stringify(...)` on the value
|
||||||
- `toString()` - returns a string representation, in some cases this performs additional encoding, i.e. for `Address`, `AccountId` and `AccountIndex` it will encode to the ss58 address
|
- `toString()` - returns a string representation, in some cases this performs additional encoding, i.e. for `Address`, `AccountId` and `AccountIndex` it will encode to the ss58 address
|
||||||
- `.toU8a()` - returns a `Uint8Array` representation of the encoded value (generally exactly as passed to the node, where values are SCALE encoded)
|
- `.toU8a()` - returns a `Uint8Array` representation of the encoded value (generally exactly as passed to the node, where values are SCALE encoded)
|
||||||
@@ -41,6 +42,7 @@ const system = modules.find(m => m.name.eq('system'));
|
|||||||
All numbers wrap and extend an instance of [bn.js](https://github.com/indutny/bn.js/). This means that in addition to the interfaces defined above, they have some additional methods -
|
All numbers wrap and extend an instance of [bn.js](https://github.com/indutny/bn.js/). This means that in addition to the interfaces defined above, they have some additional methods -
|
||||||
|
|
||||||
- `.toNumber()` - a JS number (limited to 2^53 - 1). This does mean that for large values, e.g. `Balance` (a `u128` extension), this can cause overflows
|
- `.toNumber()` - a JS number (limited to 2^53 - 1). This does mean that for large values, e.g. `Balance` (a `u128` extension), this can cause overflows
|
||||||
|
- `.toBigInt()` - a JS `BigInt` object (on supported platforms)
|
||||||
- `.add(...)`, `.sub(...)`, ... - all the base methods available on the `BN` object
|
- `.add(...)`, `.sub(...)`, ... - all the base methods available on the `BN` object
|
||||||
|
|
||||||
In cases where a `Compact` is returned, i.e. `Compact<Balance>`, the value is wrapped. This object should be `.unwrap()`-ed first to gain access to the underlying `Balance` object.
|
In cases where a `Compact` is returned, i.e. `Compact<Balance>`, the value is wrapped. This object should be `.unwrap()`-ed first to gain access to the underlying `Balance` object.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ With the conversions done in the API, there are limited reasons to create types
|
|||||||
import type { Balance } from '@polkadot/types/interfaces';
|
import type { Balance } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
...
|
...
|
||||||
// unwrap out option into a zero Balance whn not found
|
// unwrap out option into a zero Balance when not found
|
||||||
// (This can be done via `.unwrapOrDefault()`, which does the same underlying)
|
// (This can be done via `.unwrapOrDefault()`, which does the same underlying)
|
||||||
const balance: Balance = balanceOpt.unwrapOr(api.createType('Balance'));
|
const balance: Balance = balanceOpt.unwrapOr(api.createType('Balance'));
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Therefore to cater for all types, a mapping in done on the [@polkadot/types libr
|
|||||||
|
|
||||||
Additionally, the API contains some logic for chain type detection, for instance in the case of Substrate 1.x based chains, it will define `BlockNumber` & `Index` (nonce) as a `u64`, while for current-generation chains, these will be defined as `u32`. Some of the work in maintaining the API for Polkadot/Substrate is the addition of types as they appear and gets used in the Rust codebase.
|
Additionally, the API contains some logic for chain type detection, for instance in the case of Substrate 1.x based chains, it will define `BlockNumber` & `Index` (nonce) as a `u64`, while for current-generation chains, these will be defined as `u32`. Some of the work in maintaining the API for Polkadot/Substrate is the addition of types as they appear and gets used in the Rust codebase.
|
||||||
|
|
||||||
There is a the [recommendation](install.md#betas) to use a `@polkadot/api@beta` should you wish to track the master branches of Polkadot or Substrate, since master changes for the addition of new types do not make it into a stable release immediately.
|
There is the [recommendation](install.md#betas) to use a `@polkadot/api@beta` should you wish to track the master branches of Polkadot or Substrate, since master changes for the addition of new types do not make it into a stable release immediately.
|
||||||
|
|
||||||
## Extension
|
## Extension
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ Document: {
|
|||||||
|
|
||||||
## User-defined enum
|
## User-defined enum
|
||||||
|
|
||||||
One form of types that appear regularly is enums, these can be defined as follow -
|
One form of types that appear regularly is enums, these can be defined as follows -
|
||||||
|
|
||||||
```js
|
```js
|
||||||
...
|
...
|
||||||
@@ -212,4 +212,4 @@ Always look at customization and understand the impacts, replicating these chang
|
|||||||
|
|
||||||
## Custom RPC
|
## Custom RPC
|
||||||
|
|
||||||
In addition to customizing modules and types on your node, you can also add custom RPC definitions. Like the type definitions in ths section, [these can be defined and passed to the API](rpc.custom.md) for decoration.
|
In addition to customizing your node's modules and types, you can also add custom RPC definitions. Like the type definitions in this section, [these can be defined and passed to the API](rpc.custom.md) for decoration.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# TypeScript user generated
|
# 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 own definitions and chain types.
|
In the previous section we looked at the TypeScript definitions that are available and are 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 own definitions and chain types.
|
||||||
|
|
||||||
## Definitions
|
## Definitions
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ In the root of your project (with the `@polkadot/typegen` package installed), yo
|
|||||||
|
|
||||||
## Chain modules
|
## 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}.*` 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 same way as the type library provides defaults from a substrate-base chain, you can also, directly from the chain's 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 targeted 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.)
|
||||||
|
|
||||||
@@ -27,4 +27,4 @@ The [TypeScript augmentation example](../examples/promise/90_typegen/) example p
|
|||||||
|
|
||||||
## And that's a wrap
|
## And that's a wrap
|
||||||
|
|
||||||
This brings us to the end of our overview and jump through the API. While the documentation is still very much and ever evolving item, we can encourage you to try out what you have learned with some [examples](../examples). As we [indicated right at the start of this journey](README.md#help-us-help-others), if there are areas for improvement, let us know.
|
This brings us to the end of our overview and jump through the API. While the documentation is still very much an ever evolving item, we can encourage you to try out what you have learned with some [examples](../examples). As we [indicated right at the start of this journey](README.md#help-us-help-others), if there are areas for improvement, let us know.
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const config = require('@polkadot/dev/config/jest');
|
const config = require('@polkadot/dev/config/jest');
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
|||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"npmClient": "yarn",
|
|
||||||
"useWorkspaces": true,
|
|
||||||
"command": {
|
|
||||||
"publish": {
|
|
||||||
"allowBranch": "master"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
],
|
|
||||||
"version": "1.14.1"
|
|
||||||
}
|
|
||||||
+15
-10
@@ -7,7 +7,8 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"typescript": "^3.8.3"
|
"babel-core": "^7.0.0-bridge.0",
|
||||||
|
"typescript": "^4.0.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn build:interfaces && polkadot-dev-build-ts && (cd packages/typegen && copyfiles scripts/* build)",
|
"build": "yarn build:interfaces && polkadot-dev-build-ts && (cd packages/typegen && copyfiles scripts/* build)",
|
||||||
@@ -24,14 +25,18 @@
|
|||||||
"test:watch": "polkadot-dev-run-test --watch"
|
"test:watch": "polkadot-dev-run-test --watch"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.9.6",
|
"@babel/core": "^7.11.6",
|
||||||
"@babel/register": "^7.9.0",
|
"@babel/register": "^7.11.5",
|
||||||
"@babel/runtime": "^7.9.6",
|
"@babel/runtime": "^7.11.2",
|
||||||
"@polkadot/dev": "^0.52.19",
|
"@polkadot/dev": "^0.57.8",
|
||||||
"@polkadot/ts": "^0.3.21",
|
"@polkadot/ts": "^0.3.49",
|
||||||
"@polkadot/typegen": "workspace:packages/typegen",
|
"@polkadot/typegen": "workspace:packages/typegen",
|
||||||
"@types/jest": "^25.2.1",
|
"@types/jest": "^26.0.14",
|
||||||
"@vuepress/plugin-search": "^1.4.1",
|
"@vuepress/plugin-search": "^1.6.0",
|
||||||
"copyfiles": "^2.2.0"
|
"copyfiles": "^2.4.0",
|
||||||
}
|
"typedoc": "^0.19.2",
|
||||||
|
"typedoc-plugin-markdown": "^3.0.7",
|
||||||
|
"typedoc-plugin-no-inherit": "^1.2.0"
|
||||||
|
},
|
||||||
|
"version": "2.1.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/api-contract",
|
"name": "@polkadot/api-contract",
|
||||||
"version": "1.14.1",
|
"version": "2.1.1",
|
||||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.9.6",
|
"@babel/runtime": "^7.11.2",
|
||||||
"@polkadot/api": "1.14.1",
|
"@polkadot/api": "2.1.1",
|
||||||
"@polkadot/rpc-core": "1.14.1",
|
"@polkadot/rpc-core": "2.1.1",
|
||||||
"@polkadot/types": "1.14.1",
|
"@polkadot/types": "2.1.1",
|
||||||
"@polkadot/util": "^2.10.1",
|
"@polkadot/util": "^3.5.1",
|
||||||
"bn.js": "^5.1.1",
|
"bn.js": "^5.1.3",
|
||||||
"rxjs": "^6.5.5"
|
"rxjs": "^6.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { TypeRegistry } from '@polkadot/types';
|
import { TypeRegistry } from '@polkadot/types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { Registry } from '@polkadot/types/types';
|
import { Registry } from '@polkadot/types/types';
|
||||||
import { AbiConstructors, AbiMessages, ContractABI, ContractABIPre, ContractABIFn, InterfaceAbi } from './types';
|
import { AbiConstructors, AbiMessages, ContractABI, ContractABIPre, ContractABIFn, InterfaceAbi } from './types';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { CodecArg, Constructor, Registry, TypeDef } from '@polkadot/types/types';
|
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 { ContractABIArgBasePre, ContractABIContract, ContractABIContractPre, ContractABIEvent, ContractABIEventPre, ContractABIFn, ContractABIFnArg, ContractABIMessage, ContractABIMessageBase, ContractABIMessagePre, ContractABI, ContractABIMessageCommon, ContractABIPre, ContractABIRange, ContractABIRangePre, ContractABIStorage, ContractABIStorageLayout, ContractABIStorageLayoutPre, ContractABIStoragePre, ContractABIStorageStruct, ContractABIStorageStructPre, ContractABITypePre } from './types';
|
||||||
@@ -19,7 +18,7 @@ function parseSelector (registry: Registry, fnname: string, input: ContractABIMe
|
|||||||
return registry.createType('u32', hexToU8a(input));
|
return registry.createType('u32', hexToU8a(input));
|
||||||
} else if (typeof input === 'string') {
|
} else if (typeof input === 'string') {
|
||||||
try {
|
try {
|
||||||
const array = JSON.parse(input);
|
const array = JSON.parse(input) as unknown[];
|
||||||
|
|
||||||
assert(array.length === 4, `${fnname}: Invalid selector length`);
|
assert(array.length === 4, `${fnname}: Invalid selector length`);
|
||||||
|
|
||||||
@@ -108,7 +107,7 @@ export default class ContractRegistry extends MetaRegistry {
|
|||||||
|
|
||||||
public createMessage (name: string, message: Partial<ContractABIMessage> & ContractABIMessageBase): ContractABIFn {
|
public createMessage (name: string, message: Partial<ContractABIMessage> & ContractABIMessageBase): ContractABIFn {
|
||||||
const args = message.args.map(({ name, type }): ContractABIFnArg => {
|
const args = message.args.map(({ name, type }): ContractABIFnArg => {
|
||||||
assert(isObject(type), `Invalid type at index ${type}`);
|
assert(isObject(type), `Invalid type at index ${type.toString()}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: stringCamelCase(name),
|
name: stringCamelCase(name),
|
||||||
@@ -183,6 +182,7 @@ export default class ContractRegistry extends MetaRegistry {
|
|||||||
public convertMessage ({ args, name, return_type: returnType, ...message }: ContractABIMessagePre): ContractABIMessage {
|
public convertMessage ({ args, name, return_type: returnType, ...message }: ContractABIMessagePre): ContractABIMessage {
|
||||||
return {
|
return {
|
||||||
...message,
|
...message,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
args: this.convertArgs(args),
|
args: this.convertArgs(args),
|
||||||
name: this._stringAt(name),
|
name: this._stringAt(name),
|
||||||
returnType: returnType ? this.convertType(returnType) : null
|
returnType: returnType ? this.convertType(returnType) : null
|
||||||
@@ -191,6 +191,7 @@ export default class ContractRegistry extends MetaRegistry {
|
|||||||
|
|
||||||
public convertEvent ({ args }: ContractABIEventPre): ContractABIEvent {
|
public convertEvent ({ args }: ContractABIEventPre): ContractABIEvent {
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
args: this.convertArgs(args)
|
args: this.convertArgs(args)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { TypeRegistry } from '@polkadot/types';
|
import { TypeRegistry } from '@polkadot/types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { MetaRegistryItem, MetaRegistryJson, MetaTypeDefClikeEnum, MetaType, MetaTypeDefEnum, MetaTypeDefEnumVariant, MetaTypeDefEnumVariantStruct, MetaTypeDefEnumVariantTupleStruct, MetaTypeDefEnumVariantUnit, MetaTypeDefStruct, MetaTypeDefStructField, MetaTypeDefTupleStruct, MetaTypeDefUnion, MetaTypeIdCustom, MetaTypeIdVec, MetaTypeIdVecFixed, MetaTypeInfo, Registry, StringIndex, TypeDef, TypeDefInfo, TypeIndex } from '@polkadot/types/types';
|
import { MetaRegistryItem, MetaRegistryJson, MetaTypeDefClikeEnum, MetaType, MetaTypeDefEnum, MetaTypeDefEnumVariant, MetaTypeDefEnumVariantStruct, MetaTypeDefEnumVariantTupleStruct, MetaTypeDefEnumVariantUnit, MetaTypeDefStruct, MetaTypeDefStructField, MetaTypeDefTupleStruct, MetaTypeDefUnion, MetaTypeIdCustom, MetaTypeIdVec, MetaTypeIdVecFixed, MetaTypeInfo, Registry, StringIndex, TypeDef, TypeDefInfo, TypeIndex } from '@polkadot/types/types';
|
||||||
|
|
||||||
import { assert } from '@polkadot/util';
|
import { assert } from '@polkadot/util';
|
||||||
import { displayType, withTypeString } from '@polkadot/types';
|
import { displayType, withTypeString } from '@polkadot/types';
|
||||||
|
|
||||||
const builtinMap: [(id: any) => boolean, MetaTypeInfo][] = [
|
const builtinMap: [(id: unknown | unknown[] | { 'array.type': unknown } | { 'slice.type': unknown }) => boolean, MetaTypeInfo][] = [
|
||||||
[(id: any): boolean => typeof id === 'string', MetaTypeInfo.BuiltinPlain],
|
[(id: any) => typeof id === 'string', MetaTypeInfo.BuiltinPlain],
|
||||||
[(id: any): boolean => Array.isArray(id), MetaTypeInfo.BuiltinTuple],
|
[(id: any) => Array.isArray(id), MetaTypeInfo.BuiltinTuple],
|
||||||
[(id: any): boolean => !!(id['array.type']), MetaTypeInfo.BuiltinVecFixed],
|
[(id: any) => !!((id as { 'array.type': unknown })['array.type']), MetaTypeInfo.BuiltinVecFixed],
|
||||||
[(id: any): boolean => !!(id['slice.type']), MetaTypeInfo.BuiltinVec]
|
[(id: any) => !!((id as { 'slice.type': unknown })['slice.type']), MetaTypeInfo.BuiltinVec]
|
||||||
];
|
];
|
||||||
|
|
||||||
const typeMap: [string, MetaTypeInfo][] = [
|
const typeMap: [string, MetaTypeInfo][] = [
|
||||||
@@ -25,8 +24,8 @@ function detectedType ({ def, id }: MetaType): MetaTypeInfo {
|
|||||||
assert(!(def as MetaTypeDefUnion)['union.fields'], 'Invalid union type definition found');
|
assert(!(def as MetaTypeDefUnion)['union.fields'], 'Invalid union type definition found');
|
||||||
|
|
||||||
const lookup = def === 'builtin'
|
const lookup = def === 'builtin'
|
||||||
? builtinMap.find(([test]): boolean => test(id))
|
? builtinMap.find(([test]) => test(id))
|
||||||
: typeMap.find(([test]): boolean => !!(def as any)[test]);
|
: typeMap.find(([test]) => !!(def as unknown as Record<string, unknown>)[test]);
|
||||||
|
|
||||||
return lookup
|
return lookup
|
||||||
? lookup[1]
|
? lookup[1]
|
||||||
@@ -59,7 +58,7 @@ class MetadataRegistryLookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _itemAt (index: number, variant: MetaRegistryItem): any {
|
protected _itemAt (index: number, variant: MetaRegistryItem): string | MetaType | TypeDef {
|
||||||
assert(this._hasItemAt(index, variant), `MetaRegistry: Invalid ${variant} index ${index} found in metadata`);
|
assert(this._hasItemAt(index, variant), `MetaRegistry: Invalid ${variant} index ${index} found in metadata`);
|
||||||
|
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
@@ -72,24 +71,24 @@ class MetadataRegistryLookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _itemsAt (indices: number[], variant: MetaRegistryItem): any[] {
|
protected _itemsAt (indices: number[], variant: MetaRegistryItem): (string | MetaType | TypeDef)[] {
|
||||||
return indices.map((index: number): string => this._itemAt(index, variant));
|
return indices.map((index: number) => this._itemAt(index, variant));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _stringAt (index: StringIndex): string {
|
protected _stringAt (index: StringIndex): string {
|
||||||
return this._itemAt(index, MetaRegistryItem.String);
|
return this._itemAt(index, MetaRegistryItem.String) as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
public stringsAt (indices: StringIndex[]): string[] {
|
public stringsAt (indices: StringIndex[]): string[] {
|
||||||
return this._itemsAt(indices, MetaRegistryItem.String);
|
return this._itemsAt(indices, MetaRegistryItem.String) as string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
public typeAt (index: TypeIndex): MetaType {
|
public typeAt (index: TypeIndex): MetaType {
|
||||||
return this._itemAt(index, MetaRegistryItem.Type);
|
return this._itemAt(index, MetaRegistryItem.Type) as MetaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public typesAt (indices: TypeIndex[]): MetaType[] {
|
public typesAt (indices: TypeIndex[]): MetaType[] {
|
||||||
return this._itemsAt(indices, MetaRegistryItem.Type);
|
return this._itemsAt(indices, MetaRegistryItem.Type) as MetaType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasTypeDefAt (index: TypeIndex): boolean {
|
public hasTypeDefAt (index: TypeIndex): boolean {
|
||||||
@@ -98,7 +97,7 @@ class MetadataRegistryLookup {
|
|||||||
|
|
||||||
public typeDefAt (index: TypeIndex, extra: Pick<TypeDef, never> = {}): TypeDef {
|
public typeDefAt (index: TypeIndex, extra: Pick<TypeDef, never> = {}): TypeDef {
|
||||||
return {
|
return {
|
||||||
...this._itemAt(index, MetaRegistryItem.TypeDef),
|
...this._itemAt(index, MetaRegistryItem.TypeDef) as TypeDef,
|
||||||
...extra
|
...extra
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -136,7 +135,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _typeDefDefFields (metaType: MetaType, typeIndex?: TypeIndex): Pick<TypeDef, never> {
|
private _typeDefDefFields (metaType: MetaType, typeIndex: TypeIndex = -1): Pick<TypeDef, never> {
|
||||||
let typeDef;
|
let typeDef;
|
||||||
|
|
||||||
switch (detectedType(metaType)) {
|
switch (detectedType(metaType)) {
|
||||||
@@ -234,7 +233,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _typeDefForBuiltinVec (id: MetaTypeIdVec, typeIndex?: TypeIndex): Pick<TypeDef, never> {
|
private _typeDefForBuiltinVec (id: MetaTypeIdVec, typeIndex: TypeIndex = -1): Pick<TypeDef, never> {
|
||||||
const { 'slice.type': vecTypeIndex } = id;
|
const { 'slice.type': vecTypeIndex } = id;
|
||||||
|
|
||||||
assert(!typeIndex || vecTypeIndex !== typeIndex, `MetaRegistry: self-referencing registry type at index ${typeIndex}`);
|
assert(!typeIndex || vecTypeIndex !== typeIndex, `MetaRegistry: self-referencing registry type at index ${typeIndex}`);
|
||||||
@@ -250,7 +249,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _typeDefForBuiltinVecFixed (id: MetaTypeIdVecFixed, typeIndex?: TypeIndex): Pick<TypeDef, never> {
|
private _typeDefForBuiltinVecFixed (id: MetaTypeIdVecFixed, typeIndex: TypeIndex = -1): Pick<TypeDef, never> {
|
||||||
const { 'array.len': vecLength, 'array.type': vecTypeIndex } = id;
|
const { 'array.len': vecLength, 'array.type': vecTypeIndex } = id;
|
||||||
|
|
||||||
assert(!vecLength || vecLength <= 256, 'MetaRegistry: Only support for [Type; <length>], where length <= 256');
|
assert(!vecLength || vecLength <= 256, 'MetaRegistry: Only support for [Type; <length>], where length <= 256');
|
||||||
@@ -301,7 +300,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public typeDefForOption (id: MetaTypeIdCustom, typeIndex?: TypeIndex): Pick<TypeDef, any> {
|
public typeDefForOption (id: MetaTypeIdCustom, typeIndex: TypeIndex = -1): Pick<TypeDef, any> {
|
||||||
assert(id['custom.params'] && id['custom.params'][0], `Invalid Option type defined at index ${typeIndex}`);
|
assert(id['custom.params'] && id['custom.params'][0], `Invalid Option type defined at index ${typeIndex}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -310,7 +309,7 @@ export default class MetaRegistry extends MetadataRegistryLookup {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public typeDefForResult (id: MetaTypeIdCustom, typeIndex?: TypeIndex): Pick<TypeDef, any> {
|
public typeDefForResult (id: MetaTypeIdCustom, typeIndex: TypeIndex = -1): Pick<TypeDef, any> {
|
||||||
assert(id['custom.params'] && id['custom.params'][0] && id['custom.params'][1], `Invalid Result type defined at index ${typeIndex}`);
|
assert(id['custom.params'] && id['custom.params'][0] && id['custom.params'][1], `Invalid Result type defined at index ${typeIndex}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||||
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
||||||
@@ -17,6 +16,7 @@ import Abi from '../Abi';
|
|||||||
import Contract from './Contract';
|
import Contract from './Contract';
|
||||||
import { BaseWithTx } from './util';
|
import { BaseWithTx } from './util';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
type BlueprintCreateResultSubscription<ApiType extends ApiTypes> = Observable<BlueprintCreateResult<ApiType>>;
|
type BlueprintCreateResultSubscription<ApiType extends ApiTypes> = Observable<BlueprintCreateResult<ApiType>>;
|
||||||
|
|
||||||
export interface BlueprintCreate<ApiType extends ApiTypes> {
|
export interface BlueprintCreate<ApiType extends ApiTypes> {
|
||||||
@@ -47,6 +47,7 @@ export default class Blueprint<ApiType extends ApiTypes> extends BaseWithTx<ApiT
|
|||||||
assert(!!this.abi.constructors[constructorIndex], `Specified constructor index ${constructorIndex} does not exist`);
|
assert(!!this.abi.constructors[constructorIndex], `Specified constructor index ${constructorIndex} does not exist`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
signAndSend: this.decorateMethod(
|
signAndSend: this.decorateMethod(
|
||||||
(account: IKeyringPair | string | AccountId | Address): BlueprintCreateResultSubscription<ApiType> => {
|
(account: IKeyringPair | string | AccountId | Address): BlueprintCreateResultSubscription<ApiType> => {
|
||||||
return this._apiContracts
|
return this._apiContracts
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||||
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
|
||||||
@@ -17,9 +16,9 @@ import Abi from '../Abi';
|
|||||||
import Blueprint from './Blueprint';
|
import Blueprint from './Blueprint';
|
||||||
import { BaseWithTx } from './util';
|
import { BaseWithTx } from './util';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
type CodePutCodeResultSubscription<ApiType extends ApiTypes> = Observable<CodePutCodeResult<ApiType>>;
|
type CodePutCodeResultSubscription<ApiType extends ApiTypes> = Observable<CodePutCodeResult<ApiType>>;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
|
||||||
export interface CodePutCode<ApiType extends ApiTypes> {
|
export interface CodePutCode<ApiType extends ApiTypes> {
|
||||||
signAndSend (account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType>;
|
signAndSend (account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType>;
|
||||||
}
|
}
|
||||||
@@ -46,6 +45,7 @@ export default class Code<ApiType extends ApiTypes> extends BaseWithTx<ApiType>
|
|||||||
|
|
||||||
public createBlueprint = (maxGas: number | BN): CodePutCode<ApiType> => {
|
public createBlueprint = (maxGas: number | BN): CodePutCode<ApiType> => {
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
signAndSend: this.decorateMethod(
|
signAndSend: this.decorateMethod(
|
||||||
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> =>
|
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> =>
|
||||||
this._apiContracts
|
this._apiContracts
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiTypes, DecorateMethod, ObsInnerType } from '@polkadot/api/types';
|
import { ApiTypes, DecorateMethod, ObsInnerType } from '@polkadot/api/types';
|
||||||
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
|
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
|
||||||
import { Codec, IKeyringPair } from '@polkadot/types/types';
|
import { Codec, CodecArg, IKeyringPair } from '@polkadot/types/types';
|
||||||
import { ApiObject, ContractABIMessage, ContractABIPre, ContractCallOutcome } from '../types';
|
import { ApiObject, ContractABIMessage, ContractABIPre, ContractCallOutcome } from '../types';
|
||||||
|
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
@@ -18,10 +17,11 @@ import { BaseWithTxAndRpcCall } from './util';
|
|||||||
type ContractCallTypes = 'tx' | 'rpc';
|
type ContractCallTypes = 'tx' | 'rpc';
|
||||||
|
|
||||||
type ContractCallResultSubscription<ApiType extends ApiTypes, CallType extends ContractCallTypes> = ApiType extends 'rxjs'
|
type ContractCallResultSubscription<ApiType extends ApiTypes, CallType extends ContractCallTypes> = ApiType extends 'rxjs'
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
? Observable<ContractCallResult<CallType>>
|
? Observable<ContractCallResult<CallType>>
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
: Promise<ObsInnerType<ContractCallResult<CallType>>>;
|
: Promise<ObsInnerType<ContractCallResult<CallType>>>;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
|
||||||
export interface ContractCall<ApiType extends ApiTypes, CallType extends ContractCallTypes> {
|
export interface ContractCall<ApiType extends ApiTypes, CallType extends ContractCallTypes> {
|
||||||
send (account: IKeyringPair | string | AccountId | Address): ContractCallResultSubscription<ApiType, CallType>;
|
send (account: IKeyringPair | string | AccountId | Address): ContractCallResultSubscription<ApiType, CallType>;
|
||||||
}
|
}
|
||||||
@@ -39,12 +39,13 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
|||||||
this.address = this.registry.createType('Address', address);
|
this.address = this.registry.createType('Address', address);
|
||||||
}
|
}
|
||||||
|
|
||||||
public call (as: 'rpc', message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, 'rpc'>;
|
public call (as: 'rpc', message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, 'rpc'>;
|
||||||
public call (as: 'tx', message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, 'tx'>;
|
public call (as: 'tx', message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, 'tx'>;
|
||||||
public call<CallType extends ContractCallTypes> (as: CallType, message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, CallType> {
|
public call<CallType extends ContractCallTypes> (as: CallType, message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, CallType> {
|
||||||
const { def, fn } = this.getMessage(message);
|
const { def, fn } = this.getMessage(message);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
send: this.decorateMethod(
|
send: this.decorateMethod(
|
||||||
as === 'rpc' && this.hasRpcContractsCall
|
as === 'rpc' && this.hasRpcContractsCall
|
||||||
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> =>
|
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> =>
|
||||||
@@ -67,7 +68,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createOutcome (result: ContractExecResult, origin: AccountId, message: ContractABIMessage, params: any[]): ContractCallOutcome {
|
private _createOutcome (result: ContractExecResult, origin: AccountId, message: ContractABIMessage, params: CodecArg[]): ContractCallOutcome {
|
||||||
let output: Codec | null = null;
|
let output: Codec | null = null;
|
||||||
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export { default as Blueprint } from './Blueprint';
|
export { default as Blueprint } from './Blueprint';
|
||||||
export { default as Code } from './Code';
|
export { default as Code } from './Code';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiTypes, DecorateMethod, DecoratedRpc, SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
import { ApiTypes, DecorateMethod, DecoratedRpc, SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
||||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||||
@@ -46,7 +45,7 @@ export abstract class Base<ApiType extends ApiTypes> implements ContractBase<Api
|
|||||||
: 0;
|
: 0;
|
||||||
const def = this.abi.abi.contract.messages[index];
|
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}`);
|
assert(!!def, `Attempted to access a contract message that does not exist: ${typeof nameOrIndex === 'number' ? `index ${nameOrIndex}` : (nameOrIndex || 'unknown')}`);
|
||||||
|
|
||||||
const fn = this.abi.messages[def.name] || this.abi.messages[stringCamelCase(def.name)];
|
const fn = this.abi.messages[def.name] || this.abi.messages[stringCamelCase(def.name)];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export { default as Abi } from './Abi';
|
export { default as Abi } from './Abi';
|
||||||
export * from './rx';
|
export * from './rx';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { Hash } from '@polkadot/types/interfaces';
|
import { Hash } from '@polkadot/types/interfaces';
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId } from '@polkadot/types/interfaces';
|
import { AccountId } from '@polkadot/types/interfaces';
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export { default as PromiseBlueprint } from './PromiseBlueprint';
|
export { default as PromiseBlueprint } from './PromiseBlueprint';
|
||||||
export { default as PromiseCode } from './PromiseCode';
|
export { default as PromiseCode } from './PromiseCode';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { Hash } from '@polkadot/types/interfaces';
|
import { Hash } from '@polkadot/types/interfaces';
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId } from '@polkadot/types/interfaces';
|
import { AccountId } from '@polkadot/types/interfaces';
|
||||||
import { ContractABIPre } from '../types';
|
import { ContractABIPre } from '../types';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export { default as RxBlueprint } from './RxBlueprint';
|
export { default as RxBlueprint } from './RxBlueprint';
|
||||||
export { default as RxCode } from './RxCode';
|
export { default as RxCode } from './RxCode';
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||||
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
|
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
import { Codec, CodecArg } from '@polkadot/types/types';
|
import { Codec, CodecArg } from '@polkadot/types/types';
|
||||||
import { MetaRegistryJson, StringIndex, TypeIndex, TypeDef } from '@polkadot/types/create/types';
|
import { MetaRegistryJson, StringIndex, TypeIndex, TypeDef } from '@polkadot/types/create/types';
|
||||||
|
|
||||||
import { ApiPromise, ApiRx } from '@polkadot/api';
|
import { ApiPromise, ApiRx } from '@polkadot/api';
|
||||||
|
|
||||||
|
// I give up, too hard to untangle atm... and is basically deprecated
|
||||||
|
/* eslint-disable no-use-before-define */
|
||||||
|
|
||||||
export type ApiObject<ApiType extends ApiTypes> = ApiType extends 'rxjs'
|
export type ApiObject<ApiType extends ApiTypes> = ApiType extends 'rxjs'
|
||||||
? ApiRx
|
? ApiRx
|
||||||
: ApiPromise;
|
: ApiPromise;
|
||||||
@@ -23,6 +26,7 @@ export interface ContractBase<ApiType extends ApiTypes> {
|
|||||||
|
|
||||||
export interface ContractABITypePre {
|
export interface ContractABITypePre {
|
||||||
ty: TypeIndex;
|
ty: TypeIndex;
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
display_name: StringIndex[];
|
display_name: StringIndex[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +60,7 @@ export interface ContractABIMessageCommon {
|
|||||||
|
|
||||||
export interface ContractABIMessagePre extends ContractABIMessageCommon, ContractABIMessageBasePre {
|
export interface ContractABIMessagePre extends ContractABIMessageCommon, ContractABIMessageBasePre {
|
||||||
name: StringIndex;
|
name: StringIndex;
|
||||||
|
// eslint-disable-next-line camelcase
|
||||||
return_type: ContractABITypePre | null;
|
return_type: ContractABITypePre | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +192,7 @@ export interface InterfaceAbi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface InterfaceContractCalls {
|
export interface InterfaceContractCalls {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
[index: string]: Function;
|
[index: string]: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { Codec, Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types';
|
import { Codec, Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
# @polkadot/api-derive
|
# @polkadot/api-derive
|
||||||
|
|
||||||
Common functions used across Polkadot, derived from RPC calls and storage queries.
|
Common functions used across Polkadot, derived from RPC calls and storage queries.
|
||||||
|
|
||||||
## Classes
|
|
||||||
|
|
||||||
[Classes](SUMMARY.md)
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/api-derive",
|
"name": "@polkadot/api-derive",
|
||||||
"version": "1.14.1",
|
"version": "2.1.1",
|
||||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -27,18 +27,18 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.9.6",
|
"@babel/runtime": "^7.11.2",
|
||||||
"@polkadot/api": "1.14.1",
|
"@polkadot/api": "2.1.1",
|
||||||
"@polkadot/rpc-core": "1.14.1",
|
"@polkadot/rpc-core": "2.1.1",
|
||||||
"@polkadot/rpc-provider": "1.14.1",
|
"@polkadot/rpc-provider": "2.1.1",
|
||||||
"@polkadot/types": "1.14.1",
|
"@polkadot/types": "2.1.1",
|
||||||
"@polkadot/util": "^2.10.1",
|
"@polkadot/util": "^3.5.1",
|
||||||
"@polkadot/util-crypto": "^2.10.1",
|
"@polkadot/util-crypto": "^3.5.1",
|
||||||
"bn.js": "^5.1.1",
|
"bn.js": "^5.1.3",
|
||||||
"memoizee": "^0.4.14",
|
"memoizee": "^0.4.14",
|
||||||
"rxjs": "^6.5.5"
|
"rxjs": "^6.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/keyring": "^2.10.1"
|
"@polkadot/keyring": "^3.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
|
import { Observable, of } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
|
import { isU8a, assert } from '@polkadot/util';
|
||||||
|
import { decodeAddress } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIndex | string | null | undefined): Observable<AccountId> {
|
||||||
|
const decoded = isU8a(address)
|
||||||
|
? address
|
||||||
|
: decodeAddress((address || '').toString());
|
||||||
|
|
||||||
|
if (decoded.length === 32) {
|
||||||
|
return of(api.registry.createType('AccountId', decoded));
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||||
|
|
||||||
|
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||||
|
map((accountId) => {
|
||||||
|
assert(accountId, 'Unable to retrieve accountId');
|
||||||
|
|
||||||
|
return accountId;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name accountId
|
||||||
|
* @param {(Address | AccountId | AccountIndex | string | null)} address - An accounts address in various formats.
|
||||||
|
* @description An [[AccountId]]
|
||||||
|
*/
|
||||||
|
export function accountId (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
||||||
|
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> =>
|
||||||
|
retrieve(api, address));
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId, Address, Balance } from '@polkadot/types/interfaces';
|
import { AccountId, Address, Balance } from '@polkadot/types/interfaces';
|
||||||
@@ -31,8 +30,8 @@ function isIncludedFn (accountId: AccountId | Address | string): (_: AccountId |
|
|||||||
* @name info
|
* @name info
|
||||||
* @description Returns account membership flags
|
* @description Returns account membership flags
|
||||||
*/
|
*/
|
||||||
export function flags (api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||||
return memo((address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
|
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
|
||||||
const councilSection = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
const councilSection = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||||
import { AccountIdAndIndex } from '../types';
|
import { AccountIdAndIndex } from '../types';
|
||||||
@@ -30,7 +29,7 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
|||||||
|
|
||||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||||
|
|
||||||
return api.derive.accounts.indexToId(accountIndex).pipe(
|
return api.derive.accounts.indexToId(accountIndex.toString()).pipe(
|
||||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -51,7 +50,7 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> {
|
export function idAndIndex (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> {
|
||||||
return memo((address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
||||||
retrieve(api, address));
|
retrieve(api, address));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||||
import { AccountIndexes } from '../types';
|
import { AccountIndexes } from '../types';
|
||||||
@@ -25,8 +24,8 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function idToIndex (api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
export function idToIndex (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
||||||
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
return memo(instanceId, (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||||
api.derive.accounts.indexes().pipe(
|
api.derive.accounts.indexes().pipe(
|
||||||
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
||||||
(indexes || {})[accountId.toString()]
|
(indexes || {})[accountId.toString()]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
|
export * from './accountId';
|
||||||
export * from './flags';
|
export * from './flags';
|
||||||
export * from './idAndIndex';
|
export * from './idAndIndex';
|
||||||
export * from './idToIndex';
|
export * from './idToIndex';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex, BalanceOf } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, BalanceOf } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -10,6 +9,7 @@ import { map, startWith } from 'rxjs/operators';
|
|||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||||
import { Option, Vec } from '@polkadot/types';
|
import { Option, Vec } from '@polkadot/types';
|
||||||
|
import { isFunction } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
@@ -48,10 +48,10 @@ function query (api: ApiInterfaceRx, accountIndex: AccountIndex | string): Obser
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
export function indexToId (instanceId: string, api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||||
return memo((accountIndex: AccountIndex | string): Observable<AccountId | undefined> =>
|
return memo(instanceId, (accountIndex: AccountIndex | string): Observable<AccountId | undefined> =>
|
||||||
api.query.indices
|
api.query.indices
|
||||||
? api.query.indices.accounts
|
? isFunction(api.query.indices.accounts)
|
||||||
? query(api, accountIndex)
|
? query(api, accountIndex)
|
||||||
: queryEnumSet(api, accountIndex)
|
: queryEnumSet(api, accountIndex)
|
||||||
: of(undefined)
|
: of(undefined)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||||
@@ -10,11 +9,14 @@ import { Observable, of } from 'rxjs';
|
|||||||
import { map, startWith, switchMap } from 'rxjs/operators';
|
import { map, startWith, switchMap } from 'rxjs/operators';
|
||||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||||
import { Vec } from '@polkadot/types';
|
import { Vec } from '@polkadot/types';
|
||||||
|
import { isFunction } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
const enumsetSize = ENUMSET_SIZE.toNumber();
|
const enumsetSize = ENUMSET_SIZE.toNumber();
|
||||||
|
|
||||||
|
let indicesCache: AccountIndexes | null = null;
|
||||||
|
|
||||||
function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||||
return api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
return api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
||||||
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
||||||
@@ -69,13 +71,22 @@ function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
||||||
return memo((): Observable<AccountIndexes> =>
|
return memo(instanceId, (): Observable<AccountIndexes> =>
|
||||||
(api.query.indices
|
indicesCache
|
||||||
? api.query.indices.accounts
|
? of(indicesCache)
|
||||||
? queryAccounts(api)
|
: (
|
||||||
: queryEnumSet(api)
|
api.query.indices
|
||||||
: of({} as AccountIndexes)
|
? isFunction(api.query.indices.accounts)
|
||||||
).pipe(startWith({}))
|
? queryAccounts(api).pipe(startWith({}))
|
||||||
|
: queryEnumSet(api).pipe(startWith({}))
|
||||||
|
: of({} as AccountIndexes)
|
||||||
|
).pipe(
|
||||||
|
map((indices): AccountIndexes => {
|
||||||
|
indicesCache = indices;
|
||||||
|
|
||||||
|
return indices;
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkadot/types/interfaces';
|
||||||
@@ -113,8 +112,8 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab
|
|||||||
* @name info
|
* @name info
|
||||||
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
||||||
*/
|
*/
|
||||||
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
export function info (instanceId: string, api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
||||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
return memo(instanceId, (address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||||
api.derive.accounts.idAndIndex(address).pipe(
|
api.derive.accounts.idAndIndex(address).pipe(
|
||||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex, RegistrationJudgement } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, RegistrationJudgement } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountData, AccountIndex, AccountInfo, 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 { ITuple } from '@polkadot/types/types';
|
||||||
@@ -9,6 +8,7 @@ import { DeriveBalancesAccount } from '../types';
|
|||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
|
import { isFunction } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ function calcBalances (api: ApiInterfaceRx, [accountId, [freeBalance, reservedBa
|
|||||||
frozenFee,
|
frozenFee,
|
||||||
frozenMisc,
|
frozenMisc,
|
||||||
reservedBalance,
|
reservedBalance,
|
||||||
votingBalance: api.registry.createType('Balance', freeBalance.add(reservedBalance))
|
votingBalance: api.registry.createType('Balance', freeBalance.toBn())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,16 +79,16 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
|
export function account (instanceId: string, api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
|
||||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
|
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
|
||||||
api.derive.accounts.info(address).pipe(
|
api.derive.accounts.accountId(address).pipe(
|
||||||
switchMap(({ accountId }): Observable<[AccountId, Result]> =>
|
switchMap((accountId): Observable<[AccountId, Result]> =>
|
||||||
(accountId
|
(accountId
|
||||||
? combineLatest([
|
? combineLatest([
|
||||||
of(accountId),
|
of(accountId),
|
||||||
api.query.system.account
|
isFunction(api.query.system.account)
|
||||||
? queryCurrent(api, accountId)
|
? queryCurrent(api, accountId)
|
||||||
: api.query.balances.account
|
: isFunction(api.query.balances.account)
|
||||||
? queryBalancesAccount(api, accountId)
|
? queryBalancesAccount(api, accountId)
|
||||||
: queryBalancesFree(api, accountId)
|
: queryBalancesFree(api, accountId)
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo212, BlockNumber, VestingInfo, VestingSchedule } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo212, BlockNumber, VestingInfo, VestingSchedule } from '@polkadot/types/interfaces';
|
||||||
import { DeriveBalancesAccount, DeriveBalancesAll } from '../types';
|
import { DeriveBalancesAccount, DeriveBalancesAll } from '../types';
|
||||||
@@ -10,25 +9,29 @@ import { Observable, combineLatest, of } from 'rxjs';
|
|||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Option, Vec } from '@polkadot/types';
|
import { Option, Vec } from '@polkadot/types';
|
||||||
import { bnMax } from '@polkadot/util';
|
import { bnMax, isFunction } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
type ResultBalance = [VestingInfo | null, (BalanceLock | BalanceLockTo212)[]];
|
type ResultBalance = [VestingInfo | null, (BalanceLock | BalanceLockTo212)[]];
|
||||||
type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance];
|
type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance];
|
||||||
|
|
||||||
|
const VESTING_ID = '0x76657374696e6720';
|
||||||
|
|
||||||
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll {
|
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll {
|
||||||
let lockedBalance = api.registry.createType('Balance');
|
let lockedBalance = api.registry.createType('Balance');
|
||||||
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
||||||
|
let vestingLocked = api.registry.createType('Balance');
|
||||||
let allLocked = false;
|
let allLocked = false;
|
||||||
|
|
||||||
if (Array.isArray(locks)) {
|
if (Array.isArray(locks)) {
|
||||||
// only get the locks that are valid until passed the current block
|
// only get the locks that are valid until passed the current block
|
||||||
lockedBreakdown = (locks as BalanceLockTo212[]).filter(({ until }): boolean => !until || (bestNumber && until.gt(bestNumber)));
|
lockedBreakdown = (locks as BalanceLockTo212[]).filter(({ until }): boolean => !until || (bestNumber && until.gt(bestNumber)));
|
||||||
|
|
||||||
const notAll = lockedBreakdown.filter(({ amount }): boolean => !amount.isMax());
|
const notAll = lockedBreakdown.filter(({ amount }) => !amount.isMax());
|
||||||
|
|
||||||
allLocked = lockedBreakdown.some(({ amount }): boolean => amount.isMax());
|
allLocked = lockedBreakdown.some(({ amount }) => amount.isMax());
|
||||||
|
vestingLocked = api.registry.createType('Balance', lockedBreakdown.filter(({ id }) => id.eq(VESTING_ID)).reduce((result: BN, { amount }) => result.iadd(amount), new BN(0)));
|
||||||
|
|
||||||
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
||||||
if (notAll.length) {
|
if (notAll.length) {
|
||||||
@@ -41,19 +44,12 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
|||||||
// - perBlock is the unlock amount
|
// - perBlock is the unlock amount
|
||||||
const { locked: vestingTotal, perBlock, startingBlock } = vesting || api.registry.createType('VestingInfo');
|
const { locked: vestingTotal, perBlock, startingBlock } = vesting || api.registry.createType('VestingInfo');
|
||||||
const isStarted = bestNumber.gt(startingBlock);
|
const isStarted = bestNumber.gt(startingBlock);
|
||||||
const vestedBalance = api.registry.createType('Balance', isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : 0);
|
const vestedNow = isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : new BN(0);
|
||||||
const isVesting = isStarted && vestedBalance.lt(vestingTotal);
|
const vestedBalance = vestedNow.gt(vestingTotal) ? vestingTotal : api.registry.createType('Balance', vestedNow);
|
||||||
|
const isVesting = isStarted && !vestingLocked.isZero();
|
||||||
// The available balance & vested has an interplay here
|
const vestedClaimable = api.registry.createType('Balance', isVesting ? vestingLocked.sub(vestingTotal.sub(vestedBalance)) : 0);
|
||||||
// "
|
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), freeBalance.sub(lockedBalance)));
|
||||||
// vesting is a guarantee that the account's balance will never go below a certain amount. so it functions in the opposite way, a bit like a lock that is monotonically decreasing rather than a liquid amount that is monotonically increasing.
|
const vestingEndBlock = api.registry.createType('BlockNumber', isVesting ? vestingTotal.div(perBlock).add(startingBlock) : 0);
|
||||||
// locks function as the same guarantee - that a balance will not be lower than a particular amount.
|
|
||||||
// because of this you can see that if there is a "vesting lock" that guarantees the balance cannot go below 200, and a "staking lock" that guarantees the balance cannot drop below 300, then we just have two guarantees of which the first is irrelevant.
|
|
||||||
// i.e. (balance >= 200 && balance >= 300) == (balance >= 300)
|
|
||||||
// ""
|
|
||||||
const floating = freeBalance.sub(lockedBalance);
|
|
||||||
const extraReceived = isVesting ? freeBalance.sub(vestingTotal) : new BN(0);
|
|
||||||
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accountId,
|
accountId,
|
||||||
@@ -67,6 +63,10 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
|||||||
lockedBreakdown,
|
lockedBreakdown,
|
||||||
reservedBalance,
|
reservedBalance,
|
||||||
vestedBalance,
|
vestedBalance,
|
||||||
|
vestedClaimable,
|
||||||
|
vestingEndBlock,
|
||||||
|
vestingLocked,
|
||||||
|
vestingPerBlock: perBlock,
|
||||||
vestingTotal,
|
vestingTotal,
|
||||||
votingBalance
|
votingBalance
|
||||||
};
|
};
|
||||||
@@ -127,15 +127,15 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAll> {
|
export function all (instanceId: string, api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAll> {
|
||||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAll> =>
|
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAll> =>
|
||||||
api.derive.balances.account(address).pipe(
|
api.derive.balances.account(address).pipe(
|
||||||
switchMap((account): Observable<Result> =>
|
switchMap((account): Observable<Result> =>
|
||||||
(!account.accountId.isEmpty
|
(!account.accountId.isEmpty
|
||||||
? combineLatest([
|
? combineLatest([
|
||||||
of(account),
|
of(account),
|
||||||
api.derive.chain.bestNumber(),
|
api.derive.chain.bestNumber(),
|
||||||
api.query.balances.account
|
isFunction(api.query.system.account) || isFunction(api.query.balances.account)
|
||||||
? queryCurrent(api, account.accountId)
|
? queryCurrent(api, account.accountId)
|
||||||
: queryOld(api, account.accountId)
|
: queryOld(api, account.accountId)
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Balance } from '@polkadot/types/interfaces';
|
import { Balance } from '@polkadot/types/interfaces';
|
||||||
@@ -24,16 +23,16 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function fees (api: ApiInterfaceRx): () => Observable<DeriveFees> {
|
export function fees (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveFees> {
|
||||||
return memo((): Observable<DeriveFees> =>
|
return memo(instanceId, (): Observable<DeriveFees> =>
|
||||||
of([
|
of([
|
||||||
// deprecated - remove
|
// deprecated - remove
|
||||||
(api.consts.balances?.creationFee as Balance) || api.registry.createType('Balance'),
|
(api.consts.balances?.creationFee as unknown as Balance) || api.registry.createType('Balance'),
|
||||||
(api.consts.balances?.transferFee as Balance) || api.registry.createType('Balance'),
|
(api.consts.balances?.transferFee as unknown as Balance) || api.registry.createType('Balance'),
|
||||||
|
|
||||||
// current
|
// current
|
||||||
(api.consts.balances?.existentialDeposit as Balance) || api.registry.createType('Balance'),
|
(api.consts.balances?.existentialDeposit as Balance) || api.registry.createType('Balance'),
|
||||||
(api.consts.transactionPayment?.transactionBaseFee as Balance) || api.registry.createType('Balance'),
|
(api.consts.transactionPayment?.transactionBaseFee as unknown as Balance) || api.registry.createType('Balance'),
|
||||||
(api.consts.transactionPayment?.transactionByteFee as Balance) || api.registry.createType('Balance')
|
(api.consts.transactionPayment?.transactionByteFee as Balance) || api.registry.createType('Balance')
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DeriveFees => ({
|
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DeriveFees => ({
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { all } from './all';
|
import { all } from './all';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||||
import { DeriveBalancesAccount } from '../types';
|
import { DeriveBalancesAccount } from '../types';
|
||||||
@@ -10,8 +9,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
|
export function votingBalances (instanceId: string, api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
|
||||||
return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DeriveBalancesAccount[]> =>
|
return memo(instanceId, (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DeriveBalancesAccount[]> =>
|
||||||
!addresses || !addresses.length
|
!addresses || !addresses.length
|
||||||
? of([] as DeriveBalancesAccount[])
|
? of([] as DeriveBalancesAccount[])
|
||||||
: combineLatest(
|
: combineLatest(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
@@ -22,8 +21,8 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
export function bestNumber (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||||
return memo((): Observable<BlockNumber> =>
|
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||||
api.derive.chain.subscribeNewHeads().pipe(
|
api.derive.chain.subscribeNewHeads().pipe(
|
||||||
map((header) => header.number.unwrap())
|
map((header) => header.number.unwrap())
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
@@ -23,8 +22,8 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
export function bestNumberFinalized (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||||
return memo((): Observable<BlockNumber> =>
|
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||||
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
||||||
map((header) => header.number.unwrap())
|
map((header) => header.number.unwrap())
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
@@ -23,8 +22,8 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
export function bestNumberLag (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||||
return memo((): Observable<BlockNumber> =>
|
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
api.derive.chain.bestNumber(),
|
api.derive.chain.bestNumber(),
|
||||||
api.derive.chain.bestNumberFinalized()
|
api.derive.chain.bestNumberFinalized()
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
|
|
||||||
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
|
import { catchError, map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import { SignedBlockExtended } from '../type';
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name getBlock
|
||||||
|
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||||
|
* @description Get a specific block (e.g. rpc.chain.getBlock) and extend it with the author
|
||||||
|
* @example
|
||||||
|
* <BR>
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* const { author, number } = await api.derive.chain.getHeader('0x123...456');
|
||||||
|
*
|
||||||
|
* console.log(`block #${number} was authored by ${author}`);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
|
||||||
|
return memo(instanceId, (hash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
|
||||||
|
combineLatest([
|
||||||
|
api.rpc.chain.getBlock(hash),
|
||||||
|
api.query.session
|
||||||
|
? api.query.session.validators.at(hash)
|
||||||
|
: of([])
|
||||||
|
]).pipe(
|
||||||
|
map(([signedBlock, validators]): SignedBlockExtended =>
|
||||||
|
new SignedBlockExtended(api.registry, signedBlock, validators)
|
||||||
|
),
|
||||||
|
catchError((): Observable<undefined> =>
|
||||||
|
// where rpc.chain.getHeader throws, we will land here - it can happen that
|
||||||
|
// we supplied an invalid hash. (Due to defaults, storeage will have an
|
||||||
|
// empty value, so only the RPC is affected). So return undefined
|
||||||
|
of()
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ import { HeaderExtended } from '../type';
|
|||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name bestNumberFinalized
|
* @name getHeader
|
||||||
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||||
* @returns An array containing the block header and the block author
|
* @returns An array containing the block header and the block author
|
||||||
* @description Get a specific block header and extend it with the author
|
* @description Get a specific block header and extend it with the author
|
||||||
@@ -24,8 +23,8 @@ import { memo } from '../util';
|
|||||||
* console.log(`block #${number} was authored by ${author}`);
|
* console.log(`block #${number} was authored by ${author}`);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||||
return memo((hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
return memo(instanceId, (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
api.rpc.chain.getHeader(hash),
|
api.rpc.chain.getHeader(hash),
|
||||||
api.query.session
|
api.query.session
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export * from './bestNumber';
|
export * from './bestNumber';
|
||||||
export * from './bestNumberFinalized';
|
export * from './bestNumberFinalized';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
|
|
||||||
@@ -23,8 +22,8 @@ import { memo } from '../util';
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable<HeaderExtended> {
|
export function subscribeNewHeads (instanceId: string, api: ApiInterfaceRx): () => Observable<HeaderExtended> {
|
||||||
return memo((): Observable<HeaderExtended> =>
|
return memo(instanceId, (): Observable<HeaderExtended> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
api.rpc.chain.subscribeNewHeads(),
|
api.rpc.chain.subscribeNewHeads(),
|
||||||
api.query.session
|
api.query.session
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export * from './proposals';
|
export * from './proposals';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
import { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||||
@@ -9,6 +8,7 @@ import { DeriveCollectiveProposal } from '../types';
|
|||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { Option } from '@polkadot/types';
|
import { Option } from '@polkadot/types';
|
||||||
|
import { isFunction } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
@@ -28,9 +28,9 @@ function parse ([hashes, proposals, votes]: Result): DeriveCollectiveProposal[]
|
|||||||
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
|
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DeriveCollectiveProposal[]> {
|
export function proposals (instanceId: string, api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DeriveCollectiveProposal[]> {
|
||||||
return memo((): Observable<DeriveCollectiveProposal[]> =>
|
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
|
||||||
api.query[section]?.proposals
|
isFunction(api.query[section]?.proposals)
|
||||||
? api.query[section].proposals().pipe(
|
? api.query[section].proposals().pipe(
|
||||||
switchMap((hashes: Hash[]): Observable<Result> =>
|
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||||
hashes.length
|
hashes.length
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { DeriveContractFees } from '../types';
|
import { DeriveContractFees } from '../types';
|
||||||
@@ -11,23 +10,24 @@ import { map } from 'rxjs/operators';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN];
|
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN];
|
||||||
|
|
||||||
// query via constants (current applicable path)
|
// query via constants (current applicable path)
|
||||||
function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||||
return of([
|
return of([
|
||||||
// deprecated
|
// deprecated
|
||||||
|
api.consts.contracts.callBaseFee || api.registry.createType('Balance'),
|
||||||
|
api.consts.contracts.contractFee || api.registry.createType('Balance'),
|
||||||
api.consts.contracts.creationFee || api.registry.createType('Balance'),
|
api.consts.contracts.creationFee || api.registry.createType('Balance'),
|
||||||
|
api.consts.contracts.transactionBaseFee || api.registry.createType('Balance'),
|
||||||
|
api.consts.contracts.transactionByteFee || api.registry.createType('Balance'),
|
||||||
api.consts.contracts.transferFee || api.registry.createType('Balance'),
|
api.consts.contracts.transferFee || api.registry.createType('Balance'),
|
||||||
|
|
||||||
// current
|
// current
|
||||||
api.consts.contracts.callBaseFee,
|
|
||||||
api.consts.contracts.contractFee,
|
|
||||||
api.consts.contracts.rentByteFee,
|
api.consts.contracts.rentByteFee,
|
||||||
api.consts.contracts.rentDepositOffset,
|
api.consts.contracts.rentDepositOffset,
|
||||||
api.consts.contracts.tombstoneDeposit,
|
api.consts.contracts.surchargeReward,
|
||||||
api.consts.contracts.transactionBaseFee,
|
api.consts.contracts.tombstoneDeposit
|
||||||
api.consts.contracts.transactionByteFee
|
|
||||||
]) as unknown as Observable<ResultV2>;
|
]) as unknown as Observable<ResultV2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,15 +44,16 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function fees (api: ApiInterfaceRx): () => Observable<DeriveContractFees> {
|
export function fees (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveContractFees> {
|
||||||
return memo((): Observable<DeriveContractFees> => {
|
return memo(instanceId, (): Observable<DeriveContractFees> => {
|
||||||
return queryConstants(api).pipe(
|
return queryConstants(api).pipe(
|
||||||
map(([creationFee, transferFee, callBaseFee, contractFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee]): DeriveContractFees => ({
|
map(([callBaseFee, contractFee, creationFee, transactionBaseFee, transactionByteFee, transferFee, rentByteFee, rentDepositOffset, surchargeReward, tombstoneDeposit]): DeriveContractFees => ({
|
||||||
callBaseFee,
|
callBaseFee,
|
||||||
contractFee,
|
contractFee,
|
||||||
creationFee,
|
creationFee,
|
||||||
rentByteFee,
|
rentByteFee,
|
||||||
rentDepositOffset,
|
rentDepositOffset,
|
||||||
|
surchargeReward,
|
||||||
tombstoneDeposit,
|
tombstoneDeposit,
|
||||||
transactionBaseFee,
|
transactionBaseFee,
|
||||||
transactionByteFee,
|
transactionByteFee,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export * from './fees';
|
export * from './fees';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export * from './proposals';
|
export * from './proposals';
|
||||||
export * from './votes';
|
export * from './votes';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { DeriveCollectiveProposals } from '../types';
|
import { DeriveCollectiveProposals } from '../types';
|
||||||
@@ -9,6 +8,6 @@ import { Observable } from 'rxjs';
|
|||||||
import { proposals as collectiveProposals } from '../collective';
|
import { proposals as collectiveProposals } from '../collective';
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposals> {
|
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposals> {
|
||||||
return memo(collectiveProposals(api, 'council'));
|
return memo(instanceId, collectiveProposals(instanceId, api, 'council'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, Balance } from '@polkadot/types/interfaces';
|
import { AccountId, Balance } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, Balance } from '@polkadot/types/interfaces';
|
import { AccountId, Balance } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -14,35 +13,19 @@ import { Vec } from '@polkadot/types';
|
|||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
function retrieveStakeOf (api: ApiInterfaceRx): Observable<[AccountId, Balance][]> {
|
function retrieveStakeOf (api: ApiInterfaceRx): Observable<[AccountId, Balance][]> {
|
||||||
const elections = (api.query.electionsPhragmen || api.query.elections);
|
return (api.query.electionsPhragmen || api.query.elections).stakeOf.entries<Balance>().pipe(
|
||||||
|
map((entries) =>
|
||||||
return elections.stakeOf.creator.meta.type.asMap.linked.isTrue
|
entries.map(([key, stake]) => [key.args[0] as AccountId, stake])
|
||||||
? elections.stakeOf<ITuple<[Vec<AccountId>, Vec<Balance>]>>().pipe(
|
|
||||||
map(([voters, stake]) =>
|
|
||||||
voters.map((voter, index): [AccountId, Balance] => [voter, stake[index]])
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
: elections.stakeOf.entries<Balance>().pipe(
|
);
|
||||||
map((entries) =>
|
|
||||||
entries.map(([key, stake]) => [key.args[0] as AccountId, stake])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveVoteOf (api: ApiInterfaceRx): Observable<[AccountId, AccountId[]][]> {
|
function retrieveVoteOf (api: ApiInterfaceRx): Observable<[AccountId, AccountId[]][]> {
|
||||||
const elections = (api.query.electionsPhragmen || api.query.elections);
|
return (api.query.electionsPhragmen || api.query.elections).votesOf.entries<Vec<AccountId>>().pipe(
|
||||||
|
map((entries) =>
|
||||||
return elections.votesOf.creator.meta.type.asMap.linked.isTrue
|
entries.map(([key, votes]) => [key.args[0] as AccountId, votes])
|
||||||
? elections.votesOf<ITuple<[Vec<AccountId>, Vec<Vec<AccountId>>]>>().pipe(
|
|
||||||
map(([voters, votes]) =>
|
|
||||||
voters.map((voter, index) => [voter, votes[index]])
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
: elections.votesOf.entries<Vec<AccountId>>().pipe(
|
);
|
||||||
map((entries) =>
|
|
||||||
entries.map(([key, votes]) => [key.args[0] as AccountId, votes])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrievePrev (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
|
function retrievePrev (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
|
||||||
@@ -81,8 +64,8 @@ function retrieveCurrent (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function votes (api: ApiInterfaceRx): () => Observable<DeriveCouncilVotes> {
|
export function votes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCouncilVotes> {
|
||||||
return memo((): Observable<DeriveCouncilVotes> =>
|
return memo(instanceId, (): Observable<DeriveCouncilVotes> =>
|
||||||
(api.query.electionsPhragmen || api.query.elections).stakeOf
|
(api.query.electionsPhragmen || api.query.elections).stakeOf
|
||||||
? retrievePrev(api)
|
? retrievePrev(api)
|
||||||
: retrieveCurrent(api)
|
: retrieveCurrent(api)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId } from '@polkadot/types/interfaces';
|
import { AccountId } from '@polkadot/types/interfaces';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
@@ -10,8 +9,8 @@ import { Observable } from 'rxjs';
|
|||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function votesOf (api: ApiInterfaceRx): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
export function votesOf (instanceId: string, api: ApiInterfaceRx): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
||||||
return memo((accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
||||||
api.derive.council.votes().pipe(
|
api.derive.council.votes().pipe(
|
||||||
map((votes): DeriveCouncilVote =>
|
map((votes): DeriveCouncilVote =>
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { BlockNumber, Hash, ReferendumIndex, Scheduled } from '@polkadot/types/interfaces';
|
import { BlockNumber, Hash, ReferendumIndex, Scheduled } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -10,7 +9,7 @@ import { Observable, combineLatest, of } from 'rxjs';
|
|||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { Option, Vec, u64 } from '@polkadot/types';
|
import { Option, Vec, u64 } from '@polkadot/types';
|
||||||
import { stringToHex } from '@polkadot/util';
|
import { isFunction, stringToHex } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
@@ -94,9 +93,9 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dispatchQueue (api: ApiInterfaceRx): () => Observable<DeriveDispatch[]> {
|
export function dispatchQueue (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveDispatch[]> {
|
||||||
return memo((): Observable<DeriveDispatch[]> =>
|
return memo(instanceId, (): Observable<DeriveDispatch[]> =>
|
||||||
api.query.scheduler?.agenda
|
isFunction(api.query.scheduler?.agenda)
|
||||||
? queryScheduler(api)
|
? queryScheduler(api)
|
||||||
: api.query.democracy.dispatchQueue
|
: api.query.democracy.dispatchQueue
|
||||||
? queryQueue(api)
|
? queryQueue(api)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
export * from './dispatchQueue';
|
export * from './dispatchQueue';
|
||||||
export * from './locks';
|
export * from './locks';
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, ReferendumInfo, ReferendumInfoTo239, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
|
import { AccountId, ReferendumInfo, ReferendumInfoTo239, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { DeriveDemocracyLock } from '../types';
|
import { DeriveDemocracyLock } from '../types';
|
||||||
|
|
||||||
@@ -20,16 +19,37 @@ const ZERO = new BN(0);
|
|||||||
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock {
|
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: ReferendumInfo): DeriveDemocracyLock {
|
||||||
const { balance, vote } = accountVote.asStandard;
|
const { balance, vote } = accountVote.asStandard;
|
||||||
let unlockAt = ZERO;
|
let unlockAt = ZERO;
|
||||||
|
let referendumEnd = ZERO;
|
||||||
|
|
||||||
if (referendum.isFinished) {
|
if (referendum.isFinished) {
|
||||||
const { approved, end } = referendum.asFinished;
|
const { approved, end } = referendum.asFinished;
|
||||||
|
|
||||||
|
referendumEnd = end;
|
||||||
|
|
||||||
if ((approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)) {
|
if ((approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)) {
|
||||||
unlockAt = end.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[vote.conviction.index]));
|
unlockAt = end.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[vote.conviction.index]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { balance, isFinished: referendum.isFinished, referendumId, unlockAt, vote };
|
return { balance, isDelegated: false, isFinished: referendum.isFinished, referendumEnd, referendumId, unlockAt, vote };
|
||||||
|
}
|
||||||
|
|
||||||
|
function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: VotingDelegating): Observable<DeriveDemocracyLock[]> {
|
||||||
|
return api.derive.democracy.locks(target).pipe(
|
||||||
|
map((available): DeriveDemocracyLock[] =>
|
||||||
|
available.map(({ isFinished, referendumEnd, referendumId, unlockAt, vote }): DeriveDemocracyLock => ({
|
||||||
|
balance,
|
||||||
|
isDelegated: true,
|
||||||
|
isFinished,
|
||||||
|
referendumEnd,
|
||||||
|
referendumId,
|
||||||
|
unlockAt: unlockAt.isZero()
|
||||||
|
? unlockAt
|
||||||
|
: referendumEnd.add(api.consts.democracy.enactmentPeriod.muln(LOCKUPS[conviction.index])),
|
||||||
|
vote: api.registry.createType('Vote', { aye: vote.isAye, conviction })
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<DeriveDemocracyLock[]> {
|
function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<DeriveDemocracyLock[]> {
|
||||||
@@ -53,14 +73,18 @@ function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function locks (api: ApiInterfaceRx): (accountId: string | AccountId) => Observable<DeriveDemocracyLock[]> {
|
export function locks (instanceId: string, api: ApiInterfaceRx): (accountId: string | AccountId) => Observable<DeriveDemocracyLock[]> {
|
||||||
return memo((accountId: string | AccountId): Observable<DeriveDemocracyLock[]> =>
|
return memo(instanceId, (accountId: string | AccountId): Observable<DeriveDemocracyLock[]> =>
|
||||||
api.query.democracy.votingOf(accountId).pipe(
|
api.query.democracy.votingOf
|
||||||
switchMap((voting): Observable<DeriveDemocracyLock[]> =>
|
? api.query.democracy.votingOf(accountId).pipe(
|
||||||
voting.isDirect
|
switchMap((voting): Observable<DeriveDemocracyLock[]> =>
|
||||||
? directLocks(api, voting.asDirect)
|
voting.isDirect
|
||||||
: of([])
|
? directLocks(api, voting.asDirect)
|
||||||
|
: voting.isDelegating
|
||||||
|
? delegateLocks(api, voting.asDelegating)
|
||||||
|
: of([])
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
: of([])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { Hash, VoteThreshold } from '@polkadot/types/interfaces';
|
import { Hash, VoteThreshold } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -29,8 +28,8 @@ function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[Hash, VoteThres
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function nextExternal (api: ApiInterfaceRx): () => Observable<DeriveProposalExternal | null> {
|
export function nextExternal (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposalExternal | null> {
|
||||||
return memo((): Observable<DeriveProposalExternal | null> =>
|
return memo(instanceId, (): Observable<DeriveProposalExternal | null> =>
|
||||||
api.query.democracy?.nextExternal
|
api.query.democracy?.nextExternal
|
||||||
? api.query.democracy.nextExternal<Option<ITuple<[Hash, VoteThreshold]>>>().pipe(
|
? api.query.democracy.nextExternal<Option<ITuple<[Hash, VoteThreshold]>>>().pipe(
|
||||||
switchMap((nextOpt) => withImage(api, nextOpt))
|
switchMap((nextOpt) => withImage(api, nextOpt))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -16,8 +15,8 @@ import { parseImage } from './util';
|
|||||||
|
|
||||||
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
||||||
|
|
||||||
export function preimage (api: ApiInterfaceRx): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
|
export function preimage (instanceId: string, api: ApiInterfaceRx): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
|
||||||
return memo((hash: Hash): Observable<DeriveProposalImage | undefined> =>
|
return memo(instanceId, (hash: Hash): Observable<DeriveProposalImage | undefined> =>
|
||||||
api.query.democracy.preimages<PreImage>(hash).pipe(
|
api.query.democracy.preimages<PreImage>(hash).pipe(
|
||||||
map((imageOpt) => parseImage(api, imageOpt))
|
map((imageOpt) => parseImage(api, imageOpt))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -16,8 +15,8 @@ import { parseImage } from './util';
|
|||||||
|
|
||||||
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
||||||
|
|
||||||
export function preimages (api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
|
export function preimages (instanceId: string, api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
|
||||||
return memo((hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
|
return memo(instanceId, (hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
|
||||||
api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
|
api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
|
||||||
map((images): (DeriveProposalImage | undefined)[] =>
|
map((images): (DeriveProposalImage | undefined)[] =>
|
||||||
images.map((imageOpt) => parseImage(api, imageOpt))
|
images.map((imageOpt) => parseImage(api, imageOpt))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { AccountId, Balance, Hash, PropIndex } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, Hash, PropIndex } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
@@ -49,8 +48,8 @@ function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||||
return memo((): Observable<DeriveProposal[]> =>
|
return memo(instanceId, (): Observable<DeriveProposal[]> =>
|
||||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||||
switchMap((proposals) =>
|
switchMap((proposals) =>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { ReferendumIndex } from '@polkadot/types/interfaces';
|
import { ReferendumIndex } from '@polkadot/types/interfaces';
|
||||||
@@ -11,8 +10,8 @@ import { map } from 'rxjs/operators';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function referendumIds (api: ApiInterfaceRx): () => Observable<BN[]> {
|
export function referendumIds (instanceId: string, api: ApiInterfaceRx): () => Observable<BN[]> {
|
||||||
return memo((): Observable<BN[]> =>
|
return memo(instanceId, (): Observable<BN[]> =>
|
||||||
api.query.democracy?.lowestUnbaked
|
api.query.democracy?.lowestUnbaked
|
||||||
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
||||||
api.query.democracy.lowestUnbaked,
|
api.query.democracy.lowestUnbaked,
|
||||||
@@ -20,6 +19,7 @@ export function referendumIds (api: ApiInterfaceRx): () => Observable<BN[]> {
|
|||||||
]).pipe(
|
]).pipe(
|
||||||
map(([first, total]): BN[] =>
|
map(([first, total]): BN[] =>
|
||||||
total.gt(first)
|
total.gt(first)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
? [...Array(total.sub(first).toNumber())].map((_, i): BN => first.addn(i))
|
? [...Array(total.sub(first).toNumber())].map((_, i): BN => first.addn(i))
|
||||||
: []
|
: []
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { DeriveReferendumExt } from '../types';
|
import { DeriveReferendumExt } from '../types';
|
||||||
@@ -10,8 +9,8 @@ import { map, switchMap } from 'rxjs/operators';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function referendums (api: ApiInterfaceRx): () => Observable<DeriveReferendumExt[]> {
|
export function referendums (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveReferendumExt[]> {
|
||||||
return memo((): Observable<DeriveReferendumExt[]> =>
|
return memo(instanceId, (): Observable<DeriveReferendumExt[]> =>
|
||||||
api.derive.democracy.referendumsActive().pipe(
|
api.derive.democracy.referendumsActive().pipe(
|
||||||
switchMap((referendums) =>
|
switchMap((referendums) =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { DeriveReferendum } from '../types';
|
import { DeriveReferendum } from '../types';
|
||||||
@@ -10,8 +9,8 @@ import { switchMap } from 'rxjs/operators';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function referendumsActive (api: ApiInterfaceRx): () => Observable<DeriveReferendum[]> {
|
export function referendumsActive (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveReferendum[]> {
|
||||||
return memo((): Observable<DeriveReferendum[]> =>
|
return memo(instanceId, (): Observable<DeriveReferendum[]> =>
|
||||||
api.derive.democracy.referendumIds().pipe(
|
api.derive.democracy.referendumIds().pipe(
|
||||||
switchMap((ids): Observable<DeriveReferendum[]> =>
|
switchMap((ids): Observable<DeriveReferendum[]> =>
|
||||||
ids.length
|
ids.length
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { ReferendumInfo, ReferendumInfoFinished } from '@polkadot/types/interfaces';
|
import { ReferendumInfo, ReferendumInfoFinished } from '@polkadot/types/interfaces';
|
||||||
@@ -11,8 +10,8 @@ import { Option } from '@polkadot/types';
|
|||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export function referendumsFinished (api: ApiInterfaceRx): () => Observable<ReferendumInfoFinished[]> {
|
export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): () => Observable<ReferendumInfoFinished[]> {
|
||||||
return memo((): Observable<ReferendumInfoFinished[]> =>
|
return memo(instanceId, (): Observable<ReferendumInfoFinished[]> =>
|
||||||
api.derive.democracy.referendumIds().pipe(
|
api.derive.democracy.referendumIds().pipe(
|
||||||
switchMap((ids) => api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)),
|
switchMap((ids) => api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)),
|
||||||
map((infos): ReferendumInfoFinished[] =>
|
map((infos): ReferendumInfoFinished[] =>
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user