Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb791d3963 | ||
|
|
bc49e75e61 | ||
|
|
67f8dcafdb | ||
|
|
e95117839b | ||
|
|
9f60a8cd5f | ||
|
|
e23fae86d5 | ||
|
|
94a4594d32 | ||
|
|
5be8ef8f0d | ||
|
|
e855d5a9d4 | ||
|
|
2a0e481710 | ||
|
|
161c121cb2 | ||
|
|
de38735498 | ||
|
|
ce1e6615e3 | ||
|
|
3ebe9f5243 | ||
|
|
f686cfcce7 | ||
|
|
c27e49c6f5 | ||
|
|
5c69f78676 | ||
|
|
8f00351405 | ||
|
|
1f6c8c2eb8 | ||
|
|
9bb1343255 | ||
|
|
94ebb321f1 | ||
|
|
63fd5baa8f | ||
|
|
ea3ee428d8 | ||
|
|
5cb1c2d33a | ||
|
|
600666de1c | ||
|
|
524885e8de | ||
|
|
1476e5e5e9 | ||
|
|
3f48b3c29f | ||
|
|
9debb854f9 | ||
|
|
db3fe7d103 | ||
|
|
a93063c6fb | ||
|
|
8e4bbd2b23 | ||
|
|
cf1c2ea58a | ||
|
|
ca2909e4ba | ||
|
|
cc9ea53e1a | ||
|
|
d876e19fa1 | ||
|
|
bb7b94dc35 | ||
|
|
be1deb1a75 | ||
|
|
14026fef42 | ||
|
|
b2ea2da6aa | ||
|
|
f1d21847db | ||
|
|
b1fcfd11f4 | ||
|
|
7d1f0e2900 | ||
|
|
fb377fb0d4 | ||
|
|
26de59ed79 | ||
|
|
964bd33bb1 | ||
|
|
f068ef76a5 | ||
|
|
e6e60ec6d0 | ||
|
|
9f9680ba92 | ||
|
|
bb63de1653 | ||
|
|
a2c2b24198 | ||
|
|
1944ffe017 | ||
|
|
d4aa36981d | ||
|
|
2c735fbc53 | ||
|
|
7038045bc8 | ||
|
|
0be5c969aa | ||
|
|
9ead2bdc41 | ||
|
|
1ae37ed2d3 | ||
|
|
7ca78c5679 | ||
|
|
cd94d01b06 | ||
|
|
dafc92809d | ||
|
|
298884d885 | ||
|
|
2a64c7c29a | ||
|
|
d2b7dc550a | ||
|
|
25f18d5455 | ||
|
|
c9c872c736 | ||
|
|
8394b7fb5a | ||
|
|
fb82db382e | ||
|
|
9f83f5cac3 | ||
|
|
45a895b64f | ||
|
|
93fbd6e13f | ||
|
|
b53490bd26 | ||
|
|
594376367a | ||
|
|
180fe57531 | ||
|
|
bddb4465fb | ||
|
|
3cdc647506 | ||
|
|
82ee7cc4f1 | ||
|
|
9f9658d6a0 | ||
|
|
1abc519297 | ||
|
|
b939bcd57d | ||
|
|
d487a27676 | ||
|
|
0525feb6f2 | ||
|
|
4ea343e369 | ||
|
|
6f2173778e | ||
|
|
bb6166e65f | ||
|
|
dec82380c3 | ||
|
|
a980d4ae11 | ||
|
|
5c194b6f5f | ||
|
|
c4662e6fd8 | ||
|
|
995de2012e | ||
|
|
b1a8c011f4 | ||
|
|
86cd550ad3 | ||
|
|
57529998f9 | ||
|
|
0e0d733e65 | ||
|
|
773618acfb | ||
|
|
c5fcb0d06b | ||
|
|
e25272c986 | ||
|
|
d389c6737e | ||
|
|
9e1313f140 | ||
|
|
d2a2887d32 | ||
|
|
b3d9549c0b | ||
|
|
240cadd045 | ||
|
|
d47faa4687 | ||
|
|
393c677a16 | ||
|
|
074ddd8632 | ||
|
|
a8a10aec0c | ||
|
|
fed93e2459 | ||
|
|
374df23011 | ||
|
|
9c098c3fbf | ||
|
|
4e799858ad | ||
|
|
ee6924324f | ||
|
|
75f86bb43e | ||
|
|
bfd3113a55 | ||
|
|
8d8d5bd7d7 | ||
|
|
e64b5483ba | ||
|
|
6020ffcada | ||
|
|
1643ec7ddf | ||
|
|
76c206d60d | ||
|
|
8a8b6f7ac8 | ||
|
|
3ba0b2e0d8 | ||
|
|
1101826a05 | ||
|
|
fda1924577 | ||
|
|
2b1438030b | ||
|
|
d816859840 | ||
|
|
af0b4362c9 | ||
|
|
4cb563ba89 | ||
|
|
c098036ca5 | ||
|
|
c38afd4b5d | ||
|
|
4b8634b88e | ||
|
|
a1bab9edcf | ||
|
|
503286f7aa | ||
|
|
64e209783a | ||
|
|
43791bcc71 | ||
|
|
5b42bc9a22 | ||
|
|
b65b2d7720 | ||
|
|
6f99f0fc26 | ||
|
|
c6f4e64c1a | ||
|
|
d963cdf5ae | ||
|
|
453dd9e49a | ||
|
|
89e0548092 | ||
|
|
cd5a5da45c | ||
|
|
d7dc36c65b | ||
|
|
87985f1f1f | ||
|
|
e53c229ac5 | ||
|
|
6a0063addd | ||
|
|
3b1845f0a0 | ||
|
|
10880cf038 | ||
|
|
289782b3a0 | ||
|
|
c3b7302dce | ||
|
|
a5800b196c | ||
|
|
28da228479 | ||
|
|
adf3d15c86 | ||
|
|
8b54a22914 | ||
|
|
2faf68c4d2 | ||
|
|
363654dfba | ||
|
|
5c481d47bb | ||
|
|
ce00d167ee | ||
|
|
fa1be60880 | ||
|
|
a28ce768bd | ||
|
|
5bf71c46dd | ||
|
|
344af018f9 | ||
|
|
8de85c3a6b | ||
|
|
014fa123b9 | ||
|
|
6bb43d4cfa | ||
|
|
acb565d46e | ||
|
|
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 |
+4
-2
@@ -1,5 +1,7 @@
|
||||
24
|
||||
25
|
||||
1.4.2
|
||||
1.6.2
|
||||
1.11.2
|
||||
1.12.21.17.2
|
||||
1.12.2
|
||||
1.17.2
|
||||
1.31.2
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('./babel.config.js');
|
||||
@@ -1,5 +0,0 @@
|
||||
.eslintrc.js
|
||||
**/build/*
|
||||
**/coverage/*
|
||||
**/node_modules/*
|
||||
docs/examples/promise/90_typegen/*
|
||||
+15
-1
@@ -1,7 +1,19 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const base = require('@polkadot/dev/config/eslint');
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
ignorePatterns: [
|
||||
'.eslintrc.js',
|
||||
'.github/**',
|
||||
'.vscode/**',
|
||||
'.yarn/**',
|
||||
'**/build/*',
|
||||
'**/coverage/*',
|
||||
'**/node_modules/*'
|
||||
],
|
||||
parserOptions: {
|
||||
...base.parserOptions,
|
||||
project: [
|
||||
@@ -13,6 +25,8 @@ module.exports = {
|
||||
// add override for any (a metric ton of them, initial conversion)
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
// these should be removed, there are 8 of them as errors
|
||||
'@typescript-eslint/no-non-null-assertion': 'off'
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
// this seems very broken atm, false positives
|
||||
'@typescript-eslint/unbound-method': 'off'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,11 +5,11 @@ jobs:
|
||||
pr:
|
||||
strategy:
|
||||
matrix:
|
||||
step: ['lint', 'test', 'build', 'docs']
|
||||
step: ['lint', 'test', 'build']
|
||||
name: ${{ matrix.step }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
- name: ${{ matrix.step }}
|
||||
run: |
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
|
||||
@@ -8,18 +8,17 @@ jobs:
|
||||
master:
|
||||
strategy:
|
||||
matrix:
|
||||
step: ['build:release', 'docs:release']
|
||||
step: ['build:release']
|
||||
name: ${{ matrix.step }}
|
||||
if: "! startsWith(github.event.head_commit.message, '[CI Skip]') && github.repository == 'polkadot-js/api'"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
token: ${{ secrets.GH_PAT }}
|
||||
- name: ${{ matrix.step }}
|
||||
env:
|
||||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||
GH_PAGES_SRC: build-docs
|
||||
GH_PAT: ${{ secrets.GH_PAT }}
|
||||
GH_RELEASE_GITHUB_API_TOKEN: ${{ secrets.GH_PAT }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
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
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
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.3.3.cjs
|
||||
|
||||
+654
-4
File diff suppressed because it is too large
Load Diff
@@ -7,13 +7,13 @@
|
||||
|
||||
# @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.
|
||||
|
||||
## tutorials
|
||||
|
||||
Looking for tutorials to get started? Look at [examples](https://polkadot.js.org/api/examples/promise/) for guides on how to use the API to make queries and submit transactions.
|
||||
Looking for tutorials to get started? Look at [examples](https://polkadot.js.org/docs/api/examples/promise/) for guides on how to use the API to make queries and submit transactions.
|
||||
|
||||
## overview
|
||||
|
||||
@@ -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 -
|
||||
|
||||
- [@polkadot/jsonrpc](packages/jsonrpc/) Definitions for JSONRPC endpoints
|
||||
- [@polkadot/types](packages/types/) Codecs for all Polkadot and Substrate primitives
|
||||
|
||||
## development
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = require('@polkadot/dev/config/babel');
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function copy_folder () {
|
||||
SRC="packages/$1/build"
|
||||
DST="../apps/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"
|
||||
@@ -1,107 +0,0 @@
|
||||
module.exports = {
|
||||
base: '/api/',
|
||||
title: 'polkadot-js/api',
|
||||
description: 'API libraries and interfaces for communicating with Polkadot and Substrate nodes',
|
||||
markdown: {
|
||||
lineNumbers: true
|
||||
},
|
||||
themeConfig: {
|
||||
displayAllHeaders: true,
|
||||
nav: [
|
||||
{ text: 'Polkadot/Substrate Apps', link: 'https://polkadot.js.org/apps/' },
|
||||
{ text: 'Project family', link: 'https://polkadot.js.org/' },
|
||||
{
|
||||
text: 'Documentation',
|
||||
items: [
|
||||
{ text: 'API Reference (this)', link: 'https://polkadot.js.org/api/' },
|
||||
{ text: 'Utility Reference', link: 'https://polkadot.js.org/common/' },
|
||||
{ text: 'UI Libs Reference', link: 'https://polkadot.js.org/ui/' },
|
||||
]
|
||||
},
|
||||
{ text: 'GitHub', link: 'https://github.com/polkadot-js/api' }
|
||||
],
|
||||
search: true,
|
||||
searchMaxSuggestions: 10,
|
||||
sidebar: [
|
||||
{
|
||||
title: 'Getting started',
|
||||
path: '/start/',
|
||||
collapsable: false,
|
||||
sidebarDepth: 0,
|
||||
children: [
|
||||
['start/install.md', 'Installation'],
|
||||
['start/basics.md', 'Basics & Metadata'],
|
||||
['start/create.md', 'Creating an instance'],
|
||||
['start/api.consts.md', 'Runtime Constants'],
|
||||
['start/api.query.md', 'State queries'],
|
||||
['start/api.rpc.md', 'RPC calls'],
|
||||
['start/api.query.subs.md', 'Query subscriptions'],
|
||||
['start/api.query.multi.md', 'Multi queries'],
|
||||
['start/api.query.other.md', 'Query extras'],
|
||||
['start/api.tx.md', 'Transactions'],
|
||||
['start/keyring.md', 'Keyring'],
|
||||
['start/api.tx.subs.md', 'Transaction subscriptions'],
|
||||
['start/api.tx.wrap.md', 'Complex transactions'],
|
||||
['start/types.basics.md', 'Type basics'],
|
||||
['start/types.extend.md', 'Extending types'],
|
||||
['start/rpc.custom.md', 'Custom RPC'],
|
||||
['start/types.create.md', 'Creating types'],
|
||||
['start/typescript.md', 'TypeScript interfaces'],
|
||||
['start/typescript.user.md', 'TypeScript user generated'],
|
||||
['start/FAQ.md', 'FAQ']
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Cookbook',
|
||||
path: '/cookbook/',
|
||||
collapsable: false,
|
||||
sidebarDepth: 0,
|
||||
children: [
|
||||
['cookbook/blocks.md', 'Blocks'],
|
||||
['cookbook/storage.md', 'Storage'],
|
||||
['cookbook/tx.md', 'Transactions']
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Examples (Promise API)',
|
||||
path: '/examples/promise/',
|
||||
collapsable: false,
|
||||
sidebarDepth: 0,
|
||||
children: [
|
||||
['examples/promise/01_simple_connect/', 'Simple connect'],
|
||||
['examples/promise/02_listen_to_blocks/', 'Listen to blocks'],
|
||||
['examples/promise/03_listen_to_balance_change/', 'Listen to balance change'],
|
||||
['examples/promise/04_unsubscribe/', 'Unsubscribe from listening'],
|
||||
['examples/promise/05_read_storage/', 'Read chain state'],
|
||||
['examples/promise/06_make_transfer/', 'Make a transfer'],
|
||||
['examples/promise/08_system_events/', 'Display system events'],
|
||||
['examples/promise/09_transfer_events/', 'Transaction with events'],
|
||||
['examples/promise/10_upgrade_chain/', 'Upgrade via sudo'],
|
||||
['examples/promise/90_typegen/', 'TypeScript augmentation']
|
||||
]
|
||||
},
|
||||
{
|
||||
title: 'Substrate defaults',
|
||||
path: '/substrate/',
|
||||
collapsable: false,
|
||||
sidebarDepth: 0,
|
||||
children: [
|
||||
['substrate/rpc.md', 'Substrate RPC'],
|
||||
['substrate/constants.md', 'Constants'],
|
||||
['substrate/storage.md', 'State storage'],
|
||||
['substrate/extrinsics.md', 'Extrinsics'],
|
||||
['substrate/events.md', 'System events'],
|
||||
['substrate/errors.md', 'Errors']
|
||||
]
|
||||
},
|
||||
['/api/', '@polkadot/api'],
|
||||
['/types/', '@polkadot/types'],
|
||||
'/CONTRIBUTING.md'
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
['@vuepress/search', {
|
||||
searchMaxSuggestions: 10
|
||||
}]
|
||||
]
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
$accentColor = #fd8824
|
||||
$textColor = #2c3e50
|
||||
$borderColor = #eaecef
|
||||
$codeBgColor = #282c34
|
||||
$arrowBgColor = #ccc
|
||||
|
||||
.home .hero .description,
|
||||
.home .feature h2,
|
||||
.home .feature p {
|
||||
color: $textColor
|
||||
opacity: 0.75
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="initial-scale=0.5, maximum-scale=1">
|
||||
<meta http-equiv="refresh" content="0;URL='https://polkadot.js.org/docs/api/'" />
|
||||
<title>Redirecting to https://polkadot.js.org/docs/api/</title>
|
||||
</head>
|
||||
<body>
|
||||
Redirecting to <a href="https://polkadot.js.org/docs/api/">https://polkadot.js.org/docs/api/</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,43 +0,0 @@
|
||||
---
|
||||
home: true
|
||||
heroText:
|
||||
tagline:
|
||||
# Bringing JavaScript to the Polkadot world.
|
||||
# actionText: Repository Overview
|
||||
# actionLink: /REPOS.md
|
||||
features:
|
||||
- title: API
|
||||
details: A powerful dynamic API that allows chain interactions with transparent encoding and decoding.
|
||||
- title: Substrate defaults
|
||||
details: An overview of the various default methods, state entries and RPCs for Substrate-based chains.
|
||||
- title: Types
|
||||
details: Various type interfaces to make using returned values from API calls transparent in your code.
|
||||
|
||||
footer: Apache-2 Licensed | Copyright © 2017-2020 polkadot-js authors and contributors
|
||||
---
|
||||
|
||||
## Welcome
|
||||
|
||||
The API provides application developers the ability to query a node and interact with the Polkadot or Substrate chains using Javascript. Here you will find documentation and examples to get you started.
|
||||
|
||||
::: tip Getting started & Examples
|
||||
[Jump right in](/start/) and get an overview on using the API in your projects, from installation all the way through to making it do magic. Have things working and want tips? The [cookbook](/cookbook/) provides some tips and tricks. Getting started and want some full examples? [The ApiPromise examples](/examples/promise/) provide some basic examples.
|
||||
:::
|
||||
|
||||
## The Polkadot Project
|
||||
|
||||
You can read more about the Polkadot Network at [https://polkadot.network/](https://polkadot.network/) and more about the polkadot-js projects at [https://polkadot.js.org](https://polkadot.js.org)
|
||||
|
||||
## Github repositories
|
||||
|
||||
You can find the Polkadot repositories at:
|
||||
|
||||
- [https://github.com/polkadot-js](https://github.com/polkadot-js)
|
||||
- [https://github.com/paritytech/polkadot](https://github.com/paritytech/polkadot)
|
||||
- [https://github.com/paritytech/substrate](https://github.com/paritytech/substrate)
|
||||
|
||||
This documentation is generated from [https://github.com/polkadot-js/api](https://github.com/polkadot-js/api)
|
||||
|
||||
## Contributing
|
||||
|
||||
Contribution to the Polkadot JS API are more than welcome. You can [report issues](https://github.com/polkadot-js/api/issues/new) and [log feature requests](https://github.com/polkadot-js/api/issues/new).
|
||||
@@ -1,62 +0,0 @@
|
||||
## Getting started
|
||||
|
||||
- [Introduction](start/README.md)
|
||||
- [Installation](start/install.md)
|
||||
- [Basics](start/basics.md)
|
||||
- [Creating](start/create.md)
|
||||
- [Constant queries](start/api.consts.md)
|
||||
- [State queries](start/api.query.md)
|
||||
- [RPC queries](start/api.rpc.md)
|
||||
- [State subscriptions](start/api.query.subs.md)
|
||||
- [Multi state retrieval](start/api.query.multi.md)
|
||||
- [State query utilities](start/api.query.other.md)
|
||||
- [Transactions](start/api.tx.md)
|
||||
- [Keyring](start/keyring.md)
|
||||
- [Transaction subscriptions](start/api.tx.subs.md)
|
||||
- [Complex transactions](start/api.tx.wrap.md)
|
||||
- [Type basics](start/types.basics.md)
|
||||
- [Type extension](start/types.extend.md)
|
||||
- [TypeScript interfaces](start/typescript.md)
|
||||
- [TypeScript user generated](start/typescript.user.md)
|
||||
|
||||
## Packages
|
||||
|
||||
- [api](api/README.md)
|
||||
- [ApiPromise](api/classes/_promise_index_.apipromise.md)
|
||||
- [ApiRx](api/classes/_rx_index_.apirx.md)
|
||||
- [rpc-provider](rpc-provider/README.md)
|
||||
- [HttpProvider](rpc-provider/classes/_http_index_.httpprovider.md)
|
||||
- [WsProvider](rpc-provider/classes/_ws_index_.wsprovider.md)
|
||||
- [types (codec implementation)](types/README.md)
|
||||
|
||||
## Interfaces
|
||||
|
||||
- [Substrate](substrate/README.md)
|
||||
- [RPC](substrate/rpc.md)
|
||||
- [Constants (runtime)](substrate/constants.md)
|
||||
- [Chain state (runtime)](substrate/storage.md)
|
||||
- [Extrinsics (runtime)](substrate/extrinsics.md)
|
||||
- [Events (runtime)](substrate/events.md)
|
||||
|
||||
## Examples
|
||||
|
||||
- [ApiPromise](examples/promise/README.md)
|
||||
- [Simple connect](examples/promise/01_simple_connect/README.md)
|
||||
- [Listen to blocks](examples/promise/02_listen_to_blocks/README.md)
|
||||
- [Listen to balance change](examples/promise/03_listen_to_balance_change/README.md)
|
||||
- [Unsubscribe from listening](examples/promise/04_unsubscribe/README.md)
|
||||
- [Read chain state](examples/promise/05_read_storage/README.md)
|
||||
- [Make a transfer](examples/promise/06_make_transfer/README.md)
|
||||
- [Display system events](examples/promise/08_system_events/README.md)
|
||||
- [Transaction with events](examples/promise/09_transfer_events/README.md)
|
||||
- [Upgrade via sudo](examples/promise/10_upgrade_chain/README.md)
|
||||
- [ApiRx](examples/rx/README.md)
|
||||
- [Simple connect](examples/rx/01_simple_connect/README.md)
|
||||
- [Listen to blocks](examples/rx/02_listen_to_blocks/README.md)
|
||||
- [Listen to balance change](examples/rx/03_listen_to_balance_change/README.md)
|
||||
- [Unsubscribe from listening](examples/rx/04_unsubscribe/README.md)
|
||||
- [Read chain state](examples/rx/05_read_storage/README.md)
|
||||
- [Make a transfer](examples/rx/06_make_transfer/README.md)
|
||||
- [Display system events](examples/rx/08_system_events/README.md)(
|
||||
- [Transaction with events](examples/rx/09_transfer_events/README.md)
|
||||
- [Upgrade via sudo](examples/rx/10_upgrade_chain/README.md)
|
||||
@@ -1,19 +0,0 @@
|
||||
# Cookbook
|
||||
|
||||
The cookbook hosts small code snippets in a question-answer format. It does not walk you through the whole setup, like the [basic examples](../examples/), but rather aims to answer some questions around specific uses. It also does not replace the [getting started FAQ](../start/FAQ.md), rather this is focussed explicitly on code samples, instead of general trouble-shooting for common mishaps.
|
||||
|
||||
These questions are added as they do come up and the hope is that the snippets here is will be useful to others, instead of just the original person who asked on a specific use-case. As of today, it is only making a start and not fully comprehensive yet - check back early, check back often.
|
||||
|
||||
## Sections
|
||||
|
||||
The following cookbook sections are available -
|
||||
|
||||
- [Blocks](blocks.md) - Snippets around working with blocks and headers
|
||||
- [Storage](storage.md) - Snippets for working with storage
|
||||
- [Transactions](tx.md) - Snippets for working with transactions
|
||||
|
||||
... more to come.
|
||||
|
||||
## Contribute
|
||||
|
||||
And as always, if you have an addition to make, or a question to ask any [any PRs](https://github.com/polkadot-js/api/tree/master/docs) or [issues](https://github.com/polkadot-js/api/issues) are appreciated. The initial content was generate from exactly such questions, either in Riot chat or as submitted as issues.
|
||||
@@ -1,44 +0,0 @@
|
||||
# Blocks
|
||||
|
||||
The building blocks for each blockchain. As such there are a number of examples for working with blocks and headers, that could be useful.
|
||||
|
||||
## How do I retrieve the header/extrinsic hash from blocks?
|
||||
|
||||
A block hash refers to the hash over the header, the extrinsic hash refers to the hash of the encoded extrinsic. Since all objects returned by the API implements the `.hash => Hash` getter, we can simply use this to view the actual hash.
|
||||
|
||||
```js
|
||||
// returns Hash
|
||||
const blockHash = await this.api.rpc.chain.getBlockHash(blockNumber);
|
||||
// returns SignedBlock
|
||||
const signedBlock = await this.api.rpc.chain.getBlock(blockHash);
|
||||
|
||||
// the hash for the block, always via header (Hash -> toHex()) - will be
|
||||
// the same as blockHash above (also available on any header retrieved,
|
||||
// subscription or once-off)
|
||||
console.log(signedBlock.header.hash.toHex());
|
||||
|
||||
// the hash for each extrinsic in the block
|
||||
signedBlock.block.extrinsics.forEach((ex, index) => {
|
||||
console.log(index, ex.hash.toHex());
|
||||
});
|
||||
```
|
||||
|
||||
## How do I extract the block author?
|
||||
|
||||
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
|
||||
// subscribe to all new headers (with extended info)
|
||||
api.derive.chain.subscribeNewHeads((header) => {
|
||||
console.log(`#${header.number}: ${header.author}`);
|
||||
});
|
||||
```
|
||||
|
||||
For a single header only, the derives also contain a `getHeader`, which once again returns a header extended with the author -
|
||||
|
||||
```js
|
||||
// retrieve the last header (hash optional)
|
||||
const header = await api.derive.chain.getHeader();
|
||||
|
||||
console.log(`#${header.number}: ${header.author}`);
|
||||
```
|
||||
@@ -1,55 +0,0 @@
|
||||
# Storage
|
||||
|
||||
Here you will find snippets for working with storage.
|
||||
|
||||
## How do I check for storage existence?
|
||||
|
||||
In the metadata, for each storage item a fallback is provided. This means that when an entry does not exist, the fallback (which is the default value for the type) will be provided. This means, that querying for a non-existent key (unless an option), will yield a value -
|
||||
|
||||
```js
|
||||
// retrieve Option<StakingLedger>
|
||||
const ledger = await api.query.staking.ledger('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
|
||||
// retrieve ValidatorPrefs (will yield the default value)
|
||||
const prefs = await api.query.staking.validators('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
|
||||
|
||||
console.log(ledger.isNone, ledger.isSome); // true, false
|
||||
console.log(JSON.stringify(prefs.toHuman())); // {"commission":"0"}
|
||||
```
|
||||
|
||||
In the second case, the non-existent prefs returns the default/fallback value for the storage item. So in this case we don't know if the value is set to 0 or unset. Existence can be checked by using the storage size, which would be zero if nothing is stored.
|
||||
|
||||
```js
|
||||
// exists
|
||||
const sizeY = await api.query.staking.validators.size('DB2mp5nNhbFN86J9hxoAog8JALMhDXgwvWMxrRMLNUFMEY4');
|
||||
// non existent
|
||||
const sizeN = await api.query.staking.validators.size('EoukLS2Rzh6dZvMQSkqFy4zGvqeo14ron28Ue3yopVc8e3Q');
|
||||
|
||||
console.log(sizeY.isZero(), sizeY.toNumber()); // false 4
|
||||
console.log(sizeN.isZero(), sizeY.toNumber()); // true 0
|
||||
```
|
||||
|
||||
## How do I use .entries()/.keys() on double maps?
|
||||
|
||||
As [explained elsewhere](../start/api.query.other.md#map-keys-entries) each map-type storage entry exposes the entries/keys helpers to retrieve the whole list. In the case of double maps, with the addition of a single argument, you can retrieve either all entries or a subset based on the first map key.
|
||||
|
||||
In both these cases, entries/keys operate the same way, `.entries()` retrieving `(StorageKey, Codec)[]` and `.keys()` retrieving `StorageKey[]`
|
||||
|
||||
```js
|
||||
// Retrieves the entries for all slashes, in all eras (no arg)
|
||||
const allEntries = await api.query.staking.nominatorSlashInEra.entries();
|
||||
|
||||
// nominatorSlashInEra(EraIndex, AccountId) for the types of the key args
|
||||
allEntries.forEach(([{ args: [era, nominatorId] }, value]) => {
|
||||
console.log(`${era}: ${nominatorId} slashed ${value.toHuman()}`);
|
||||
});
|
||||
```
|
||||
|
||||
While we can retrieve only the keys for a specific era, using a argument for the first part of the doublemap (as defined here, an `EraIndex`) -
|
||||
|
||||
```js
|
||||
// Retrieves the keys for the slashed validators in era 652
|
||||
const slashedKeys = await api.query.staking.nominatorSlashInEra.keys(652);
|
||||
|
||||
// key args still contains [EraIndex, AccountId] decoded
|
||||
console.log(`slashed: ${slashedKeys.map(({ args: [era, nominatorId] }) => nominatorId)`);
|
||||
```
|
||||
@@ -1,112 +0,0 @@
|
||||
# Transactions
|
||||
|
||||
A blockchain is no fun if you are not submitting transactions. Or at least if somebody is not submitting any. Here you will find some snippets for dealing with some common issues.
|
||||
|
||||
## How do I estimate the transaction fees?
|
||||
|
||||
In addition to the `signAndSend` helper on transactions, `.paymentInfo` (with the exact same parameters) are also exposed. Using the same sender, it applies a dummy signature to the transaction and then gets the fee estimation via RPC.
|
||||
|
||||
```js
|
||||
// estimate the fees as RuntimeDispatchInfo, using the signer (either
|
||||
// address or locked/unlocked keypair) (When overrides are applied, e.g
|
||||
// nonce, the format would be `paymentInfo(sender, { nonce })`)
|
||||
const info = await api.tx.balances
|
||||
.transfer(recipient, 123)
|
||||
.paymentInfo(sender);
|
||||
|
||||
// log relevant info, partialFee is Balance, estimated for current
|
||||
console.log(`
|
||||
class=${class.toString()},
|
||||
weight=${weight.toString()},
|
||||
partialFee=${partialFee.toHuman()}
|
||||
`);
|
||||
```
|
||||
|
||||
## How do I get the decoded enum for an ExtrinsicFailed event?
|
||||
|
||||
Assuming you are sending a tx via `.signAndSend`, the callback yields information around the tx pool status as well as any events when `isInBlock` or `isFinalized`. If an extrinsic fails via `system.ExtrinsicFailed` event, you can retrieve the error, if defined as an enum on a module.
|
||||
|
||||
```js
|
||||
api.tx.balances
|
||||
.transfer(recipient, 123)
|
||||
.signAndSend(sender, ({ status, events }) => {
|
||||
if (status.isInBlock || status.isFinalized) {
|
||||
events
|
||||
// find/filter for failed events
|
||||
.filter(({ section, method }) =>
|
||||
section === 'system' &&
|
||||
method === 'ExtrinsicFailed'
|
||||
)
|
||||
// we know that data for system.ExtrinsicFailed is
|
||||
// (DispatchError, DispatchInfo)
|
||||
.forEach(({ data: [error, info] }) => {
|
||||
if (error.isModule) {
|
||||
// for module errors, we have the section indexed, lookup
|
||||
const decoded = api.registry.findMetaError(error.asModule);
|
||||
const { documentation, method, section } = decoded;
|
||||
|
||||
console.log(`${section}.${method}: ${documentation.join(' ')}`);
|
||||
} else {
|
||||
// Other, CannotLookup, BadOrigin, no extra info
|
||||
console.log(error.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## How do I send an unsigned extrinsic?
|
||||
|
||||
For most runtime modules, transactions need to be signed and validation for this happens node-side. There are however modules that accepts unsigned extrinsics, an example would be the Polkadot/Kusama token claims (which is here used as an example).
|
||||
|
||||
```js
|
||||
// construct the transaction, exactly as per normal
|
||||
const utx = api.tx.claims.claim(beneficiary, ethSignature);
|
||||
|
||||
// send it without calling sign, pass callback with status/events
|
||||
tx.send(({ status }) => {
|
||||
if (status.isInBlock) {
|
||||
console.log(`included in ${status.asInBlock}`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The signing is indicated by the first byte in the transaction, so in this case we have called `.send` on it (no `.sign` or `.signAndSend`), so it will be sent using the unsigned state, without signature attached.
|
||||
|
||||
## How can I batch transactions?
|
||||
|
||||
Polkadot/Substrate provides a `utility.batch` method that can be used to send a number of transactions at once. These are then executed from a single sender (single nonce specified) in sequence. This is very useful in a number of cases, for instance if you wish to create a payout for a validator for multiple eras, you can use this method. Likewise, you can send a number of transfers at once. Or even batch different types of transactions.
|
||||
|
||||
```js
|
||||
// construct a list of transactions we want to batch
|
||||
const txs = [
|
||||
api.tx.balances.transfer(addrBob, 12345),
|
||||
api.tx.balances.transfer(addrEve, 12345),
|
||||
api.tx.staking.unbond(12345)
|
||||
];
|
||||
|
||||
// construct the batch and send the transactions
|
||||
api.tx.utility
|
||||
.batch(txs)
|
||||
.signAndSend(sender, ({ status }) => {
|
||||
if (status.isInBlock) {
|
||||
console.log(`included in ${status.asInBlock}`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## How do I take the pending tx pool into account in my nonce?
|
||||
|
||||
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signandSend` operation, we can override the nonce, either by manually incrementing it o querying it via `nextNonce`.
|
||||
|
||||
```js
|
||||
for (let i = 0; i < 10; i++) {
|
||||
// retrieve the nextNonce, taking txs in the pool into account
|
||||
const nonce = await api.rpc.account.nextNonce(sender);
|
||||
|
||||
// send, just retrieving the hash, not waiting on status
|
||||
const txhash = await api.tx.balances
|
||||
.transfer(recipient, 123)
|
||||
.signAndSend(sender, { nonce });
|
||||
}
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
yarn.lock
|
||||
@@ -1,5 +0,0 @@
|
||||
# Simple Connect
|
||||
|
||||
The following example shows how to instantiate a Polkadot API object and use it to connect to a node using ApiPromise.
|
||||
|
||||
<<< @/docs/examples/promise/01_simple_connect/index.js
|
||||
@@ -1,25 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Required imports
|
||||
const { ApiPromise, WsProvider } = require('@polkadot/api');
|
||||
|
||||
async function main () {
|
||||
// Initialise the provider to connect to the local node
|
||||
const provider = new WsProvider('ws://127.0.0.1:9944');
|
||||
|
||||
// Create the API and wait until ready
|
||||
const api = await ApiPromise.create({ provider });
|
||||
|
||||
// Retrieve the chain & node information information via rpc calls
|
||||
const [chain, nodeName, nodeVersion] = await Promise.all([
|
||||
api.rpc.system.chain(),
|
||||
api.rpc.system.name(),
|
||||
api.rpc.system.version()
|
||||
]);
|
||||
|
||||
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "01_simple_connect",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to connect using a WebSocket",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
# Listen to new blocks
|
||||
This example shows how to subscribe to new blocks.
|
||||
|
||||
It displays the block number every time a new block is seen by the node you are connected to.
|
||||
|
||||
NOTE: The example runs until you stop it with CTRL+C
|
||||
|
||||
<<< @/docs/examples/promise/02_listen_to_blocks/index.js
|
||||
@@ -1,30 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
async function main () {
|
||||
// Here we don't pass the (optional) provider, connecting directly to the default
|
||||
// node/port, i.e. `ws://127.0.0.1:9944`. Await for the isReady promise to ensure
|
||||
// the API has connected to the node and completed the initialisation process
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// We only display a couple, then unsubscribe
|
||||
let count = 0;
|
||||
|
||||
// Subscribe to the new headers on-chain. The callback is fired when new headers
|
||||
// are found, the call itself returns a promise with a subscription that can be
|
||||
// used to unsubscribe from the newHead subscription
|
||||
const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {
|
||||
console.log(`Chain is at block: #${header.number}`);
|
||||
|
||||
if (++count === 256) {
|
||||
unsubscribe();
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "02_listen_to_blocks",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to use subscriptions",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Listen to balance changes
|
||||
|
||||
This example shows how to instantiate a Polkadot API object and use it to connect to a node and retrieve balance updates.
|
||||
|
||||
<<< @/docs/examples/promise/03_listen_to_balance_change/index.js
|
||||
@@ -1,39 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
// Known account we want to use (available on dev chain, with funds)
|
||||
const Alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
async function main () {
|
||||
// Create an await for the API
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Retrieve the initial balance. Since the call has no callback, it is simply a promise
|
||||
// that resolves to the current on-chain value
|
||||
let { data: { free: previousFree }, nonce: previousNonce } = await api.query.system.account(Alice);
|
||||
|
||||
console.log(`${Alice} has a balance of ${previousFree}, nonce ${previousNonce}`);
|
||||
console.log(`You may leave this example running and start example 06 or transfer any value to ${Alice}`);
|
||||
|
||||
// Here we subscribe to any balance changes and update the on-screen value
|
||||
api.query.system.account(Alice, ({ data: { free: currentFree }, nonce: currentNonce }) => {
|
||||
// Calculate the delta
|
||||
const change = currentFree.sub(previousFree);
|
||||
|
||||
// Only display positive value changes (Since we are pulling `previous` above already,
|
||||
// the initial balance change will also be zero)
|
||||
if (!change.isZero()) {
|
||||
console.log(`New balance change of ${change}, nonce ${currentNonce}`);
|
||||
|
||||
previousFree = currentFree;
|
||||
previousNonce = currentNonce;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "03_listen_to_balance_change",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to subscribe to balance change",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Listen to balance changes
|
||||
|
||||
This example shows how to instantiate a Polkadot API object and use it to connect to a node and retrieve balance updates.
|
||||
|
||||
<<< @/docs/examples/promise/03_listen_to_balance_change/index.js
|
||||
@@ -1,25 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
// Known account we want to use (available on dev chain, with funds)
|
||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
|
||||
|
||||
async function main () {
|
||||
// Create an await for the API
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
console.log('Tracking balances for:', [ALICE, BOB]);
|
||||
|
||||
// Subscribe and listen to several balance changes
|
||||
api.query.system.account.multi([ALICE, BOB], (balances) => {
|
||||
console.log('Change detected, new balances: ', balances.map(({ data: { free } }) => free));
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "03_listen_to_multiple_balances_change",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to subscribe to multiple balances change",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
# Unsubscribe from listening to updates
|
||||
|
||||
This example shows how to subscribe to and later unsubscribe from listening to block updates.
|
||||
|
||||
In this example we're calling the built-in unsubscribe() function after a timeOut of 20s to cleanup and unsubscribe from listening to updates.
|
||||
|
||||
<<< @/docs/examples/promise/04_unsubscribe/index.js
|
||||
@@ -1,25 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
async function main () {
|
||||
// Create a new instance of the api
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Subscribe to chain updates and log the current block number on update.
|
||||
const unsubscribe = await api.rpc.chain.subscribeNewHeads((header) => {
|
||||
console.log(`Chain is at block: #${header.number}`);
|
||||
});
|
||||
|
||||
// In this example we're calling the unsubscribe() function that is being
|
||||
// returned by the api call function after 20s.
|
||||
setTimeout(() => {
|
||||
unsubscribe();
|
||||
console.log('Unsubscribed');
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "04_unsubscribe",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to unsubscribe from a subscription",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Read storage
|
||||
|
||||
Many important variables are available through the storage API. This example shows how to call a few of those APIs.
|
||||
|
||||
<<< @/docs/examples/promise/05_read_storage/index.js
|
||||
@@ -1,42 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
// Our address for Alice on the dev chain
|
||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
async function main () {
|
||||
// Create our API with a default connection to the local node
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Make our basic chain state/storage queries, all in one go
|
||||
const [{ nonce: accountNonce }, now, validators] = await Promise.all([
|
||||
api.query.system.account(ALICE),
|
||||
api.query.timestamp.now(),
|
||||
api.query.session.validators()
|
||||
]);
|
||||
|
||||
console.log(`accountNonce(${ALICE}) ${accountNonce}`);
|
||||
console.log(`last block timestamp ${now.toNumber()}`);
|
||||
|
||||
if (validators && validators.length > 0) {
|
||||
// Retrieve the balances for all validators
|
||||
const validatorBalances = await Promise.all(
|
||||
validators.map((authorityId) =>
|
||||
api.query.system.account(authorityId)
|
||||
)
|
||||
);
|
||||
|
||||
// Print out the authorityIds and balances of all validators
|
||||
console.log('validators', validators.map((authorityId, index) => ({
|
||||
address: authorityId.toString(),
|
||||
balance: validatorBalances[index].data.free.toHuman(),
|
||||
nonce: validatorBalances[index].nonce.toHuman()
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "05_read_storage",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to query storage",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Read storage, at a specific blockhash
|
||||
|
||||
In addition to querying the latest storage, you can make storage queries at a specific blockhash. Be aware that the node applies a pruning strategy and typically only keeps the last 256 blocks, unless run in archive mode.
|
||||
|
||||
<<< @/docs/examples/promise/05_read_storage_at/index.js
|
||||
@@ -1,33 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
// Our address for Alice on the dev chain
|
||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
|
||||
|
||||
async function main () {
|
||||
// Create our API with a default connection to the local node
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Retrieve the last block header, extracting the hash and parentHash
|
||||
const { hash, parentHash } = await api.rpc.chain.getHeader();
|
||||
|
||||
console.log(`last header hash ${hash.toHex()}`);
|
||||
|
||||
// Retrieve the balance at the preceding block for Alice. For at queries
|
||||
// the format is always `.at(<blockhash>, ...params)`
|
||||
const balance = await api.query.system.account.at(parentHash, ALICE);
|
||||
|
||||
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance.data.free}`);
|
||||
|
||||
// Now perform a multi query, returning multiple balances at once
|
||||
const balances = await api.query.system.account.multi([ALICE, BOB]);
|
||||
|
||||
console.log(`Current balances for Alice and Bob are ${balances[0].data.free} and ${balances[1].data.free}`);
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "05_read_storage_at",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to query storage at a specific block",
|
||||
"main": "index.js",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Make a simple transfer
|
||||
|
||||
This sample shows how to create a transaction to make a transfer from one an account to another.
|
||||
|
||||
<<< @/docs/examples/promise/06_make_transfer/index.js
|
||||
@@ -1,30 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API, Keyring and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
const { Keyring } = require('@polkadot/keyring');
|
||||
|
||||
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
|
||||
|
||||
async function main () {
|
||||
// Instantiate the API
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Constuct the keying after the API (crypto has an async init)
|
||||
const keyring = new Keyring({ type: 'sr25519' });
|
||||
|
||||
// Add Alice to our keyring with a hard-deived path (empty phrase, so uses dev)
|
||||
const alice = keyring.addFromUri('//Alice');
|
||||
|
||||
// Create a extrinsic, transferring 12345 units to Bob
|
||||
const transfer = api.tx.balances.transfer(BOB, 12345);
|
||||
|
||||
// Sign and send the transaction using our account
|
||||
const hash = await transfer.signAndSend(alice);
|
||||
|
||||
console.log('Transfer sent with hash', hash.toHex());
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "06_make_transfer",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to make a transfer",
|
||||
"main": "index.js",
|
||||
"author": "chevdor",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Make a Transfer with allowed block permissions
|
||||
|
||||
This transactions shows you how to add a nonce and a valid length of blocks a transaction is valid for.
|
||||
|
||||
This is important because as an account drops below the exsistential limit (0.1 dots) it gets pruned from the state tree. If it is added back its nonce starts at 0 again and is now vulnerable to replay attacks.
|
||||
@@ -1,46 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API, Keyring and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
const { Keyring } = require('@polkadot/keyring');
|
||||
const { createType } = require('@polkadot/types');
|
||||
|
||||
const BOB = '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty';
|
||||
|
||||
async function main () {
|
||||
// Instantiate the API
|
||||
const api = await ApiPromise.create(); // default provider
|
||||
|
||||
// Constuct the keying after the API (crypto has an async init)
|
||||
const keyring = new Keyring({ type: 'sr25519' });
|
||||
|
||||
// Add Alice to our keyring with a hard-derived path (empty phrase, so uses dev)
|
||||
const alice = keyring.addFromUri('//Alice');
|
||||
|
||||
// Get nonce for account
|
||||
const { nonce } = await api.query.system.account(alice.address);
|
||||
|
||||
// Get current block
|
||||
const signedBlock = await api.rpc.chain.getBlock();
|
||||
|
||||
// Get current block height and hash
|
||||
const currentHeight = signedBlock.block.header.number;
|
||||
const blockHash = signedBlock.block.header.hash;
|
||||
|
||||
// NOTE By default the API will send mortal transactions, only explicitly construct
|
||||
// if you wish to override the defaults
|
||||
// construct a mortal era
|
||||
const era = createType('ExtrinsicEra', { current: currentHeight, period: 10 });
|
||||
|
||||
// Create an extrinsic, transferring 12345 units to Bob
|
||||
const transfer = api.tx.balances.transfer(BOB, 12345);
|
||||
|
||||
// Sign and send the transaction using our account with a nonce and the length of blocks the transaction is valid for
|
||||
const hash = await transfer.signAndSend(alice, { blockHash, era, nonce });
|
||||
|
||||
console.log('Transfer sent with hash', hash.toHex());
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "07_make_transfer_with_allowed_block_permissions_only",
|
||||
"version": "0.1.0",
|
||||
"description": "Example showing how to make a transfer with allowed block permissions",
|
||||
"main": "index.js",
|
||||
"author": "Jesse",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Traverse events
|
||||
|
||||
Query the system events and extract information from them. This example runs until exited via Ctrl-C
|
||||
|
||||
<<< @/docs/examples/promise/08_system_events/index.js
|
||||
@@ -1,38 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
|
||||
// Import the API
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
async function main () {
|
||||
// Create our API with a default connection to the local node
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Subscribe to system events via storage
|
||||
api.query.system.events((events) => {
|
||||
console.log(`\nReceived ${events.length} events:`);
|
||||
|
||||
// Loop through the Vec<EventRecord>
|
||||
events.forEach((record) => {
|
||||
// Extract the phase, event and the event types
|
||||
const { event, phase } = record;
|
||||
const types = event.typeDef;
|
||||
|
||||
// Show what we are busy with
|
||||
console.log(`\t${event.section}:${event.method}:: (phase=${phase.toString()})`);
|
||||
console.log(`\t\t${event.meta.documentation.toString()}`);
|
||||
|
||||
// Loop through each of the parameters, displaying the type and data
|
||||
event.data.forEach((data, index) => {
|
||||
console.log(`\t\t\t${types[index].type}: ${data.toString()}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "08_system_events",
|
||||
"version": "0.1.0",
|
||||
"description": "Example showing how to query and parse events",
|
||||
"main": "index.js",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Transfer events
|
||||
|
||||
Display the events that occur during a transfer by sending a value to a random account
|
||||
|
||||
<<< @/docs/examples/promise/09_transfer_events/index.js
|
||||
@@ -1,60 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
|
||||
// Import the API & Provider and some utility functions
|
||||
const { ApiPromise } = require('@polkadot/api');
|
||||
|
||||
// Import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
|
||||
const testKeyring = require('@polkadot/keyring/testing');
|
||||
|
||||
// Utility function for random values
|
||||
const { randomAsU8a } = require('@polkadot/util-crypto');
|
||||
|
||||
// Some constants we are using in this sample
|
||||
const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
const AMOUNT = 10000;
|
||||
|
||||
async function main () {
|
||||
// Create the API and wait until ready
|
||||
const api = await ApiPromise.create();
|
||||
|
||||
// Create an instance of our testing keyring
|
||||
// If you're using ES6 module imports instead of require, just change this line to:
|
||||
// const keyring = testKeyring();
|
||||
const keyring = testKeyring.default();
|
||||
|
||||
// Get the nonce for the admin key
|
||||
const { nonce } = await api.query.system.account(ALICE);
|
||||
|
||||
// Find the actual keypair in the keyring
|
||||
const alicePair = keyring.getPair(ALICE);
|
||||
|
||||
// Create a new random recipient
|
||||
const recipient = keyring.addFromSeed(randomAsU8a(32)).address;
|
||||
|
||||
console.log('Sending', AMOUNT, 'from', alicePair.address, 'to', recipient, 'with nonce', nonce.toString());
|
||||
|
||||
// Do the transfer and track the actual status
|
||||
api.tx.balances
|
||||
.transfer(recipient, AMOUNT)
|
||||
.signAndSend(alicePair, { nonce }, ({ events = [], status }) => {
|
||||
console.log('Transaction status:', status.type);
|
||||
|
||||
if (status.isInBlock) {
|
||||
console.log('Included at block hash', status.asInBlock.toHex());
|
||||
console.log('Events:');
|
||||
|
||||
events.forEach(({ event: { data, method, section }, phase }) => {
|
||||
console.log('\t', phase.toString(), `: ${section}.${method}`, data.toString());
|
||||
});
|
||||
} else if (status.isFinalized) {
|
||||
console.log('Finalized block hash', status.asFinalized.toHex());
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "09_transfer_events",
|
||||
"version": "0.1.0",
|
||||
"description": "Example showing how to transfer DOTs (with events)",
|
||||
"main": "index.js",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Chain upgrade
|
||||
|
||||
Performs a chain upgrade using the `sudo` module. This may brick your chain, so use it as an educational sample. (use `substrate purge-chain --dev` to remove DB and recover).
|
||||
|
||||
<<< @/docs/examples/promise/10_upgrade_chain/index.js
|
||||
@@ -1,62 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
|
||||
// Import the API & Provider and some utility functions
|
||||
const { ApiPromise, WsProvider } = require('@polkadot/api');
|
||||
|
||||
// import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
|
||||
const testKeyring = require('@polkadot/keyring/testing');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
async function main () {
|
||||
// Initialise the provider to connect to the local node
|
||||
const provider = new WsProvider('ws://127.0.0.1:9944');
|
||||
|
||||
// Create the API and wait until ready (optional provider passed through)
|
||||
const api = await ApiPromise.create({ provider });
|
||||
|
||||
// Retrieve the upgrade key from the chain state
|
||||
const adminId = await api.query.sudo.key();
|
||||
|
||||
// Find the actual keypair in the keyring (if this is a changed value, the key
|
||||
// needs to be added to the keyring before - this assumes we have defaults, i.e.
|
||||
// Alice as the key - and this already exists on the test keyring)
|
||||
const keyring = testKeyring.default();
|
||||
const adminPair = keyring.getPair(adminId.toString());
|
||||
|
||||
// Retrieve the runtime to upgrade
|
||||
const code = fs.readFileSync('./test.wasm').toString('hex');
|
||||
const proposal = api.tx.system && api.tx.system.setCode
|
||||
? api.tx.system.setCode(`0x${code}`) // For newer versions of Substrate
|
||||
: api.tx.consensus.setCode(`0x${code}`); // For previous versions
|
||||
|
||||
console.log(`Upgrading from ${adminId}, ${code.length / 2} bytes`);
|
||||
|
||||
// Perform the actual chain upgrade via the sudo module
|
||||
api.tx.sudo
|
||||
.sudo(proposal)
|
||||
.signAndSend(adminPair, ({ events = [], status }) => {
|
||||
console.log('Proposal status:', status.type);
|
||||
|
||||
if (status.isInBlock) {
|
||||
console.error('You have just upgraded your chain');
|
||||
|
||||
console.log('Included at block hash', status.asInBlock.toHex());
|
||||
console.log('Events:');
|
||||
|
||||
console.log(JSON.stringify(events.toHuman(), null, 2));
|
||||
} else if (status.isFinalized) {
|
||||
console.log('Finalized block hash', status.asFinalized.toHex());
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "10_upgrade_chain",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to upgrade via upgradeKey",
|
||||
"main": "index.js",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,248 +0,0 @@
|
||||
# typegen
|
||||
|
||||
This is a sample TypeScript project [with full source & config on GithHub](https://github.com/polkadot-js/api/tree/master/docs/examples/promise/90_typegen), that uses `@polkadot/typegen` to generate type definitions that can be used to decorate the `@polkadot/api`. It uses both types defined for the specific chain as well as the chain metadata to generate TypeScript interfaces. This means that interfaces such as `api.query.*`, `api.tx.*` and `api.consts.*` will be decorated based on chain-specific information, instead of an un-augmented catch-all definition.
|
||||
|
||||
**NOTE** This is built using the updates in the `1.4.0` api track and as such it uses the latest (at the time of writing) `@polkadot/api 1.4.0`. If you want to play on your own, it is also suggested that you use the `1.4+` series since some generation types have moved around internally, making it easier to augment.
|
||||
|
||||
## Packages
|
||||
|
||||
For the packages we need from the `@polkadot/*` we have added `@polkadot/api` (we want to do API stuff) and `@polkadot/typegen` (to generate the actual interfaces). So our scripts and dependencies inside `package.json` contain the following -
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"build": "yarn generate:defs && yarn generate:meta",
|
||||
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
|
||||
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces",
|
||||
"lint": "tsc --noEmit --pretty"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/typegen": "^1.4.0",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.8.2"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We will delve into the setup and running the scripts and what they do in a short bit, but as of now just notice that we are running the scripts via `ts-node`. Since we supply our definitions as `*.ts` files, this is important otherwise they will not be parsable. `build` will just run both the types and meta generators (in that order, so metadata can use the types) and we have a `lint` that can just check that everything is as it is meant to be.
|
||||
|
||||
## Metadata setup
|
||||
|
||||
The idea here is to use the actual chain metadata to generate the actual api augmented endpoints. The metadata we are adding here (in addition to the user types), is from the Edgeware Berlin testnet. So this is a real-world example of configuring the API for a specific substrate chain. For the metadata retrieval, we just ran a simple curl command to get it from the node -
|
||||
|
||||
`curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933`
|
||||
|
||||
And then add the full JSONPC output as received to the `edgeware.json` file as specified by the generation command. A trimmed version would look like -
|
||||
|
||||
```json
|
||||
{"jsonrpc":"2.0","result":"0x6d6574610b6c185379737....","id":29}
|
||||
```
|
||||
|
||||
The generator can also use a `wss://` as an `--endpoint` param as part of the generation, but in most cases you would want a static metadata to work from in development, hence we are actually adding it here.
|
||||
|
||||
## Types setup
|
||||
|
||||
The types are defined in the `src/interfaces` folder. While this repo contains a number of generated files in there as well, you basically only need to manually add the following -
|
||||
|
||||
- `src/interfaces/definitions.ts` - this just exports all the sub-folder definitions in one go
|
||||
- `src/interfaces/<module>/definitions.ts` - type definitions for a specific module
|
||||
|
||||
This structure fully matches what is available in the `@polkadot/type/interfaces` folder, so the structure is setup based on the convention used in the `@polkadot/types` library. The generating scripts will expect something matching this since the same underlying code is actually used inside `@polkadot/types` as well. The top-level `interfaces/` folder can be name anything, however the internal content structure need to match what is defined above.
|
||||
|
||||
For the top-level the definition file has the following contents -
|
||||
|
||||
```js
|
||||
export { default as signaling } from './signaling/definitions';
|
||||
export { default as treasuryRewards } from './treasuryRewards/definitions';
|
||||
export { default as voting } from './voting/definitions';
|
||||
```
|
||||
|
||||
As explained above, it really is just a re-export of the definitions, so they are all easily accessible to the outside, i.e. we will use this import inside our own code to use the definitions in API initialization. The generation scripts will load this file to determine which types it needs to import. By the `@polkadot/types` convention, match the export names with the folders (preferably your runtime module names), the generation scripts will use these names to find the correct folders to output the generated `types.ts` to.
|
||||
|
||||
For each of the folders, `signaling`, `treasuryRewards` and `voting` another `definitions.ts` file is contained within. Looking at the one from `signaling`, it contains this -
|
||||
|
||||
```js
|
||||
export default {
|
||||
types: {
|
||||
ProposalRecord: {
|
||||
index: 'u32',
|
||||
author: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
transition_time: 'u32',
|
||||
title: 'Text',
|
||||
contents: 'Text',
|
||||
vote_id: 'u64'
|
||||
},
|
||||
ProposalContents: 'Vec<u8>',
|
||||
ProposalTitle: 'Vec<u8>'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Just the type definitions (the structure of which you should be familiar with), nested inside a `types: {...}` container. This allows us future extension points, i.e. there is some work to expose the custom RPC types alongside, so that would become another key on a per-module basis.
|
||||
|
||||
In the above, you will note that the `ProposalRecord` references a type for `voting`, i.e. `VoteStage`. The type generation and resolution will determine where the type comes from, and provide the required imports on generation.
|
||||
|
||||
Looking at the example in this repo, it also has `augment*`, `index.ts` and `types.ts` files in the interfaces folder. These are all generated, and will be re-generated when the generator is run - so all edits to these files will be lost. The only requirement for user-edits are the `definitions.ts` files.
|
||||
|
||||
## Generating
|
||||
|
||||
Now that both the metadata nd types setup is completed, we just run the build command via `yarn build` and magically (assuming you didn't have the `augment*` and other generated files), these files will be added. When running this command, the console should display something like -
|
||||
|
||||
```
|
||||
> yarn build
|
||||
$ yarn generate:defs && yarn generate:meta
|
||||
$ ts-node --skip-project \
|
||||
node_modules/.bin/polkadot-types-from-defs \
|
||||
--package sample-polkadotjs-typegen/interfaces \
|
||||
--input ./src/interfaces
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/types.ts
|
||||
Generating
|
||||
Extracting interfaces for signaling
|
||||
...
|
||||
Writing
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/augment-types.ts
|
||||
Generating
|
||||
Writing
|
||||
|
||||
$ ts-node --skip-project \
|
||||
node_modules/.bin/polkadot-types-from-chain \
|
||||
--package sample-polkadotjs-typegen/interfaces \
|
||||
--endpoint ./edgeware.json \
|
||||
--output ./src/interfaces
|
||||
|
||||
Generating from metadata, 81,267 bytes
|
||||
...
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/augment-api.ts
|
||||
Generating
|
||||
Writing
|
||||
|
||||
✨ Done in 4.04s.
|
||||
```
|
||||
|
||||
Now if we check the actual output against the source via `yarn lint`, we would see that valid output has been generated -
|
||||
|
||||
```
|
||||
> yarn lint
|
||||
$ tsc --noEmit --pretty
|
||||
✨ Done in 2.28s.
|
||||
```
|
||||
|
||||
## Peering at the output
|
||||
|
||||
We are ready to use all these generated types this after some TS config. If you take a look at the generated `src/signaling/types.ts`, you would see generated TS interfaces, such as -
|
||||
|
||||
```js
|
||||
import { Struct } from '@polkadot/types/codec';
|
||||
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
|
||||
/** @name ProposalContents */
|
||||
export interface ProposalContents extends Bytes {}
|
||||
|
||||
/** @name ProposalRecord */
|
||||
export interface ProposalRecord extends Struct {
|
||||
readonly index: u32;
|
||||
readonly author: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly transition_time: u32;
|
||||
readonly title: Text;
|
||||
readonly contents: Text;
|
||||
readonly vote_id: u64;
|
||||
}
|
||||
|
||||
/** @name ProposalTitle */
|
||||
export interface ProposalTitle extends Bytes {}
|
||||
```
|
||||
|
||||
As mentioned earlier, here you will notice the `import { VoteStage }`, the generator has determined that `voting` exports that interface and has added the required imports.
|
||||
|
||||
## TypeScript config
|
||||
|
||||
Now that we have files generated, it is time to make TypeScript aware of the types and add an explicit override into out `tsconfig.json`. After some changes, the paths in the config looks as follow (comments are in teh actual config file here) -
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"sample-polkadotjs-typegen/*": ["src/*"],
|
||||
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
|
||||
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Effectively what we do above is tell the TypeScript compiler to not use the built-in API augmentation, but rather to replace it with our version. This means that all types from these are injected not by the substrate-latest-master version, but rather with what we have defined above.
|
||||
|
||||
## Usage
|
||||
|
||||
For simple usage, we have added the `src/index.ts` file that show how the metadata and types actually decorate the API. In addition, we also have setup instructions included here.
|
||||
|
||||
```js
|
||||
// We need to import the augmented definitions "somewhere" in our project, however since we have
|
||||
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
|
||||
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
|
||||
import './interfaces/augment-api';
|
||||
import './interfaces/augment-types';
|
||||
|
||||
// all type stuff, the only one we are using here
|
||||
import type { VoteRecord } from './interfaces';
|
||||
|
||||
// external imports
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
// our local stuff
|
||||
import * as definitions from './interfaces/definitions';
|
||||
|
||||
async function main (): Promise<void> {
|
||||
// extract all types from definitions - fast and dirty approach, flatted on 'types'
|
||||
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
|
||||
|
||||
const api = await ApiPromise.create({
|
||||
types: {
|
||||
...types,
|
||||
// aliases that don't do well as part of interfaces
|
||||
'voting::VoteType': 'VoteType',
|
||||
'voting::TallyType': 'TallyType',
|
||||
// chain-specific overrides
|
||||
Keys: 'SessionKeys4'
|
||||
}
|
||||
});
|
||||
|
||||
// get a query
|
||||
const recordOpt = await api.query.voting.voteRecords(123);
|
||||
|
||||
// the types match with what we expect here
|
||||
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
|
||||
console.log(firstRecord?.toHuman());
|
||||
|
||||
// it even does work for arrays & subscriptions
|
||||
api.query.signaling.activeProposals((results): void => {
|
||||
results.forEach(([hash, blockNumber]): void => {
|
||||
console.log(hash.toHex(), ':', blockNumber.toNumber());
|
||||
});
|
||||
});
|
||||
|
||||
// even createType works, allowing for our types to be used
|
||||
console.log(`Balance2 bitLength:`, [
|
||||
api.createType('Balance2').bitLength(),
|
||||
api.registry.createType('Balance2').bitLength(),
|
||||
createType(api.registry, 'Balance2').bitLength()
|
||||
]);
|
||||
}
|
||||
|
||||
await main();
|
||||
```
|
||||
|
||||
## And that is a ...
|
||||
|
||||
... wrap. Just a really simple walk-through to customizing the API TypeScript definitions for your chain.
|
||||
File diff suppressed because one or more lines are too long
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"name": "sample-polkadotjs-typegen",
|
||||
"version": "0.0.1",
|
||||
"description": "A sample using @polkadot/typegen to generate type definitions",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/jacogr/sample-polkadotjs-typegen",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "The Unlicense",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "yarn generate:defs && yarn generate:meta",
|
||||
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
|
||||
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces --strict",
|
||||
"lint": "tsc --noEmit --pretty"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/typegen": "^1.4.0",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.8.2"
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
// We need to import the augmented definitions "somewhere" in our project, however since we have
|
||||
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
|
||||
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
|
||||
import './interfaces/augment-api';
|
||||
import './interfaces/augment-types';
|
||||
|
||||
// all type stuff, the only one we are using here
|
||||
import type { VoteRecord } from './interfaces';
|
||||
|
||||
// external imports
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
// our local stuff
|
||||
import * as definitions from './interfaces/definitions';
|
||||
|
||||
async function main (): Promise<void> {
|
||||
// extract all types from definitions - fast and dirty approach, flatted on 'types'
|
||||
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
|
||||
|
||||
const api = await ApiPromise.create({
|
||||
types: {
|
||||
...types,
|
||||
// aliasses that don't do well as part of interfaces
|
||||
'voting::VoteType': 'VoteType',
|
||||
'voting::TallyType': 'TallyType',
|
||||
// chain-specific overrides
|
||||
Keys: 'SessionKeys4'
|
||||
}
|
||||
});
|
||||
|
||||
// get a query
|
||||
const recordOpt = await api.query.voting.voteRecords(123);
|
||||
|
||||
// the types match with what we expect here
|
||||
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
|
||||
console.log(firstRecord?.toHuman());
|
||||
|
||||
// it even does work for arrays & subscriptions
|
||||
api.query.signaling.activeProposals((results): void => {
|
||||
results.forEach(([hash, blockNumber]): void => {
|
||||
console.log(hash.toHex(), ':', blockNumber.toNumber());
|
||||
});
|
||||
});
|
||||
|
||||
// even createType works, allowing for our types to be used
|
||||
console.log(`Balance2 bitLength:`, [
|
||||
api.createType('Balance2').bitLength(),
|
||||
api.registry.createType('Balance2').bitLength(),
|
||||
createType(api.registry, 'Balance2').bitLength()
|
||||
]);
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -1,253 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Bytes, u32 } from '@polkadot/types/primitive';
|
||||
import { Gas } from '@polkadot/types/interfaces/contracts';
|
||||
import { Balance, BalanceOf, BlockNumber, Moment, Percent, Permill } from '@polkadot/types/interfaces/runtime';
|
||||
import { SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
|
||||
declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
export interface Constants {
|
||||
timestamp: {
|
||||
|
||||
/**
|
||||
* The minimum period between blocks. Beware that this is different to the *expected* period
|
||||
* that the block production apparatus provides. Your chosen consensus system will generally
|
||||
* work with this to determine a sensible block time. e.g. For Aura, it will be double this
|
||||
* period on default settings.
|
||||
**/
|
||||
minimumPeriod: AugmentedConst<Moment>;
|
||||
};
|
||||
balances: {
|
||||
|
||||
/**
|
||||
* The minimum amount required to keep an account open.
|
||||
**/
|
||||
existentialDeposit: AugmentedConst<Balance>;
|
||||
/**
|
||||
* The fee required to make a transfer.
|
||||
**/
|
||||
transferFee: AugmentedConst<Balance>;
|
||||
/**
|
||||
* The fee required to create an account.
|
||||
**/
|
||||
creationFee: AugmentedConst<Balance>;
|
||||
};
|
||||
transactionPayment: {
|
||||
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the base.
|
||||
**/
|
||||
transactionBaseFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the per-byte portion.
|
||||
**/
|
||||
transactionByteFee: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
staking: {
|
||||
|
||||
/**
|
||||
* Number of sessions per era.
|
||||
**/
|
||||
sessionsPerEra: AugmentedConst<SessionIndex>;
|
||||
/**
|
||||
* Number of eras that staked funds must remain bonded for.
|
||||
**/
|
||||
bondingDuration: AugmentedConst<EraIndex>;
|
||||
};
|
||||
session: {
|
||||
|
||||
/**
|
||||
* Used as first key for `NextKeys` and `KeyOwner` to put all the data into the same branch
|
||||
* of the trie.
|
||||
**/
|
||||
dedupKeyPrefix: AugmentedConst<Bytes>;
|
||||
};
|
||||
democracy: {
|
||||
|
||||
/**
|
||||
* The minimum period of locking and the period between a proposal being approved and enacted.
|
||||
* It should generally be a little more than the unstake period to ensure that
|
||||
* voting stakers have an opportunity to remove themselves from the system in the case where
|
||||
* they are on the losing side of a vote.
|
||||
**/
|
||||
enactmentPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* How often (in blocks) new public referenda are launched.
|
||||
**/
|
||||
launchPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* How often (in blocks) to check for new votes.
|
||||
**/
|
||||
votingPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The minimum amount to be used as a deposit for a public referendum proposal.
|
||||
**/
|
||||
minimumDeposit: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Minimum voting period allowed for an emergency referendum.
|
||||
**/
|
||||
emergencyVotingPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* Period in blocks where an external proposal may not be re-submitted after being vetoed.
|
||||
**/
|
||||
cooloffPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The amount of balance that must be deposited per byte of preimage stored.
|
||||
**/
|
||||
preimageByteDeposit: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
elections: {
|
||||
|
||||
candidacyBond: AugmentedConst<BalanceOf>;
|
||||
votingBond: AugmentedConst<BalanceOf>;
|
||||
desiredMembers: AugmentedConst<u32>;
|
||||
desiredRunnersUp: AugmentedConst<u32>;
|
||||
termDuration: AugmentedConst<BlockNumber>;
|
||||
};
|
||||
finalityTracker: {
|
||||
|
||||
/**
|
||||
* The number of recent samples to keep from this chain. Default is 101.
|
||||
**/
|
||||
windowSize: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The delay after which point things become suspicious. Default is 1000.
|
||||
**/
|
||||
reportLatency: AugmentedConst<BlockNumber>;
|
||||
};
|
||||
treasury: {
|
||||
|
||||
/**
|
||||
* Fraction of a proposal's value that should be bonded in order to place the proposal.
|
||||
* An accepted proposal gets these back. A rejected proposal does not.
|
||||
**/
|
||||
proposalBond: AugmentedConst<Permill>;
|
||||
/**
|
||||
* Minimum amount of funds that should be placed in a deposit for making a proposal.
|
||||
**/
|
||||
proposalBondMinimum: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Period between successive spends.
|
||||
**/
|
||||
spendPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* Percentage of spare funds (if any) that are burnt per spend period.
|
||||
**/
|
||||
burn: AugmentedConst<Permill>;
|
||||
/**
|
||||
* The period for which a tip remains open after is has achieved threshold tippers.
|
||||
**/
|
||||
tipCountdown: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The amount of the final tip which goes to the original reporter of the tip.
|
||||
**/
|
||||
tipFindersFee: AugmentedConst<Percent>;
|
||||
/**
|
||||
* The amount held on deposit for placing a tip report.
|
||||
**/
|
||||
tipReportDepositBase: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount held on deposit per byte within the tip report reason.
|
||||
**/
|
||||
tipReportDepositPerByte: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
contracts: {
|
||||
|
||||
/**
|
||||
* Number of block delay an extrinsic claim surcharge has.
|
||||
* When claim surcharge is called by an extrinsic the rent is checked
|
||||
* for current_block - delay
|
||||
**/
|
||||
signedClaimHandicap: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The minimum amount required to generate a tombstone.
|
||||
**/
|
||||
tombstoneDeposit: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Size of a contract at the time of instantiaion. This is a simple way to ensure that
|
||||
* empty contracts eventually gets deleted.
|
||||
**/
|
||||
storageSizeOffset: AugmentedConst<u32>;
|
||||
/**
|
||||
* Price of a byte of storage per one block interval. Should be greater than 0.
|
||||
**/
|
||||
rentByteFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount of funds a contract should deposit in order to offset
|
||||
* the cost of one byte.
|
||||
* Let's suppose the deposit is 1,000 BU (balance units)/byte and the rent is 1 BU/byte/day,
|
||||
* then a contract with 1,000,000 BU that uses 1,000 bytes of storage would pay no rent.
|
||||
* But if the balance reduced to 500,000 BU and the storage stayed the same at 1,000,
|
||||
* then it would pay 500 BU/day.
|
||||
**/
|
||||
rentDepositOffset: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Reward that is received by the party whose touch has led
|
||||
* to removal of a contract.
|
||||
**/
|
||||
surchargeReward: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to make a transfer.
|
||||
**/
|
||||
transferFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to create an account.
|
||||
**/
|
||||
creationFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the base.
|
||||
**/
|
||||
transactionBaseFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the per-byte portion.
|
||||
**/
|
||||
transactionByteFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to instantiate a contract instance. A reasonable default value
|
||||
* is 21.
|
||||
**/
|
||||
contractFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The base fee charged for calling into a contract. A reasonable default
|
||||
* value is 135.
|
||||
**/
|
||||
callBaseFee: AugmentedConst<Gas>;
|
||||
/**
|
||||
* The base fee charged for instantiating a contract. A reasonable default value
|
||||
* is 175.
|
||||
**/
|
||||
instantiateBaseFee: AugmentedConst<Gas>;
|
||||
/**
|
||||
* The maximum nesting level of a call/instantiate stack. A reasonable default
|
||||
* value is 100.
|
||||
**/
|
||||
maxDepth: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum size of a storage value in bytes. A reasonable default is 16 KiB.
|
||||
**/
|
||||
maxValueSize: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum amount of gas that could be expended per block. A reasonable
|
||||
* default value is 10_000_000.
|
||||
**/
|
||||
blockGasLimit: AugmentedConst<Gas>;
|
||||
};
|
||||
nicks: {
|
||||
|
||||
/**
|
||||
* Reservation fee.
|
||||
**/
|
||||
reservationFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The minimum length a name may be.
|
||||
**/
|
||||
minLength: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum length a name may be.
|
||||
**/
|
||||
maxLength: AugmentedConst<u32>;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,706 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { AnyNumber, ITuple } from '@polkadot/types/types';
|
||||
import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
|
||||
import { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
|
||||
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
|
||||
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { ProposalRecord } from 'sample-polkadotjs-typegen/interfaces/signaling';
|
||||
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
import { Multisig } from '@polkadot/types/interfaces/utility';
|
||||
import { VoteRecord } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ApiTypes } from '@polkadot/api/types';
|
||||
|
||||
declare module '@polkadot/api/types/storage' {
|
||||
export interface AugmentedQueries<ApiType> {
|
||||
system: {
|
||||
|
||||
/**
|
||||
* Extrinsics nonce for accounts.
|
||||
**/
|
||||
accountNonce: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Index>>;
|
||||
/**
|
||||
* Total extrinsics count for the current block.
|
||||
**/
|
||||
extrinsicCount: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
|
||||
/**
|
||||
* Total weight for all extrinsics put together, for the current block.
|
||||
**/
|
||||
allExtrinsicsWeight: AugmentedQuery<ApiType, () => Observable<Option<Weight>>>;
|
||||
/**
|
||||
* Total length (in bytes) for all extrinsics put together, for the current block.
|
||||
**/
|
||||
allExtrinsicsLen: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
|
||||
/**
|
||||
* Map of block numbers to block hashes.
|
||||
**/
|
||||
blockHash: AugmentedQuery<ApiType, (arg: BlockNumber | AnyNumber | Uint8Array) => Observable<Hash>>;
|
||||
/**
|
||||
* Extrinsics data for the current block (maps an extrinsic's index to its data).
|
||||
**/
|
||||
extrinsicData: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* The current block number being processed. Set by `execute_block`.
|
||||
**/
|
||||
number: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Hash of the previous block.
|
||||
**/
|
||||
parentHash: AugmentedQuery<ApiType, () => Observable<Hash>>;
|
||||
/**
|
||||
* Extrinsics root of the current block, also part of the block header.
|
||||
**/
|
||||
extrinsicsRoot: AugmentedQuery<ApiType, () => Observable<Hash>>;
|
||||
/**
|
||||
* Digest of the current block, also part of the block header.
|
||||
**/
|
||||
digest: AugmentedQuery<ApiType, () => Observable<DigestOf>>;
|
||||
/**
|
||||
* Events deposited for the current block.
|
||||
**/
|
||||
events: AugmentedQuery<ApiType, () => Observable<Vec<EventRecord>>>;
|
||||
/**
|
||||
* The number of events in the `Events<T>` list.
|
||||
**/
|
||||
eventCount: AugmentedQuery<ApiType, () => Observable<EventIndex>>;
|
||||
/**
|
||||
* Mapping between a topic (represented by T::Hash) and a vector of indexes
|
||||
* of events in the `<Events<T>>` list.
|
||||
* All topic vectors have deterministic storage locations depending on the topic. This
|
||||
* allows light-clients to leverage the changes trie storage tracking mechanism and
|
||||
* in case of changes fetch the list of events of interest.
|
||||
* The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
|
||||
* the `EventIndex` then in case if the topic has the same contents on the next block
|
||||
* no notification will be triggered thus the event might be lost.
|
||||
**/
|
||||
eventTopics: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>>;
|
||||
};
|
||||
utility: {
|
||||
|
||||
/**
|
||||
* The set of open multisig operations.
|
||||
**/
|
||||
multisigs: AugmentedQueryDoubleMap<ApiType, (key1: AccountId | string | Uint8Array, key2: U8aFixed | string | Uint8Array) => Observable<Option<Multisig>>>;
|
||||
};
|
||||
timestamp: {
|
||||
|
||||
/**
|
||||
* Current time for the current block.
|
||||
**/
|
||||
now: AugmentedQuery<ApiType, () => Observable<Moment>>;
|
||||
/**
|
||||
* Did the timestamp get updated in this block?
|
||||
**/
|
||||
didUpdate: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
};
|
||||
authorship: {
|
||||
|
||||
/**
|
||||
* Uncles
|
||||
**/
|
||||
uncles: AugmentedQuery<ApiType, () => Observable<Vec<UncleEntryItem>>>;
|
||||
/**
|
||||
* Author of current block.
|
||||
**/
|
||||
author: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Whether uncles were already set in this block.
|
||||
**/
|
||||
didSetUncles: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
};
|
||||
indices: {
|
||||
|
||||
/**
|
||||
* The next free enumeration set.
|
||||
**/
|
||||
nextEnumSet: AugmentedQuery<ApiType, () => Observable<AccountIndex>>;
|
||||
/**
|
||||
* The enumeration sets.
|
||||
**/
|
||||
enumSet: AugmentedQuery<ApiType, (arg: AccountIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
balances: {
|
||||
|
||||
/**
|
||||
* The total units issued in the system.
|
||||
**/
|
||||
totalIssuance: AugmentedQuery<ApiType, () => Observable<Balance>>;
|
||||
/**
|
||||
* Information regarding the vesting of a given account.
|
||||
**/
|
||||
vesting: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<VestingSchedule>>>;
|
||||
/**
|
||||
* The 'free' balance of a given account.
|
||||
* This is the only balance that matters in terms of most operations on tokens. It
|
||||
* alone is used to determine the balance when in the contract execution environment. When this
|
||||
* balance falls below the value of `ExistentialDeposit`, then the 'current account' is
|
||||
* deleted: specifically `FreeBalance`. Further, the `OnFreeBalanceZero` callback
|
||||
* is invoked, giving a chance to external modules to clean up data associated with
|
||||
* the deleted account.
|
||||
* `frame_system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
|
||||
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.
|
||||
**/
|
||||
freeBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
|
||||
/**
|
||||
* The amount of the balance of a given account that is externally reserved; this can still get
|
||||
* slashed, but gets slashed last of all.
|
||||
* This balance is a 'reserve' balance that other subsystems use in order to set aside tokens
|
||||
* that are still 'owned' by the account holder, but which are suspendable.
|
||||
* When this balance falls below the value of `ExistentialDeposit`, then this 'reserve account'
|
||||
* is deleted: specifically, `ReservedBalance`.
|
||||
* `frame_system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
|
||||
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.)
|
||||
**/
|
||||
reservedBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
|
||||
/**
|
||||
* Any liquidity locks on some account balances.
|
||||
**/
|
||||
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>>;
|
||||
};
|
||||
transactionPayment: {
|
||||
|
||||
nextFeeMultiplier: AugmentedQuery<ApiType, () => Observable<Multiplier>>;
|
||||
};
|
||||
staking: {
|
||||
|
||||
/**
|
||||
* The ideal number of staking participants.
|
||||
**/
|
||||
validatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Minimum number of staking participants before emergency conditions are imposed.
|
||||
**/
|
||||
minimumValidatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
|
||||
* easy to initialize and the performance hit is minimal (we expect no more than four
|
||||
* invulnerables) and restricted to testnets.
|
||||
**/
|
||||
invulnerables: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Map from all locked "stash" accounts to the controller account.
|
||||
**/
|
||||
bonded: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Map from all (unlocked) "controller" accounts to the info regarding the staking.
|
||||
**/
|
||||
ledger: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<StakingLedger>>>;
|
||||
/**
|
||||
* Where the reward payment should be made. Keyed by stash.
|
||||
**/
|
||||
payee: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<RewardDestination>>;
|
||||
/**
|
||||
* The map from (wannabe) validator stash key to the preferences of that validator.
|
||||
**/
|
||||
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>>;
|
||||
/**
|
||||
* The map from nominator stash key to the set of stash keys of all validators to nominate.
|
||||
* NOTE: is private so that we can ensure upgraded before all typical accesses.
|
||||
* Direct storage APIs can still bypass this protection.
|
||||
**/
|
||||
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Nominations>>>;
|
||||
/**
|
||||
* Nominators for a particular account that is in action right now. You can't iterate
|
||||
* through validators here, but you can find them in the Session module.
|
||||
* This is keyed by the stash account.
|
||||
**/
|
||||
stakers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Exposure>>;
|
||||
/**
|
||||
* The currently elected validator set keyed by stash account ID.
|
||||
**/
|
||||
currentElected: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* The current era index.
|
||||
**/
|
||||
currentEra: AugmentedQuery<ApiType, () => Observable<EraIndex>>;
|
||||
/**
|
||||
* The start of the current era.
|
||||
**/
|
||||
currentEraStart: AugmentedQuery<ApiType, () => Observable<MomentOf>>;
|
||||
/**
|
||||
* The session index at which the current era started.
|
||||
**/
|
||||
currentEraStartSessionIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
|
||||
/**
|
||||
* Rewards for the current era. Using indices of current elected set.
|
||||
**/
|
||||
currentEraPointsEarned: AugmentedQuery<ApiType, () => Observable<EraPoints>>;
|
||||
/**
|
||||
* The amount of balance actively at stake for each validator slot, currently.
|
||||
* This is used to derive rewards and punishments.
|
||||
**/
|
||||
slotStake: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* True if the next session change will be a new era regardless of index.
|
||||
**/
|
||||
forceEra: AugmentedQuery<ApiType, () => Observable<Forcing>>;
|
||||
/**
|
||||
* The percentage of the slash that is distributed to reporters.
|
||||
* The rest of the slashed value is handled by the `Slash`.
|
||||
**/
|
||||
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>>;
|
||||
/**
|
||||
* The amount of currency given to reporters of a slash event which was
|
||||
* canceled by extraordinary circumstances (e.g. governance).
|
||||
**/
|
||||
canceledSlashPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* All unapplied slashes that are queued for later.
|
||||
**/
|
||||
unappliedSlashes: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Vec<UnappliedSlash>>>;
|
||||
/**
|
||||
* A mapping from still-bonded eras to the first session index of that era.
|
||||
**/
|
||||
bondedEras: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>>;
|
||||
/**
|
||||
* All slashing events on validators, mapped by era to the highest slash proportion
|
||||
* and slash value of the era.
|
||||
**/
|
||||
validatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Perbill, BalanceOf]>>>>;
|
||||
/**
|
||||
* All slashing events on nominators, mapped by era to the highest slash value of the era.
|
||||
**/
|
||||
nominatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<BalanceOf>>>;
|
||||
/**
|
||||
* Slashing spans for stash accounts.
|
||||
**/
|
||||
slashingSpans: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SlashingSpans>>>;
|
||||
/**
|
||||
* Records information about the maximum slash of a stash within a slashing span,
|
||||
* as well as how much reward has been paid out.
|
||||
**/
|
||||
spanSlash: AugmentedQuery<ApiType, (arg: ITuple<[AccountId, SpanIndex]> | [AccountId | string | Uint8Array, SpanIndex | AnyNumber | Uint8Array]) => Observable<SpanRecord>>;
|
||||
/**
|
||||
* The earliest era for which we have a pending, unapplied slash.
|
||||
**/
|
||||
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>>;
|
||||
/**
|
||||
* The version of storage for upgrade.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
};
|
||||
session: {
|
||||
|
||||
/**
|
||||
* The current set of validators.
|
||||
**/
|
||||
validators: AugmentedQuery<ApiType, () => Observable<Vec<ValidatorId>>>;
|
||||
/**
|
||||
* Current index of the session.
|
||||
**/
|
||||
currentIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
|
||||
/**
|
||||
* True if the underlying economic identities or weighting behind the validators
|
||||
* has changed in the queued validator set.
|
||||
**/
|
||||
queuedChanged: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
/**
|
||||
* The queued keys for the next session. When the next session begins, these keys
|
||||
* will be used to determine the validator's session keys.
|
||||
**/
|
||||
queuedKeys: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[ValidatorId, Keys]>>>>;
|
||||
/**
|
||||
* Indices of disabled validators.
|
||||
* The set is cleared when `on_session_ending` returns a new set of identities.
|
||||
**/
|
||||
disabledValidators: AugmentedQuery<ApiType, () => Observable<Vec<u32>>>;
|
||||
/**
|
||||
* The next session keys for a validator.
|
||||
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
* the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
**/
|
||||
nextKeys: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<Option<Keys>>>;
|
||||
/**
|
||||
* The owner of a key. The second key is the `KeyTypeId` + the encoded key.
|
||||
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
* the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
**/
|
||||
keyOwner: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ITuple<[KeyTypeId, Bytes]> | [KeyTypeId | AnyNumber | Uint8Array, Bytes | string | Uint8Array]) => Observable<Option<ValidatorId>>>;
|
||||
};
|
||||
democracy: {
|
||||
|
||||
/**
|
||||
* The number of (public) proposals that have been made so far.
|
||||
**/
|
||||
publicPropCount: AugmentedQuery<ApiType, () => Observable<PropIndex>>;
|
||||
/**
|
||||
* The public proposals. Unsorted. The second item is the proposal's hash.
|
||||
**/
|
||||
publicProps: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[PropIndex, Hash, AccountId]>>>>;
|
||||
/**
|
||||
* Map of hashes to the proposal preimage, along with who registered it and their deposit.
|
||||
* The block number is the block at which it was deposited.
|
||||
**/
|
||||
preimages: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[Bytes, AccountId, BalanceOf, BlockNumber]>>>>;
|
||||
/**
|
||||
* Those who have locked a deposit.
|
||||
**/
|
||||
depositOf: AugmentedQuery<ApiType, (arg: PropIndex | AnyNumber | Uint8Array) => Observable<Option<ITuple<[BalanceOf, Vec<AccountId>]>>>>;
|
||||
/**
|
||||
* The next free referendum index, aka the number of referenda started so far.
|
||||
**/
|
||||
referendumCount: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
|
||||
/**
|
||||
* The lowest referendum index representing an unbaked referendum. Equal to
|
||||
* `ReferendumCount` if there isn't a unbaked referendum.
|
||||
**/
|
||||
lowestUnbaked: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
|
||||
/**
|
||||
* Information concerning any given referendum.
|
||||
**/
|
||||
referendumInfoOf: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Option<ReferendumInfo>>>;
|
||||
/**
|
||||
* Queue of successful referenda to be dispatched. Stored ordered by block number.
|
||||
**/
|
||||
dispatchQueue: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>>;
|
||||
/**
|
||||
* Get the voters for the current proposal.
|
||||
**/
|
||||
votersFor: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Get the vote in a given referendum of a particular voter. The result is meaningful only
|
||||
* if `voters_for` includes the voter when called with the referendum (you'll get the
|
||||
* default `Vote` value otherwise). If you don't want to check `voters_for`, then you can
|
||||
* also check for simple existence with `VoteOf::exists` first.
|
||||
**/
|
||||
voteOf: AugmentedQuery<ApiType, (arg: ITuple<[ReferendumIndex, AccountId]> | [ReferendumIndex | AnyNumber | Uint8Array, AccountId | string | Uint8Array]) => Observable<Vote>>;
|
||||
/**
|
||||
* Who is able to vote for whom. Value is the fund-holding account, key is the
|
||||
* vote-transaction-sending account.
|
||||
**/
|
||||
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Get the account (and lock periods) to which another account is delegating vote.
|
||||
**/
|
||||
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[AccountId, Conviction]>>>;
|
||||
/**
|
||||
* True if the last referendum tabled was submitted externally. False if it was a public
|
||||
* proposal.
|
||||
**/
|
||||
lastTabledWasExternal: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
/**
|
||||
* The referendum to be tabled whenever it would be valid to table an external proposal.
|
||||
* This happens when a referendum needs to be tabled and one of two conditions are met:
|
||||
* - `LastTabledWasExternal` is `false`; or
|
||||
* - `PublicProps` is empty.
|
||||
**/
|
||||
nextExternal: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[Hash, VoteThreshold]>>>>;
|
||||
/**
|
||||
* A record of who vetoed what. Maps proposal hash to a possible existent block number
|
||||
* (until when it may not be resubmitted) and who vetoed it.
|
||||
**/
|
||||
blacklist: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[BlockNumber, Vec<AccountId>]>>>>;
|
||||
/**
|
||||
* Record of all proposals that have been subject to emergency cancellation.
|
||||
**/
|
||||
cancellations: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<bool>>;
|
||||
};
|
||||
council: {
|
||||
|
||||
/**
|
||||
* The hashes of the active proposals.
|
||||
**/
|
||||
proposals: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
|
||||
/**
|
||||
* Actual proposal for a given hash, if it's current.
|
||||
**/
|
||||
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Proposal>>>;
|
||||
/**
|
||||
* Votes on a given proposal, if it is ongoing.
|
||||
**/
|
||||
voting: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Votes>>>;
|
||||
/**
|
||||
* Proposals so far.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* The current members of the collective. This is stored sorted (just by value).
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
elections: {
|
||||
|
||||
/**
|
||||
* The current elected membership. Sorted based on account id.
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
|
||||
/**
|
||||
* The current runners_up. Sorted based on low to high merit (worse to best runner).
|
||||
**/
|
||||
runnersUp: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
|
||||
/**
|
||||
* The total number of vote rounds that have happened, excluding the upcoming one.
|
||||
**/
|
||||
electionRounds: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Votes of a particular voter, with the round index of the votes.
|
||||
**/
|
||||
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Locked stake of a voter.
|
||||
**/
|
||||
stakeOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<BalanceOf>>;
|
||||
/**
|
||||
* The present candidate list. Sorted based on account-id. A current member or a runner can
|
||||
* never enter this vector and is always implicitly assumed to be a candidate.
|
||||
**/
|
||||
candidates: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
grandpa: {
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
* This used to store the current authority set, which has been migrated to the well-known
|
||||
* GRANDPA_AUTHORITES_KEY unhashed key.
|
||||
**/
|
||||
authorities: AugmentedQuery<ApiType, () => Observable<AuthorityList>>;
|
||||
/**
|
||||
* State of the current authority set.
|
||||
**/
|
||||
state: AugmentedQuery<ApiType, () => Observable<StoredState>>;
|
||||
/**
|
||||
* Pending change: (signaled at, scheduled change).
|
||||
**/
|
||||
pendingChange: AugmentedQuery<ApiType, () => Observable<Option<StoredPendingChange>>>;
|
||||
/**
|
||||
* next block number where we can force a change.
|
||||
**/
|
||||
nextForced: AugmentedQuery<ApiType, () => Observable<Option<BlockNumber>>>;
|
||||
/**
|
||||
* `true` if we are currently stalled.
|
||||
**/
|
||||
stalled: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[BlockNumber, BlockNumber]>>>>;
|
||||
/**
|
||||
* The number of changes (both in terms of keys and underlying economic responsibilities)
|
||||
* in the "set" of Grandpa validators from genesis.
|
||||
**/
|
||||
currentSetId: AugmentedQuery<ApiType, () => Observable<SetId>>;
|
||||
/**
|
||||
* A mapping from grandpa set ID to the index of the *most recent* session for which its members were responsible.
|
||||
**/
|
||||
setIdSession: AugmentedQuery<ApiType, (arg: SetId | AnyNumber | Uint8Array) => Observable<Option<SessionIndex>>>;
|
||||
};
|
||||
treasury: {
|
||||
|
||||
/**
|
||||
* Number of proposals that have been made.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<ProposalIndex>>;
|
||||
/**
|
||||
* Proposals that have been made.
|
||||
**/
|
||||
proposals: AugmentedQuery<ApiType, (arg: ProposalIndex | AnyNumber | Uint8Array) => Observable<Option<TreasuryProposal>>>;
|
||||
/**
|
||||
* Proposal indices that have been approved but not yet awarded.
|
||||
**/
|
||||
approvals: AugmentedQuery<ApiType, () => Observable<Vec<ProposalIndex>>>;
|
||||
/**
|
||||
* Tips that are not yet completed. Keyed by the hash of `(reason, who)` from the value.
|
||||
* This has the insecure enumerable hash function since the key itself is already
|
||||
* guaranteed to be a secure hash.
|
||||
**/
|
||||
tips: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<OpenTip>>>;
|
||||
/**
|
||||
* Simple preimage lookup from the reason's hash to the original data. Again, has an
|
||||
* insecure enumerable hash since the key is guaranteed to be the result of a secure hash.
|
||||
**/
|
||||
reasons: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
};
|
||||
contracts: {
|
||||
|
||||
/**
|
||||
* Gas spent so far in this block.
|
||||
**/
|
||||
gasSpent: AugmentedQuery<ApiType, () => Observable<Gas>>;
|
||||
/**
|
||||
* Current cost schedule for contracts.
|
||||
**/
|
||||
currentSchedule: AugmentedQuery<ApiType, () => Observable<Schedule>>;
|
||||
/**
|
||||
* A mapping from an original code hash to the original code, untouched by instrumentation.
|
||||
**/
|
||||
pristineCode: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
/**
|
||||
* A mapping between an original code hash and instrumented wasm code, ready for execution.
|
||||
**/
|
||||
codeStorage: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<PrefabWasmModule>>>;
|
||||
/**
|
||||
* The subtrie counter.
|
||||
**/
|
||||
accountCounter: AugmentedQuery<ApiType, () => Observable<u64>>;
|
||||
/**
|
||||
* The code associated with a given account.
|
||||
**/
|
||||
contractInfoOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ContractInfo>>>;
|
||||
/**
|
||||
* The price of one unit of gas.
|
||||
**/
|
||||
gasPrice: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
};
|
||||
identity: {
|
||||
|
||||
/**
|
||||
* Information that is pertinent to identify the entity behind an account.
|
||||
**/
|
||||
identityOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Registration>>>;
|
||||
/**
|
||||
* The super-identity of an alternative "sub" identity together with its name, within that
|
||||
* context. If the account is not some other account's sub-identity, then just `None`.
|
||||
**/
|
||||
superOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[AccountId, Data]>>>>;
|
||||
/**
|
||||
* Alternative "sub" identities of this account.
|
||||
* The first item is the deposit, the second is a vector of the accounts.
|
||||
**/
|
||||
subsOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>>;
|
||||
/**
|
||||
* The set of registrars. Not expected to get very big as can only be added through a
|
||||
* special origin (likely a council motion).
|
||||
* The index into this can be cast to `RegistrarIndex` to get a valid value.
|
||||
**/
|
||||
registrars: AugmentedQuery<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>>;
|
||||
};
|
||||
imOnline: {
|
||||
|
||||
/**
|
||||
* The block number after which it's ok to send heartbeats in current session.
|
||||
* At the beginning of each session we set this to a value that should
|
||||
* fall roughly in the middle of the session duration.
|
||||
* The idea is to first wait for the validators to produce a block
|
||||
* in the current session, so that the heartbeat later on will not be necessary.
|
||||
**/
|
||||
heartbeatAfter: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* The current set of keys that may issue a heartbeat.
|
||||
**/
|
||||
keys: AugmentedQuery<ApiType, () => Observable<Vec<AuthorityId>>>;
|
||||
/**
|
||||
* For each session index, we keep a mapping of `AuthIndex`
|
||||
* to `offchain::OpaqueNetworkState`.
|
||||
**/
|
||||
receivedHeartbeats: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: AuthIndex | AnyNumber | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
/**
|
||||
* For each session index, we keep a mapping of `T::ValidatorId` to the
|
||||
* number of blocks authored by the given authority.
|
||||
**/
|
||||
authoredBlocks: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>>;
|
||||
};
|
||||
offences: {
|
||||
|
||||
/**
|
||||
* The primary structure that holds all offence records keyed by report identifiers.
|
||||
**/
|
||||
reports: AugmentedQuery<ApiType, (arg: ReportIdOf | string | Uint8Array) => Observable<Option<OffenceDetails>>>;
|
||||
/**
|
||||
* A vector of reports of the same kind that happened at the same time slot.
|
||||
**/
|
||||
concurrentReportsIndex: AugmentedQueryDoubleMap<ApiType, (key1: Kind | string | Uint8Array, key2: OpaqueTimeSlot | string | Uint8Array) => Observable<Vec<ReportIdOf>>>;
|
||||
/**
|
||||
* Enumerates all reports of a kind along with the time they happened.
|
||||
* All reports are sorted by the time of offence.
|
||||
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
|
||||
* different types are not supported at the moment so we are doing the manual serialization.
|
||||
**/
|
||||
reportsByKindIndex: AugmentedQuery<ApiType, (arg: Kind | string | Uint8Array) => Observable<Bytes>>;
|
||||
};
|
||||
randomnessCollectiveFlip: {
|
||||
|
||||
/**
|
||||
* Series of block headers from the last 81 blocks that acts as random seed material. This
|
||||
* is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
|
||||
* the oldest hash.
|
||||
**/
|
||||
randomMaterial: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
|
||||
};
|
||||
nicks: {
|
||||
|
||||
/**
|
||||
* The lookup table for names.
|
||||
**/
|
||||
nameOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Bytes, BalanceOf]>>>>;
|
||||
};
|
||||
sudo: {
|
||||
|
||||
/**
|
||||
* The `AccountId` of the sudo key.
|
||||
**/
|
||||
key: AugmentedQuery<ApiType, () => Observable<AccountId>>;
|
||||
};
|
||||
signaling: {
|
||||
|
||||
/**
|
||||
* The total number of proposals created thus far.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* A list of all extant proposals.
|
||||
**/
|
||||
inactiveProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* A list of active proposals along with the time at which they complete.
|
||||
**/
|
||||
activeProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* A list of completed proposals, pending deletion
|
||||
**/
|
||||
completedProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* Amount of time a proposal remains in "Voting" stage.
|
||||
**/
|
||||
votingLength: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Map for retrieving the information about any proposal from its hash.
|
||||
**/
|
||||
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ProposalRecord>>>;
|
||||
/**
|
||||
* Registration bond
|
||||
**/
|
||||
proposalCreationBond: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
};
|
||||
voting: {
|
||||
|
||||
/**
|
||||
* The map of all vote records indexed by id
|
||||
**/
|
||||
voteRecords: AugmentedQuery<ApiType, (arg: u64 | AnyNumber | Uint8Array) => Observable<Option<VoteRecord>>>;
|
||||
/**
|
||||
* The number of vote records that have been created
|
||||
**/
|
||||
voteRecordCount: AugmentedQuery<ApiType, () => Observable<u64>>;
|
||||
};
|
||||
treasuryReward: {
|
||||
|
||||
/**
|
||||
* Interval in number of blocks to reward treasury
|
||||
**/
|
||||
mintingInterval: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Current payout of module
|
||||
**/
|
||||
currentPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* Current pot
|
||||
**/
|
||||
pot: AugmentedQuery<ApiType, () => Observable<Balance>>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import '@polkadot/api/augment/rpc';
|
||||
import './augment-api-consts';
|
||||
import './augment-api-query';
|
||||
import './augment-api-tx';
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
// order here matches with what is found in (unused removed)
|
||||
// https://www.npmjs.com/package/edgeware-node-types
|
||||
// https://github.com/hicommonwealth/edgeware-node-types/tree/master/types
|
||||
|
||||
export { default as signaling } from './signaling/definitions';
|
||||
export { default as treasuryRewards } from './treasuryRewards/definitions';
|
||||
export { default as voting } from './voting/definitions';
|
||||
@@ -1,17 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
ProposalRecord: {
|
||||
index: 'u32',
|
||||
author: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
transition_time: 'u32',
|
||||
title: 'Text',
|
||||
contents: 'Text',
|
||||
vote_id: 'u64'
|
||||
},
|
||||
ProposalContents: 'Vec<u8>',
|
||||
ProposalTitle: 'Vec<u8>'
|
||||
}
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Struct } from '@polkadot/types/codec';
|
||||
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
|
||||
/** @name ProposalContents */
|
||||
export interface ProposalContents extends Bytes {}
|
||||
|
||||
/** @name ProposalRecord */
|
||||
export interface ProposalRecord extends Struct {
|
||||
readonly index: u32;
|
||||
readonly author: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly transition_time: u32;
|
||||
readonly title: Text;
|
||||
readonly contents: Text;
|
||||
readonly vote_id: u64;
|
||||
}
|
||||
|
||||
/** @name ProposalTitle */
|
||||
export interface ProposalTitle extends Bytes {}
|
||||
@@ -1,7 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
Balance2: 'u128'
|
||||
}
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { u128 } from '@polkadot/types/primitive';
|
||||
|
||||
/** @name Balance2 */
|
||||
export interface Balance2 extends u128 {}
|
||||
@@ -1,6 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './signaling/types';
|
||||
export * from './treasuryRewards/types';
|
||||
export * from './voting/types';
|
||||
@@ -1,33 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
VoteStage: {
|
||||
_enum: ['PreVoting', 'Commit', 'Voting', 'Completed']
|
||||
},
|
||||
VoteType: {
|
||||
_enum: ['Binary', 'MultiOption', 'RankedChoice']
|
||||
},
|
||||
TallyType: {
|
||||
_enum: ['OnePerson', 'OneCoin']
|
||||
},
|
||||
VoteOutcome: '[u8; 32]',
|
||||
Tally: 'Option<Vec<(VoteOutcome, u128)>>',
|
||||
VoteData: {
|
||||
initiator: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
vote_type: 'VoteType',
|
||||
tally_type: 'TallyType',
|
||||
is_commit_reveal: 'bool'
|
||||
},
|
||||
Commitments: 'Vec<(AccountId, VoteOutcome)>',
|
||||
Reveals: 'Vec<(AccountId, Vec<VoteOutcome>)>',
|
||||
VoteRecord: {
|
||||
id: 'u64',
|
||||
commitments: 'Commitments',
|
||||
reveals: 'Reveals',
|
||||
data: 'VoteData',
|
||||
outcomes: 'Vec<VoteOutcome>'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -1,58 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { bool, u128, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
|
||||
/** @name Commitments */
|
||||
export interface Commitments extends Vec<ITuple<[AccountId, VoteOutcome]>> {}
|
||||
|
||||
/** @name Reveals */
|
||||
export interface Reveals extends Vec<ITuple<[AccountId, Vec<VoteOutcome>]>> {}
|
||||
|
||||
/** @name Tally */
|
||||
export interface Tally extends Option<Vec<ITuple<[VoteOutcome, u128]>>> {}
|
||||
|
||||
/** @name TallyType */
|
||||
export interface TallyType extends Enum {
|
||||
readonly isOnePerson: boolean;
|
||||
readonly isOneCoin: boolean;
|
||||
}
|
||||
|
||||
/** @name VoteData */
|
||||
export interface VoteData extends Struct {
|
||||
readonly initiator: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly vote_type: VoteType;
|
||||
readonly tally_type: TallyType;
|
||||
readonly is_commit_reveal: bool;
|
||||
}
|
||||
|
||||
/** @name VoteOutcome */
|
||||
export interface VoteOutcome extends U8aFixed {}
|
||||
|
||||
/** @name VoteRecord */
|
||||
export interface VoteRecord extends Struct {
|
||||
readonly id: u64;
|
||||
readonly commitments: Commitments;
|
||||
readonly reveals: Reveals;
|
||||
readonly data: VoteData;
|
||||
readonly outcomes: Vec<VoteOutcome>;
|
||||
}
|
||||
|
||||
/** @name VoteStage */
|
||||
export interface VoteStage extends Enum {
|
||||
readonly isPreVoting: boolean;
|
||||
readonly isCommit: boolean;
|
||||
readonly isVoting: boolean;
|
||||
readonly isCompleted: boolean;
|
||||
}
|
||||
|
||||
/** @name VoteType */
|
||||
export interface VoteType extends Enum {
|
||||
readonly isBinary: boolean;
|
||||
readonly isMultiOption: boolean;
|
||||
readonly isRankedChoice: boolean;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// this is specific with augmented overrides
|
||||
"paths": {
|
||||
// this is the package name we use (in the interface imports, --package for generators)
|
||||
"sample-polkadotjs-typegen/*": ["src/*"],
|
||||
// here we replace the @polkadot/api augmentation with our own, generated from chain
|
||||
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
|
||||
// replace the augmented types with our own, as generated from definitions
|
||||
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
|
||||
},
|
||||
// some other options, whatever you want for your environment
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"jsx": "preserve",
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitReturns": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
# ApiPromise Examples
|
||||
|
||||
Here you will find a list of examples that takes you through the basics of connecting to a local node, retrieving data from the Node and chain and execute transactions on the chain. It uses the [[ApiPromise]] interface.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
For the following examples, you need a local node. It is usually convenient testing with:
|
||||
|
||||
```
|
||||
substrate --dev
|
||||
```
|
||||
|
||||
## Running the examples
|
||||
|
||||
From each folder, run `yarn` to install the required dependencies and then run `yarn start` to execute the example against the running node.
|
||||
|
||||
## Development accounts
|
||||
|
||||
Some of the examples use the following accounts:
|
||||
|
||||
- Alice: `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY`
|
||||
- Bob: `5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty`
|
||||
|
||||
Those accounts are easy to add if you don't have/see them. The seed of Alice's account is `//Alice` (via `keyring.addUri(...)`, dev seed implied) and the seed of Bob is... well you guess...
|
||||
@@ -1,5 +0,0 @@
|
||||
# Simple Connect
|
||||
|
||||
The following example shows how to instantiate a Polkadot API object and use it to connect to a node using ApiRx.
|
||||
|
||||
<<< @/docs/examples/rx/01_simple_connect/index.js
|
||||
@@ -1,28 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Required imports
|
||||
const { zip } = require('rxjs');
|
||||
const { ApiRx } = require('@polkadot/api');
|
||||
const { WsProvider } = require('@polkadot/rpc-provider');
|
||||
|
||||
async function main () {
|
||||
// Initialise the provider to connect to the local node
|
||||
const provider = new WsProvider('ws://127.0.0.1:9944');
|
||||
|
||||
// Create the API and wait until ready
|
||||
const api = await ApiRx.create({ provider }).toPromise();
|
||||
|
||||
// We're using RxJs 'zip()' combination operator to get the emitted values
|
||||
// of multiple observables as an array
|
||||
zip(
|
||||
api.rpc.system.chain(),
|
||||
api.rpc.system.name(),
|
||||
api.rpc.system.version()
|
||||
).subscribe(([chain, nodeName, nodeVersion]) => {
|
||||
console.log(`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`);
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "rx_01_simple_connect",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to connect using a WebSocket",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
# Listen to new blocks
|
||||
|
||||
This example shows how to subscribe to new blocks.
|
||||
|
||||
It displays the block number every time a new block is seen by the node you are connected to.
|
||||
|
||||
NOTE: The example runs until you stop it with CTRL+C
|
||||
|
||||
<<< @/docs/examples/rx/02_listen_to_blocks/index.js
|
||||
@@ -1,23 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiRx } = require('@polkadot/api');
|
||||
const { switchMap } = require('rxjs/operators');
|
||||
|
||||
async function main () {
|
||||
// Here we don't pass the (optional) provider, connecting directly to the default
|
||||
// node/port, i.e. `ws://127.0.0.1:9944`. Await for the isReady promise to ensure
|
||||
// the API has connected to the node and completed the initialisation process
|
||||
new ApiRx().isReady
|
||||
.pipe(
|
||||
switchMap((api) =>
|
||||
api.rpc.chain.subscribeNewHeads()
|
||||
))
|
||||
.subscribe((header) => {
|
||||
console.log(`Chain is at block: #${header.number}`);
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "rx_02_listen_to_blocks",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to use subscriptions",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Listen to balance changes
|
||||
|
||||
This example shows how to instantiate a Polkadot API object and use it to connect to a node and retrieve balance updates.
|
||||
|
||||
<<< @/docs/examples/rx/03_listen_to_balance_change/index.js
|
||||
@@ -1,44 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API and operators from RxJs
|
||||
const { ApiRx } = require('@polkadot/api');
|
||||
const { pairwise, startWith } = require('rxjs/operators');
|
||||
|
||||
// Known account we want to use (available on dev chain, with funds)
|
||||
const Alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
async function main () {
|
||||
// Create an await for the API
|
||||
const api = await ApiRx.create().toPromise();
|
||||
|
||||
// Here we subscribe to any balance changes and update the on-screen value.
|
||||
// We're using RxJs pairwise() operator to get the previous and current values as an array.
|
||||
api.query.system.account(Alice)
|
||||
.pipe(
|
||||
// since pairwise only starts emitting values on the second emission, we prepend an
|
||||
// initial value with the startWith() operator to be able to also receive the first value
|
||||
startWith('first'),
|
||||
pairwise()
|
||||
)
|
||||
.subscribe((balance) => {
|
||||
if (balance[0] === 'first') {
|
||||
// Now we know that if the previous value emitted as balance[0] is `first`,
|
||||
// then balance[1] is the initial value of Alice account.
|
||||
console.log(`Alice ${Alice} has a balance of ${balance[1].data.free}`);
|
||||
console.log('You may leave this example running and start the "Make a transfer" example or transfer any value to Alice address');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const change = balance[1].data.free.sub(balance[0].date.free);
|
||||
|
||||
// Only display value changes
|
||||
if (!change.isZero()) {
|
||||
console.log(`New balance change of: ${change}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "rx_03_listen_to_balance_change",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to subscribe to balance change",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
# Unsubscribe from listening to updates
|
||||
|
||||
This example shows how to subscribe to and later unsubscribe from listening to block updates.
|
||||
|
||||
In this example we're calling the built-in unsubscribe() function after a timeOut of 20s to cleanup and unsubscribe from listening to updates.
|
||||
|
||||
<<< @/docs/examples/rx/04_unsubscribe/index.js
|
||||
@@ -1,29 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiRx } = require('@polkadot/api');
|
||||
const { switchMap } = require('rxjs/operators');
|
||||
|
||||
async function main () {
|
||||
// Create a new instance of the api
|
||||
// Subscribe to chain updates and log the current block number on update.
|
||||
const subscription = new ApiRx().isReady
|
||||
.pipe(
|
||||
switchMap((api) =>
|
||||
api.rpc.chain.subscribeNewHeads()
|
||||
))
|
||||
.subscribe((header) => {
|
||||
console.log(`Chain is at block: #${header.number}`);
|
||||
});
|
||||
|
||||
// In this example we're calling the Overvables unsubscribe() //
|
||||
// function after 20s.
|
||||
setTimeout(() => {
|
||||
subscription.unsubscribe();
|
||||
console.log('Unsubscribed');
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "rx_04_unsubscribe",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to unsubscribe from a subscription",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
# Read storage
|
||||
|
||||
Many important variables are available through the storage API. This example shows how to call a few of those APIs.
|
||||
|
||||
<<< @/docs/examples/rx/05_read_storage/index.js
|
||||
@@ -1,55 +0,0 @@
|
||||
/* eslint-disable header/header */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
|
||||
// Import the API
|
||||
const { ApiRx } = require('@polkadot/api');
|
||||
const { combineLatest, of } = require('rxjs');
|
||||
const { first, switchMap } = require('rxjs/operators');
|
||||
|
||||
// Our address for Alice on the dev chain
|
||||
const Alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
|
||||
function main () {
|
||||
// Create our API with a default connection to the local node
|
||||
new ApiRx().isReady
|
||||
.pipe(
|
||||
// Here we ake our basic chain state/storage queries
|
||||
switchMap((api) => combineLatest(
|
||||
of(api),
|
||||
api.query.session.validators().pipe(first())
|
||||
)),
|
||||
switchMap(([api, validators]) => {
|
||||
// In the next step, we're checking if the node has active validators.
|
||||
// If it does, we're making another call to the api to get the balances for all validators
|
||||
const balances = (validators && validators.length > 0)
|
||||
? combineLatest(validators.map((authorityId) => api.query.system.account(authorityId).pipe(first())))
|
||||
: of(null);
|
||||
|
||||
// We're combining the results together with the emitted value 'validators',
|
||||
// which we're turning back into an observable using of()
|
||||
return combineLatest(
|
||||
api.query.system.account(Alice).pipe(first()),
|
||||
api.query.timestamp.blockPeriod().pipe(first()),
|
||||
of(validators),
|
||||
balances
|
||||
);
|
||||
})
|
||||
)
|
||||
// Then we're subscribing to the emitted results
|
||||
.subscribe(([{ nonce }, blockPeriod, validators, validatorBalances]) => {
|
||||
console.log(`accountNonce(${Alice}) ${nonce}`);
|
||||
console.log(`blockPeriod ${blockPeriod.toNumber()} seconds`);
|
||||
|
||||
if (validatorBalances) {
|
||||
// And lastly we print out the authorityIds and balances of all validators
|
||||
console.log('validators', validators.map((authorityId, index) => ({
|
||||
address: authorityId.toString(),
|
||||
balance: validatorBalances[index].data.free.toString(),
|
||||
nonce: validatorBalances[index].data.toString()
|
||||
})));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => process.exit());
|
||||
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "rx_05_read_storage",
|
||||
"version": "0.2.0",
|
||||
"description": "Example showing how to query storage",
|
||||
"main": "index.js",
|
||||
"author": "Stefie",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rimraf node_modules",
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rimraf": "^2.6.2"
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user