@waves/node-api-js 1.3.0 → 1.3.10-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/README.md +2 -2
  2. package/cjs/api-node/activation/index.d.ts +21 -21
  3. package/cjs/api-node/activation/index.js +19 -19
  4. package/cjs/api-node/addresses/index.d.ts +81 -81
  5. package/cjs/api-node/addresses/index.js +173 -173
  6. package/cjs/api-node/addresses/index.js.map +1 -1
  7. package/cjs/api-node/alias/index.d.ts +6 -6
  8. package/cjs/api-node/alias/index.js +21 -21
  9. package/cjs/api-node/assets/index.d.ts +79 -79
  10. package/cjs/api-node/assets/index.js +171 -171
  11. package/cjs/api-node/blocks/index.d.ts +143 -131
  12. package/cjs/api-node/blocks/index.js +209 -209
  13. package/cjs/api-node/consensus/index.d.ts +39 -39
  14. package/cjs/api-node/consensus/index.js +36 -36
  15. package/cjs/api-node/debug/index.d.ts +189 -189
  16. package/cjs/api-node/debug/index.js +244 -244
  17. package/cjs/api-node/eth/index.d.ts +3 -3
  18. package/cjs/api-node/eth/index.js +14 -14
  19. package/cjs/api-node/leasing/index.d.ts +22 -22
  20. package/cjs/api-node/leasing/index.js +41 -41
  21. package/cjs/api-node/node/index.d.ts +11 -11
  22. package/cjs/api-node/node/index.js +19 -19
  23. package/cjs/api-node/peers/index.d.ts +46 -46
  24. package/cjs/api-node/peers/index.js +59 -59
  25. package/cjs/api-node/rewards/index.d.ts +21 -21
  26. package/cjs/api-node/rewards/index.js +20 -20
  27. package/cjs/api-node/transactions/index.d.ts +73 -73
  28. package/cjs/api-node/transactions/index.js +192 -192
  29. package/cjs/api-node/utils/index.d.ts +110 -110
  30. package/cjs/api-node/utils/index.js +210 -210
  31. package/cjs/api-node/wallet/index.d.ts +5 -5
  32. package/cjs/api-node/wallet/index.js +6 -6
  33. package/cjs/constants.d.ts +40 -40
  34. package/cjs/constants.js +42 -42
  35. package/cjs/create.d.ts +1238 -1240
  36. package/cjs/create.js +115 -118
  37. package/cjs/create.js.map +1 -1
  38. package/cjs/index.d.ts +9 -9
  39. package/cjs/index.js +17 -17
  40. package/cjs/interface.d.ts +44 -44
  41. package/cjs/interface.js +9 -9
  42. package/cjs/tools/adresses/availableSponsoredBalances.d.ts +7 -7
  43. package/cjs/tools/adresses/availableSponsoredBalances.js +29 -29
  44. package/cjs/tools/adresses/ethAddress2waves.d.ts +1 -1
  45. package/cjs/tools/adresses/ethAddress2waves.js +46 -46
  46. package/cjs/tools/adresses/getAssetIdListByTx.d.ts +2 -2
  47. package/cjs/tools/adresses/getAssetIdListByTx.js +47 -47
  48. package/cjs/tools/adresses/getAssetsByTransaction.d.ts +3 -3
  49. package/cjs/tools/adresses/getAssetsByTransaction.js +13 -13
  50. package/cjs/tools/adresses/getTransactionsWithAssets.d.ts +6 -6
  51. package/cjs/tools/adresses/getTransactionsWithAssets.js +12 -12
  52. package/cjs/tools/adresses/watch.d.ts +24 -24
  53. package/cjs/tools/adresses/watch.js +167 -167
  54. package/cjs/tools/adresses/wavesAddress2eth.d.ts +1 -1
  55. package/cjs/tools/adresses/wavesAddress2eth.js +9 -9
  56. package/cjs/tools/assets/wavesAsset2eth.d.ts +1 -1
  57. package/cjs/tools/assets/wavesAsset2eth.js +9 -9
  58. package/cjs/tools/blocks/detectInterval.d.ts +1 -1
  59. package/cjs/tools/blocks/detectInterval.js +11 -11
  60. package/cjs/tools/blocks/getNetworkByte.d.ts +1 -1
  61. package/cjs/tools/blocks/getNetworkByte.js +53 -53
  62. package/cjs/tools/blocks/getNetworkCode.d.ts +1 -1
  63. package/cjs/tools/blocks/getNetworkCode.js +10 -10
  64. package/cjs/tools/blocks/waitHeight.d.ts +3 -3
  65. package/cjs/tools/blocks/waitHeight.js +64 -64
  66. package/cjs/tools/parse.d.ts +1 -1
  67. package/cjs/tools/parse.js +7 -7
  68. package/cjs/tools/query.d.ts +4 -4
  69. package/cjs/tools/query.js +40 -40
  70. package/cjs/tools/request.d.ts +64 -64
  71. package/cjs/tools/request.js +41 -41
  72. package/cjs/tools/resolve.d.ts +1 -1
  73. package/cjs/tools/resolve.js +6 -6
  74. package/cjs/tools/stringify.d.ts +1 -1
  75. package/cjs/tools/stringify.js +20 -20
  76. package/cjs/tools/transactions/broadcast.d.ts +14 -14
  77. package/cjs/tools/transactions/broadcast.js +59 -59
  78. package/cjs/tools/transactions/ethTxId2waves.d.ts +1 -1
  79. package/cjs/tools/transactions/ethTxId2waves.js +10 -10
  80. package/cjs/tools/transactions/wait.d.ts +10 -10
  81. package/cjs/tools/transactions/wait.js +41 -41
  82. package/cjs/tools/utils.d.ts +32 -32
  83. package/cjs/tools/utils.js +117 -117
  84. package/dist/node-api.js +2368 -2420
  85. package/dist/node-api.min.js +2 -2
  86. package/es/api-node/activation/index.d.ts +21 -21
  87. package/es/api-node/activation/index.js +12 -12
  88. package/es/api-node/addresses/index.d.ts +81 -81
  89. package/es/api-node/addresses/index.js +110 -110
  90. package/es/api-node/addresses/index.js.map +1 -1
  91. package/es/api-node/alias/index.d.ts +6 -6
  92. package/es/api-node/alias/index.js +13 -13
  93. package/es/api-node/assets/index.d.ts +79 -79
  94. package/es/api-node/assets/index.js +102 -102
  95. package/es/api-node/blocks/index.d.ts +143 -131
  96. package/es/api-node/blocks/index.js +178 -178
  97. package/es/api-node/consensus/index.d.ts +39 -39
  98. package/es/api-node/consensus/index.js +26 -26
  99. package/es/api-node/debug/index.d.ts +189 -189
  100. package/es/api-node/debug/index.js +200 -200
  101. package/es/api-node/eth/index.d.ts +3 -3
  102. package/es/api-node/eth/index.js +7 -7
  103. package/es/api-node/leasing/index.d.ts +22 -22
  104. package/es/api-node/leasing/index.js +21 -21
  105. package/es/api-node/node/index.d.ts +11 -11
  106. package/es/api-node/node/index.js +9 -9
  107. package/es/api-node/peers/index.d.ts +46 -46
  108. package/es/api-node/peers/index.js +45 -45
  109. package/es/api-node/rewards/index.d.ts +21 -21
  110. package/es/api-node/rewards/index.js +12 -12
  111. package/es/api-node/transactions/index.d.ts +73 -73
  112. package/es/api-node/transactions/index.js +136 -136
  113. package/es/api-node/utils/index.d.ts +110 -110
  114. package/es/api-node/utils/index.js +192 -192
  115. package/es/api-node/wallet/index.d.ts +5 -5
  116. package/es/api-node/wallet/index.js +6 -6
  117. package/es/constants.d.ts +40 -40
  118. package/es/constants.js +39 -39
  119. package/es/create.d.ts +1238 -1240
  120. package/es/create.js +89 -92
  121. package/es/create.js.map +1 -1
  122. package/es/index.d.ts +9 -9
  123. package/es/index.js +8 -8
  124. package/es/interface.d.ts +44 -44
  125. package/es/interface.js +2 -2
  126. package/es/tools/adresses/availableSponsoredBalances.d.ts +7 -7
  127. package/es/tools/adresses/availableSponsoredBalances.js +26 -26
  128. package/es/tools/adresses/ethAddress2waves.d.ts +1 -1
  129. package/es/tools/adresses/ethAddress2waves.js +30 -30
  130. package/es/tools/adresses/getAssetIdListByTx.d.ts +2 -2
  131. package/es/tools/adresses/getAssetIdListByTx.js +23 -23
  132. package/es/tools/adresses/getAssetsByTransaction.d.ts +3 -3
  133. package/es/tools/adresses/getAssetsByTransaction.js +7 -7
  134. package/es/tools/adresses/getTransactionsWithAssets.d.ts +6 -6
  135. package/es/tools/adresses/getTransactionsWithAssets.js +6 -6
  136. package/es/tools/adresses/watch.d.ts +24 -24
  137. package/es/tools/adresses/watch.js +133 -133
  138. package/es/tools/adresses/wavesAddress2eth.d.ts +1 -1
  139. package/es/tools/adresses/wavesAddress2eth.js +6 -6
  140. package/es/tools/assets/wavesAsset2eth.d.ts +1 -1
  141. package/es/tools/assets/wavesAsset2eth.js +6 -6
  142. package/es/tools/blocks/detectInterval.d.ts +1 -1
  143. package/es/tools/blocks/detectInterval.js +8 -8
  144. package/es/tools/blocks/getNetworkByte.d.ts +1 -1
  145. package/es/tools/blocks/getNetworkByte.js +50 -50
  146. package/es/tools/blocks/getNetworkCode.d.ts +1 -1
  147. package/es/tools/blocks/getNetworkCode.js +4 -4
  148. package/es/tools/blocks/waitHeight.d.ts +3 -3
  149. package/es/tools/blocks/waitHeight.js +35 -35
  150. package/es/tools/parse.d.ts +1 -1
  151. package/es/tools/parse.js +4 -4
  152. package/es/tools/query.d.ts +4 -4
  153. package/es/tools/query.js +11 -11
  154. package/es/tools/request.d.ts +64 -64
  155. package/es/tools/request.js +21 -21
  156. package/es/tools/resolve.d.ts +1 -1
  157. package/es/tools/resolve.js +3 -3
  158. package/es/tools/stringify.d.ts +1 -1
  159. package/es/tools/stringify.js +17 -17
  160. package/es/tools/transactions/broadcast.d.ts +14 -14
  161. package/es/tools/transactions/broadcast.js +42 -42
  162. package/es/tools/transactions/ethTxId2waves.d.ts +1 -1
  163. package/es/tools/transactions/ethTxId2waves.js +7 -7
  164. package/es/tools/transactions/wait.d.ts +10 -10
  165. package/es/tools/transactions/wait.js +38 -38
  166. package/es/tools/utils.d.ts +32 -32
  167. package/es/tools/utils.js +72 -72
  168. package/package.json +66 -66
  169. package/cjs/tools/transactions/transactions.d.ts +0 -0
  170. package/cjs/tools/transactions/transactions.js +0 -2
  171. package/cjs/tools/transactions/transactions.js.map +0 -1
  172. package/dist/0.node-api.js +0 -467
  173. package/dist/node-api.min.js.LICENSE.txt +0 -17
  174. package/dist/node_fs-node_path.node-api.js +0 -23
  175. package/dist/vendors-node_modules_node-fetch_src_utils_multipart-parser_js.node-api.js +0 -599
  176. package/es/tools/transactions/transactions.d.ts +0 -0
  177. package/es/tools/transactions/transactions.js +0 -2
  178. package/es/tools/transactions/transactions.js.map +0 -1
@@ -1,134 +1,134 @@
1
- import { fetchTransactions } from '../../api-node/transactions';
2
- import { indexBy, keys, prop } from '../utils';
3
- import { EventEmitter } from 'typed-ts-events';
4
- export class Watch {
5
- constructor(base, address, tx, interval) {
6
- this._emitter = new EventEmitter();
7
- this._timer = null;
8
- this.address = address;
9
- this._interval = interval || 1000;
10
- this._base = base;
11
- this._lastBlock = {
12
- lastId: (tx === null || tx === void 0 ? void 0 : tx.id) || '',
13
- height: (tx === null || tx === void 0 ? void 0 : tx.height) || 0,
14
- transactions: tx ? [tx] : []
15
- };
16
- this._addTimeout();
17
- }
18
- on(event, handler) {
19
- this._emitter.on(event, handler);
20
- }
21
- once(event, handler) {
22
- this._emitter.once(event, handler);
23
- }
24
- off(event, handler) {
25
- this._emitter.off(event, handler);
26
- }
27
- _run() {
28
- if (this._timer) {
29
- clearTimeout(this._timer);
30
- }
31
- const onError = () => this._addTimeout();
32
- fetchTransactions(this._base, this.address, 1)
33
- .then(([tx]) => {
34
- if (!tx) {
35
- this._addTimeout();
36
- return null;
37
- }
38
- this.getTransactionsInHeight(tx, 310)
39
- .then(list => {
40
- const hash = Watch._groupByHeight(list);
41
- const heightList = keys(hash)
42
- .map(Number)
43
- .sort((a, b) => b - a);
44
- const [last, prev] = heightList;
45
- if (!this._lastBlock.height) {
46
- this._lastBlock = {
47
- height: last,
48
- lastId: hash[prev] && hash[prev].length ? hash[prev][0].id : '',
49
- transactions: hash[last]
50
- };
51
- this._emitter.trigger('change-state', list);
52
- }
53
- else {
54
- const wasDispatchHash = indexBy(prop('id'), this._lastBlock.transactions);
55
- const toDispatch = Watch._getTransactionsToDispatch([...hash[last], ...(hash[prev] || [])], wasDispatchHash, this._lastBlock.lastId);
56
- if (this._lastBlock.height !== last) {
57
- this._lastBlock = {
58
- height: last,
59
- lastId: hash[prev] && hash[prev].length ? hash[prev][0].id : '',
60
- transactions: hash[last]
61
- };
62
- }
63
- else {
64
- this._lastBlock.transactions.push(...toDispatch);
65
- }
66
- if (toDispatch.length) {
67
- this._emitter.trigger('change-state', toDispatch);
68
- }
69
- }
70
- this._addTimeout();
71
- }, onError);
72
- })
73
- .catch(onError);
74
- }
75
- getTransactionsInHeight(from, limit) {
76
- const height = from.height;
77
- const loop = (downloaded) => {
78
- if (downloaded.length >= limit) {
79
- return Promise.resolve(downloaded);
80
- }
81
- return fetchTransactions(this._base, this.address, downloaded.length + 100).then(list => {
82
- if (downloaded.length === list.length) {
83
- return downloaded;
84
- }
85
- const hash = Watch._groupByHeight(list);
86
- const heightList = keys(hash)
87
- .map(Number)
88
- .sort((a, b) => b - a);
89
- const [last, prev] = heightList;
90
- if (last === height) {
91
- return prev ? [...hash[last], hash[prev][0]] : loop(list);
92
- }
93
- else {
94
- return loop(list);
95
- }
96
- });
97
- };
98
- return loop([from]);
99
- }
100
- _addTimeout() {
101
- this._timer = setTimeout(() => {
102
- this._run();
103
- }, this._interval);
104
- }
105
- static _groupByHeight(list) {
106
- return list.reduce((hash, tx) => {
107
- if (!hash[tx.height]) {
108
- hash[tx.height] = [tx];
109
- }
110
- else {
111
- hash[tx.height].push(tx);
112
- }
113
- return hash;
114
- }, Object.create(null));
115
- }
116
- static _getTransactionsToDispatch(list, dispatched, lastId) {
117
- const result = [];
118
- for (let i = 0; i < list.length; i++) {
119
- const tx = list[i];
120
- if (tx.id === lastId) {
121
- break;
122
- }
123
- if (!dispatched[tx.id]) {
124
- result.push(tx);
125
- }
126
- }
127
- return result;
128
- }
129
- }
130
- export default function (base, address, interval) {
131
- return fetchTransactions(base, address, 1)
132
- .then(([tx]) => new Watch(base, address, tx, interval));
133
- }
1
+ import { fetchTransactions } from '../../api-node/transactions';
2
+ import { indexBy, keys, prop } from '../utils';
3
+ import { EventEmitter } from 'typed-ts-events';
4
+ export class Watch {
5
+ constructor(base, address, tx, interval) {
6
+ this._emitter = new EventEmitter();
7
+ this._timer = null;
8
+ this.address = address;
9
+ this._interval = interval || 1000;
10
+ this._base = base;
11
+ this._lastBlock = {
12
+ lastId: (tx === null || tx === void 0 ? void 0 : tx.id) || '',
13
+ height: (tx === null || tx === void 0 ? void 0 : tx.height) || 0,
14
+ transactions: tx ? [tx] : []
15
+ };
16
+ this._addTimeout();
17
+ }
18
+ on(event, handler) {
19
+ this._emitter.on(event, handler);
20
+ }
21
+ once(event, handler) {
22
+ this._emitter.once(event, handler);
23
+ }
24
+ off(event, handler) {
25
+ this._emitter.off(event, handler);
26
+ }
27
+ _run() {
28
+ if (this._timer) {
29
+ clearTimeout(this._timer);
30
+ }
31
+ const onError = () => this._addTimeout();
32
+ fetchTransactions(this._base, this.address, 1)
33
+ .then(([tx]) => {
34
+ if (!tx) {
35
+ this._addTimeout();
36
+ return null;
37
+ }
38
+ this.getTransactionsInHeight(tx, 310)
39
+ .then(list => {
40
+ const hash = Watch._groupByHeight(list);
41
+ const heightList = keys(hash)
42
+ .map(Number)
43
+ .sort((a, b) => b - a);
44
+ const [last, prev] = heightList;
45
+ if (!this._lastBlock.height) {
46
+ this._lastBlock = {
47
+ height: last,
48
+ lastId: hash[prev] && hash[prev].length ? hash[prev][0].id : '',
49
+ transactions: hash[last]
50
+ };
51
+ this._emitter.trigger('change-state', list);
52
+ }
53
+ else {
54
+ const wasDispatchHash = indexBy(prop('id'), this._lastBlock.transactions);
55
+ const toDispatch = Watch._getTransactionsToDispatch([...hash[last], ...(hash[prev] || [])], wasDispatchHash, this._lastBlock.lastId);
56
+ if (this._lastBlock.height !== last) {
57
+ this._lastBlock = {
58
+ height: last,
59
+ lastId: hash[prev] && hash[prev].length ? hash[prev][0].id : '',
60
+ transactions: hash[last]
61
+ };
62
+ }
63
+ else {
64
+ this._lastBlock.transactions.push(...toDispatch);
65
+ }
66
+ if (toDispatch.length) {
67
+ this._emitter.trigger('change-state', toDispatch);
68
+ }
69
+ }
70
+ this._addTimeout();
71
+ }, onError);
72
+ })
73
+ .catch(onError);
74
+ }
75
+ getTransactionsInHeight(from, limit) {
76
+ const height = from.height;
77
+ const loop = (downloaded) => {
78
+ if (downloaded.length >= limit) {
79
+ return Promise.resolve(downloaded);
80
+ }
81
+ return fetchTransactions(this._base, this.address, downloaded.length + 100).then(list => {
82
+ if (downloaded.length === list.length) {
83
+ return downloaded;
84
+ }
85
+ const hash = Watch._groupByHeight(list);
86
+ const heightList = keys(hash)
87
+ .map(Number)
88
+ .sort((a, b) => b - a);
89
+ const [last, prev] = heightList;
90
+ if (last === height) {
91
+ return prev ? [...hash[last], hash[prev][0]] : loop(list);
92
+ }
93
+ else {
94
+ return loop(list);
95
+ }
96
+ });
97
+ };
98
+ return loop([from]);
99
+ }
100
+ _addTimeout() {
101
+ this._timer = setTimeout(() => {
102
+ this._run();
103
+ }, this._interval);
104
+ }
105
+ static _groupByHeight(list) {
106
+ return list.reduce((hash, tx) => {
107
+ if (!hash[tx.height]) {
108
+ hash[tx.height] = [tx];
109
+ }
110
+ else {
111
+ hash[tx.height].push(tx);
112
+ }
113
+ return hash;
114
+ }, Object.create(null));
115
+ }
116
+ static _getTransactionsToDispatch(list, dispatched, lastId) {
117
+ const result = [];
118
+ for (let i = 0; i < list.length; i++) {
119
+ const tx = list[i];
120
+ if (tx.id === lastId) {
121
+ break;
122
+ }
123
+ if (!dispatched[tx.id]) {
124
+ result.push(tx);
125
+ }
126
+ }
127
+ return result;
128
+ }
129
+ }
130
+ export default function (base, address, interval) {
131
+ return fetchTransactions(base, address, 1)
132
+ .then(([tx]) => new Watch(base, address, tx, interval));
133
+ }
134
134
  //# sourceMappingURL=watch.js.map
@@ -1 +1 @@
1
- export default function wavesAddress2eth(wavesAddress: string): string;
1
+ export default function wavesAddress2eth(wavesAddress: string): string;
@@ -1,7 +1,7 @@
1
- import { base16Encode, base58Decode } from '@waves/ts-lib-crypto';
2
- export default function wavesAddress2eth(wavesAddress) {
3
- const rawBytes = base58Decode(wavesAddress);
4
- const bytes = rawBytes.slice(2, rawBytes.byteLength - 4);
5
- return `0x${base16Encode(bytes)}`;
6
- }
1
+ import { base16Encode, base58Decode } from '@waves/ts-lib-crypto';
2
+ export default function wavesAddress2eth(wavesAddress) {
3
+ const rawBytes = base58Decode(wavesAddress);
4
+ const bytes = rawBytes.slice(2, rawBytes.byteLength - 4);
5
+ return `0x${base16Encode(bytes)}`;
6
+ }
7
7
  //# sourceMappingURL=wavesAddress2eth.js.map
@@ -1 +1 @@
1
- export default function wavesAsset2Eth(wavesAsset: string): string;
1
+ export default function wavesAsset2Eth(wavesAsset: string): string;
@@ -1,7 +1,7 @@
1
- import { base16Encode, base58Decode } from '@waves/ts-lib-crypto';
2
- export default function wavesAsset2Eth(wavesAsset) {
3
- const rawBytes = base58Decode(wavesAsset);
4
- const bytes = rawBytes.slice(0, 20);
5
- return `0x${base16Encode(bytes)}`;
6
- }
1
+ import { base16Encode, base58Decode } from '@waves/ts-lib-crypto';
2
+ export default function wavesAsset2Eth(wavesAsset) {
3
+ const rawBytes = base58Decode(wavesAsset);
4
+ const bytes = rawBytes.slice(0, 20);
5
+ return `0x${base16Encode(bytes)}`;
6
+ }
7
7
  //# sourceMappingURL=wavesAsset2eth.js.map
@@ -1 +1 @@
1
- export default function (base: string): Promise<number>;
1
+ export default function (base: string): Promise<number>;
@@ -1,9 +1,9 @@
1
- import { fetchHeadersAt, fetchHeadersLast } from '../../api-node/blocks';
2
- export default function (base) {
3
- return fetchHeadersLast(base).then(header => {
4
- const firstHeight = Math.max(2, header.height - 1000);
5
- return fetchHeadersAt(base, firstHeight)
6
- .then(oldHeader => Math.floor((header.timestamp - oldHeader.timestamp) / (header.height - firstHeight)));
7
- });
8
- }
1
+ import { fetchHeadersAt, fetchHeadersLast } from '../../api-node/blocks';
2
+ export default function (base) {
3
+ return fetchHeadersLast(base).then(header => {
4
+ const firstHeight = Math.max(2, header.height - 1000);
5
+ return fetchHeadersAt(base, firstHeight)
6
+ .then(oldHeader => Math.floor((header.timestamp - oldHeader.timestamp) / (header.height - firstHeight)));
7
+ });
8
+ }
9
9
  //# sourceMappingURL=detectInterval.js.map
@@ -1 +1 @@
1
- export default function (base: string): Promise<number>;
1
+ export default function (base: string): Promise<number>;
@@ -1,51 +1,51 @@
1
- import { fetchHeadersLast } from '../../api-node/blocks';
2
- export default function (base) {
3
- return fetchHeadersLast(base).then(header => base58Decode(header.generator)[1]);
4
- }
5
- const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
6
- const ALPHABET_MAP = {};
7
- for (let i = 0; i < ALPHABET.length; i++) {
8
- ALPHABET_MAP[ALPHABET.charAt(i)] = i;
9
- }
10
- function base58Decode(string) {
11
- let bytes, c, carry, j, i;
12
- if (string.length === 0) {
13
- return new Uint8Array(0);
14
- }
15
- i = void 0;
16
- j = void 0;
17
- bytes = [0];
18
- i = 0;
19
- while (i < string.length) {
20
- c = string[i];
21
- if (!(c in ALPHABET_MAP)) {
22
- throw 'Base58.decode received unacceptable input. Character \'' + c + '\' is not in the Base58 alphabet.';
23
- }
24
- j = 0;
25
- while (j < bytes.length) {
26
- bytes[j] *= 58;
27
- j++;
28
- }
29
- bytes[0] += ALPHABET_MAP[c];
30
- carry = 0;
31
- j = 0;
32
- while (j < bytes.length) {
33
- bytes[j] += carry;
34
- carry = bytes[j] >> 8;
35
- bytes[j] &= 0xff;
36
- ++j;
37
- }
38
- while (carry) {
39
- bytes.push(carry & 0xff);
40
- carry >>= 8;
41
- }
42
- i++;
43
- }
44
- i = 0;
45
- while (string[i] === '1' && i < string.length - 1) {
46
- bytes.push(0);
47
- i++;
48
- }
49
- return new Uint8Array(bytes.reverse());
50
- }
1
+ import { fetchHeadersLast } from '../../api-node/blocks';
2
+ export default function (base) {
3
+ return fetchHeadersLast(base).then(header => base58Decode(header.generator)[1]);
4
+ }
5
+ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
6
+ const ALPHABET_MAP = {};
7
+ for (let i = 0; i < ALPHABET.length; i++) {
8
+ ALPHABET_MAP[ALPHABET.charAt(i)] = i;
9
+ }
10
+ function base58Decode(string) {
11
+ let bytes, c, carry, j, i;
12
+ if (string.length === 0) {
13
+ return new Uint8Array(0);
14
+ }
15
+ i = void 0;
16
+ j = void 0;
17
+ bytes = [0];
18
+ i = 0;
19
+ while (i < string.length) {
20
+ c = string[i];
21
+ if (!(c in ALPHABET_MAP)) {
22
+ throw 'Base58.decode received unacceptable input. Character \'' + c + '\' is not in the Base58 alphabet.';
23
+ }
24
+ j = 0;
25
+ while (j < bytes.length) {
26
+ bytes[j] *= 58;
27
+ j++;
28
+ }
29
+ bytes[0] += ALPHABET_MAP[c];
30
+ carry = 0;
31
+ j = 0;
32
+ while (j < bytes.length) {
33
+ bytes[j] += carry;
34
+ carry = bytes[j] >> 8;
35
+ bytes[j] &= 0xff;
36
+ ++j;
37
+ }
38
+ while (carry) {
39
+ bytes.push(carry & 0xff);
40
+ carry >>= 8;
41
+ }
42
+ i++;
43
+ }
44
+ i = 0;
45
+ while (string[i] === '1' && i < string.length - 1) {
46
+ bytes.push(0);
47
+ i++;
48
+ }
49
+ return new Uint8Array(bytes.reverse());
50
+ }
51
51
  //# sourceMappingURL=getNetworkByte.js.map
@@ -1 +1 @@
1
- export default function (base: string): Promise<string>;
1
+ export default function (base: string): Promise<string>;
@@ -1,5 +1,5 @@
1
- import getNetworkByte from './getNetworkByte';
2
- export default function (base) {
3
- return getNetworkByte(base).then(byte => String.fromCharCode(byte));
4
- }
1
+ import getNetworkByte from './getNetworkByte';
2
+ export default function (base) {
3
+ return getNetworkByte(base).then(byte => String.fromCharCode(byte));
4
+ }
5
5
  //# sourceMappingURL=getNetworkCode.js.map
@@ -1,3 +1,3 @@
1
- export default function (base: string, current?: number): Promise<{
2
- height: number;
3
- }>;
1
+ export default function (base: string, current?: number): Promise<{
2
+ height: number;
3
+ }>;
@@ -1,36 +1,36 @@
1
- import { fetchHeadersLast, fetchHeight } from '../../api-node/blocks';
2
- import { wait } from '../utils';
3
- import detectInterval from './detectInterval';
4
- const storage = Object.create(null);
5
- export default function (base, current) {
6
- return Promise.all([
7
- getInterval(base),
8
- current == undefined ? fetchHeight(base).then(({ height }) => height + 1) : current
9
- ]).then(([interval, current]) => loop(interval, current));
10
- function loop(interval, current) {
11
- return fetchHeadersLast(base).then(({ height, timestamp }) => {
12
- if (height >= current) {
13
- return { height };
14
- }
15
- const blocksToWait = current - height;
16
- const now = Date.now();
17
- const timeout = (((blocksToWait - 1) * interval) + ((interval - Math.abs(now - timestamp)))) * 0.8;
18
- return wait(inRange(timeout, 200, (interval * blocksToWait) * 0.8)).then(() => loop(interval, current));
19
- });
20
- }
21
- }
22
- function inRange(current, min, max) {
23
- return Math.round(Math.min(Math.max(current, min), max));
24
- }
25
- function getInterval(base) {
26
- if (storage[base]) {
27
- return Promise.resolve(storage[base]);
28
- }
29
- else {
30
- return detectInterval(base).then(interval => {
31
- storage[base] = interval;
32
- return interval;
33
- });
34
- }
35
- }
1
+ import { fetchHeadersLast, fetchHeight } from '../../api-node/blocks';
2
+ import { wait } from '../utils';
3
+ import detectInterval from './detectInterval';
4
+ const storage = Object.create(null);
5
+ export default function (base, current) {
6
+ return Promise.all([
7
+ getInterval(base),
8
+ current == undefined ? fetchHeight(base).then(({ height }) => height + 1) : current
9
+ ]).then(([interval, current]) => loop(interval, current));
10
+ function loop(interval, current) {
11
+ return fetchHeadersLast(base).then(({ height, timestamp }) => {
12
+ if (height >= current) {
13
+ return { height };
14
+ }
15
+ const blocksToWait = current - height;
16
+ const now = Date.now();
17
+ const timeout = (((blocksToWait - 1) * interval) + ((interval - Math.abs(now - timestamp)))) * 0.8;
18
+ return wait(inRange(timeout, 200, (interval * blocksToWait) * 0.8)).then(() => loop(interval, current));
19
+ });
20
+ }
21
+ }
22
+ function inRange(current, min, max) {
23
+ return Math.round(Math.min(Math.max(current, min), max));
24
+ }
25
+ function getInterval(base) {
26
+ if (storage[base]) {
27
+ return Promise.resolve(storage[base]);
28
+ }
29
+ else {
30
+ return detectInterval(base).then(interval => {
31
+ storage[base] = interval;
32
+ return interval;
33
+ });
34
+ }
35
+ }
36
36
  //# sourceMappingURL=waitHeight.js.map
@@ -1 +1 @@
1
- export default function (json: string): any;
1
+ export default function (json: string): any;
package/es/tools/parse.js CHANGED
@@ -1,5 +1,5 @@
1
- const reg = new RegExp('((?!\\\\)"\\w+"):\\s*(-?[\\d|\\.]{14,})', 'g');
2
- export default function (json) {
3
- return JSON.parse(json.replace(reg, `$1:"$2"`));
4
- }
1
+ const reg = new RegExp('((?!\\\\)"\\w+"):\\s*(-?[\\d|\\.]{14,})', 'g');
2
+ export default function (json) {
3
+ return JSON.parse(json.replace(reg, `$1:"$2"`));
4
+ }
5
5
  //# sourceMappingURL=parse.js.map
@@ -1,4 +1,4 @@
1
- export default function <T extends Record<string, any>>(params: T, evolver?: TEvolver<T>): string;
2
- export declare type TEvolver<T extends Record<string, any>> = {
3
- [Key in keyof T]?: (value: T[Key]) => string | undefined;
4
- };
1
+ export default function <T extends Record<string, any>>(params: T, evolver?: TEvolver<T>): string;
2
+ export declare type TEvolver<T extends Record<string, any>> = {
3
+ [Key in keyof T]?: (value: T[Key]) => string | undefined;
4
+ };
package/es/tools/query.js CHANGED
@@ -1,12 +1,12 @@
1
- import { toArray } from "./utils";
2
- export default function (params, evolver = Object.create(null)) {
3
- const query = Object.keys(params)
4
- .map(key => [key, params[key]])
5
- .map(([key, value]) => [key, Object.prototype.hasOwnProperty.call(evolver, key) ? evolver[key](value) : value])
6
- .filter(([key, value]) => value != null)
7
- .map(([key, value]) => toArray(value).map(v => `${key}=${v}`).join('&'))
8
- .join('&');
9
- return query.length ? `?${query}` : '';
10
- }
11
- ;
1
+ import { toArray } from "./utils";
2
+ export default function (params, evolver = Object.create(null)) {
3
+ const query = Object.keys(params)
4
+ .map(key => [key, params[key]])
5
+ .map(([key, value]) => [key, Object.prototype.hasOwnProperty.call(evolver, key) ? evolver[key](value) : value])
6
+ .filter(([key, value]) => value != null)
7
+ .map(([key, value]) => toArray(value).map(v => `${key}=${v}`).join('&'))
8
+ .join('&');
9
+ return query.length ? `?${query}` : '';
10
+ }
11
+ ;
12
12
  //# sourceMappingURL=query.js.map