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

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 (165) 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/alias/index.d.ts +6 -6
  7. package/cjs/api-node/alias/index.js +21 -21
  8. package/cjs/api-node/assets/index.d.ts +79 -79
  9. package/cjs/api-node/assets/index.js +171 -171
  10. package/cjs/api-node/blocks/index.d.ts +143 -143
  11. package/cjs/api-node/blocks/index.js +209 -209
  12. package/cjs/api-node/debug/index.d.ts +189 -189
  13. package/cjs/api-node/debug/index.js +244 -244
  14. package/cjs/api-node/eth/index.d.ts +3 -3
  15. package/cjs/api-node/eth/index.js +14 -14
  16. package/cjs/api-node/leasing/index.d.ts +22 -22
  17. package/cjs/api-node/leasing/index.js +41 -41
  18. package/cjs/api-node/node/index.d.ts +11 -11
  19. package/cjs/api-node/node/index.js +19 -19
  20. package/cjs/api-node/peers/index.d.ts +46 -46
  21. package/cjs/api-node/peers/index.js +59 -59
  22. package/cjs/api-node/rewards/index.d.ts +21 -21
  23. package/cjs/api-node/rewards/index.js +20 -20
  24. package/cjs/api-node/transactions/index.d.ts +73 -73
  25. package/cjs/api-node/transactions/index.js +192 -192
  26. package/cjs/api-node/utils/index.d.ts +110 -110
  27. package/cjs/api-node/utils/index.js +210 -210
  28. package/cjs/api-node/wallet/index.d.ts +5 -5
  29. package/cjs/api-node/wallet/index.js +6 -6
  30. package/cjs/constants.d.ts +40 -40
  31. package/cjs/constants.js +42 -42
  32. package/cjs/create.d.ts +1238 -1238
  33. package/cjs/create.js +115 -115
  34. package/cjs/index.d.ts +9 -9
  35. package/cjs/index.js +17 -17
  36. package/cjs/interface.d.ts +44 -44
  37. package/cjs/interface.js +9 -9
  38. package/cjs/tools/adresses/availableSponsoredBalances.d.ts +7 -7
  39. package/cjs/tools/adresses/availableSponsoredBalances.js +29 -29
  40. package/cjs/tools/adresses/ethAddress2waves.d.ts +1 -1
  41. package/cjs/tools/adresses/ethAddress2waves.js +46 -46
  42. package/cjs/tools/adresses/getAssetIdListByTx.d.ts +2 -2
  43. package/cjs/tools/adresses/getAssetIdListByTx.js +47 -47
  44. package/cjs/tools/adresses/getAssetsByTransaction.d.ts +3 -3
  45. package/cjs/tools/adresses/getAssetsByTransaction.js +13 -13
  46. package/cjs/tools/adresses/getTransactionsWithAssets.d.ts +6 -6
  47. package/cjs/tools/adresses/getTransactionsWithAssets.js +12 -12
  48. package/cjs/tools/adresses/watch.d.ts +24 -24
  49. package/cjs/tools/adresses/watch.js +167 -167
  50. package/cjs/tools/adresses/wavesAddress2eth.d.ts +1 -1
  51. package/cjs/tools/adresses/wavesAddress2eth.js +9 -9
  52. package/cjs/tools/assets/wavesAsset2eth.d.ts +1 -1
  53. package/cjs/tools/assets/wavesAsset2eth.js +9 -9
  54. package/cjs/tools/blocks/detectInterval.d.ts +1 -1
  55. package/cjs/tools/blocks/detectInterval.js +11 -11
  56. package/cjs/tools/blocks/getNetworkByte.d.ts +1 -1
  57. package/cjs/tools/blocks/getNetworkByte.js +53 -53
  58. package/cjs/tools/blocks/getNetworkCode.d.ts +1 -1
  59. package/cjs/tools/blocks/getNetworkCode.js +10 -10
  60. package/cjs/tools/blocks/waitHeight.d.ts +3 -3
  61. package/cjs/tools/blocks/waitHeight.js +64 -64
  62. package/cjs/tools/parse.d.ts +1 -1
  63. package/cjs/tools/parse.js +7 -7
  64. package/cjs/tools/query.d.ts +4 -4
  65. package/cjs/tools/query.js +40 -40
  66. package/cjs/tools/request.d.ts +64 -64
  67. package/cjs/tools/request.js +41 -41
  68. package/cjs/tools/resolve.d.ts +1 -1
  69. package/cjs/tools/resolve.js +6 -6
  70. package/cjs/tools/stringify.d.ts +1 -1
  71. package/cjs/tools/stringify.js +20 -20
  72. package/cjs/tools/transactions/broadcast.d.ts +14 -14
  73. package/cjs/tools/transactions/broadcast.js +59 -59
  74. package/cjs/tools/transactions/ethTxId2waves.d.ts +1 -1
  75. package/cjs/tools/transactions/ethTxId2waves.js +10 -10
  76. package/cjs/tools/transactions/wait.d.ts +10 -10
  77. package/cjs/tools/transactions/wait.js +41 -41
  78. package/cjs/tools/utils.d.ts +32 -32
  79. package/cjs/tools/utils.js +117 -117
  80. package/dist/node-api.js +2300 -2300
  81. package/es/api-node/activation/index.d.ts +21 -21
  82. package/es/api-node/activation/index.js +12 -12
  83. package/es/api-node/addresses/index.d.ts +81 -81
  84. package/es/api-node/addresses/index.js +110 -110
  85. package/es/api-node/alias/index.d.ts +6 -6
  86. package/es/api-node/alias/index.js +13 -13
  87. package/es/api-node/assets/index.d.ts +79 -79
  88. package/es/api-node/assets/index.js +102 -102
  89. package/es/api-node/blocks/index.d.ts +143 -143
  90. package/es/api-node/blocks/index.js +178 -178
  91. package/es/api-node/debug/index.d.ts +189 -189
  92. package/es/api-node/debug/index.js +200 -200
  93. package/es/api-node/eth/index.d.ts +3 -3
  94. package/es/api-node/eth/index.js +7 -7
  95. package/es/api-node/leasing/index.d.ts +22 -22
  96. package/es/api-node/leasing/index.js +21 -21
  97. package/es/api-node/node/index.d.ts +11 -11
  98. package/es/api-node/node/index.js +9 -9
  99. package/es/api-node/peers/index.d.ts +46 -46
  100. package/es/api-node/peers/index.js +45 -45
  101. package/es/api-node/rewards/index.d.ts +21 -21
  102. package/es/api-node/rewards/index.js +12 -12
  103. package/es/api-node/transactions/index.d.ts +73 -73
  104. package/es/api-node/transactions/index.js +136 -136
  105. package/es/api-node/utils/index.d.ts +110 -110
  106. package/es/api-node/utils/index.js +192 -192
  107. package/es/api-node/wallet/index.d.ts +5 -5
  108. package/es/api-node/wallet/index.js +6 -6
  109. package/es/constants.d.ts +40 -40
  110. package/es/constants.js +39 -39
  111. package/es/create.d.ts +1238 -1238
  112. package/es/create.js +89 -89
  113. package/es/index.d.ts +9 -9
  114. package/es/index.js +8 -8
  115. package/es/interface.d.ts +44 -44
  116. package/es/interface.js +2 -2
  117. package/es/tools/adresses/availableSponsoredBalances.d.ts +7 -7
  118. package/es/tools/adresses/availableSponsoredBalances.js +26 -26
  119. package/es/tools/adresses/ethAddress2waves.d.ts +1 -1
  120. package/es/tools/adresses/ethAddress2waves.js +30 -30
  121. package/es/tools/adresses/getAssetIdListByTx.d.ts +2 -2
  122. package/es/tools/adresses/getAssetIdListByTx.js +23 -23
  123. package/es/tools/adresses/getAssetsByTransaction.d.ts +3 -3
  124. package/es/tools/adresses/getAssetsByTransaction.js +7 -7
  125. package/es/tools/adresses/getTransactionsWithAssets.d.ts +6 -6
  126. package/es/tools/adresses/getTransactionsWithAssets.js +6 -6
  127. package/es/tools/adresses/watch.d.ts +24 -24
  128. package/es/tools/adresses/watch.js +133 -133
  129. package/es/tools/adresses/wavesAddress2eth.d.ts +1 -1
  130. package/es/tools/adresses/wavesAddress2eth.js +6 -6
  131. package/es/tools/assets/wavesAsset2eth.d.ts +1 -1
  132. package/es/tools/assets/wavesAsset2eth.js +6 -6
  133. package/es/tools/blocks/detectInterval.d.ts +1 -1
  134. package/es/tools/blocks/detectInterval.js +8 -8
  135. package/es/tools/blocks/getNetworkByte.d.ts +1 -1
  136. package/es/tools/blocks/getNetworkByte.js +50 -50
  137. package/es/tools/blocks/getNetworkCode.d.ts +1 -1
  138. package/es/tools/blocks/getNetworkCode.js +4 -4
  139. package/es/tools/blocks/waitHeight.d.ts +3 -3
  140. package/es/tools/blocks/waitHeight.js +35 -35
  141. package/es/tools/parse.d.ts +1 -1
  142. package/es/tools/parse.js +4 -4
  143. package/es/tools/query.d.ts +4 -4
  144. package/es/tools/query.js +11 -11
  145. package/es/tools/request.d.ts +64 -64
  146. package/es/tools/request.js +21 -21
  147. package/es/tools/resolve.d.ts +1 -1
  148. package/es/tools/resolve.js +3 -3
  149. package/es/tools/stringify.d.ts +1 -1
  150. package/es/tools/stringify.js +17 -17
  151. package/es/tools/transactions/broadcast.d.ts +14 -14
  152. package/es/tools/transactions/broadcast.js +42 -42
  153. package/es/tools/transactions/ethTxId2waves.d.ts +1 -1
  154. package/es/tools/transactions/ethTxId2waves.js +7 -7
  155. package/es/tools/transactions/wait.d.ts +10 -10
  156. package/es/tools/transactions/wait.js +38 -38
  157. package/es/tools/utils.d.ts +32 -32
  158. package/es/tools/utils.js +72 -72
  159. package/package.json +66 -66
  160. package/cjs/api-node/consensus/index.d.ts +0 -39
  161. package/cjs/api-node/consensus/index.js +0 -37
  162. package/cjs/api-node/consensus/index.js.map +0 -1
  163. package/es/api-node/consensus/index.d.ts +0 -39
  164. package/es/api-node/consensus/index.js +0 -27
  165. package/es/api-node/consensus/index.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