@ethersphere/bee-js 6.9.0 → 7.0.0

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 (144) hide show
  1. package/README.md +107 -65
  2. package/dist/cjs/bee.js +533 -6
  3. package/dist/cjs/chunk/cac.js +3 -3
  4. package/dist/cjs/chunk/soc.js +5 -5
  5. package/dist/cjs/chunk/span.js +2 -6
  6. package/dist/cjs/feed/identifier.js +2 -2
  7. package/dist/cjs/feed/index.js +7 -8
  8. package/dist/cjs/feed/retrievable.js +2 -2
  9. package/dist/cjs/index.js +1 -3
  10. package/dist/cjs/modules/bytes.js +3 -3
  11. package/dist/cjs/modules/bzz.js +9 -20
  12. package/dist/cjs/modules/chunk.js +2 -2
  13. package/dist/cjs/modules/debug/balance.js +4 -4
  14. package/dist/cjs/modules/debug/chequebook.js +8 -8
  15. package/dist/cjs/modules/debug/chunk.js +2 -19
  16. package/dist/cjs/modules/debug/settlements.js +2 -2
  17. package/dist/cjs/modules/debug/stake.js +3 -3
  18. package/dist/cjs/modules/debug/states.js +4 -19
  19. package/dist/cjs/modules/debug/status.js +15 -32
  20. package/dist/cjs/modules/debug/tag.js +1 -1
  21. package/dist/cjs/modules/debug/transactions.js +4 -4
  22. package/dist/cjs/modules/feed.js +6 -7
  23. package/dist/cjs/modules/pinning.js +4 -4
  24. package/dist/cjs/modules/pss.js +1 -1
  25. package/dist/cjs/modules/soc.js +1 -1
  26. package/dist/cjs/modules/status.js +1 -1
  27. package/dist/cjs/modules/stewardship.js +1 -1
  28. package/dist/cjs/package.json +4 -0
  29. package/dist/cjs/types/index.js +5 -1
  30. package/dist/cjs/utils/collection.js +7 -22
  31. package/dist/cjs/utils/collection.node.js +2 -1
  32. package/dist/cjs/utils/data.browser.js +1 -49
  33. package/dist/cjs/utils/error.js +2 -6
  34. package/dist/cjs/utils/eth.js +1 -1
  35. package/dist/cjs/utils/expose.js +1 -8
  36. package/dist/cjs/utils/file.js +2 -2
  37. package/dist/cjs/utils/http.js +6 -25
  38. package/dist/cjs/utils/tar-uploader.browser.js +26 -0
  39. package/dist/cjs/utils/tar-uploader.js +27 -0
  40. package/dist/cjs/utils/tar-writer.browser.js +17 -0
  41. package/dist/cjs/utils/tar-writer.js +21 -0
  42. package/dist/cjs/utils/tar.browser.js +65 -0
  43. package/dist/cjs/utils/tar.js +47 -21
  44. package/dist/cjs/utils/type.js +7 -3
  45. package/dist/cjs/utils/url.js +1 -6
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +0 -42
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee.js +533 -9
  50. package/dist/mjs/chunk/cac.js +4 -4
  51. package/dist/mjs/chunk/soc.js +6 -6
  52. package/dist/mjs/chunk/span.js +2 -6
  53. package/dist/mjs/feed/identifier.js +2 -2
  54. package/dist/mjs/feed/index.js +7 -11
  55. package/dist/mjs/feed/retrievable.js +2 -2
  56. package/dist/mjs/index.js +1 -2
  57. package/dist/mjs/modules/bytes.js +3 -3
  58. package/dist/mjs/modules/bzz.js +8 -20
  59. package/dist/mjs/modules/chunk.js +2 -2
  60. package/dist/mjs/modules/debug/balance.js +4 -4
  61. package/dist/mjs/modules/debug/chequebook.js +8 -8
  62. package/dist/mjs/modules/debug/chunk.js +1 -17
  63. package/dist/mjs/modules/debug/settlements.js +2 -2
  64. package/dist/mjs/modules/debug/stake.js +3 -3
  65. package/dist/mjs/modules/debug/states.js +4 -19
  66. package/dist/mjs/modules/debug/status.js +15 -34
  67. package/dist/mjs/modules/debug/tag.js +1 -1
  68. package/dist/mjs/modules/debug/transactions.js +4 -4
  69. package/dist/mjs/modules/feed.js +6 -7
  70. package/dist/mjs/modules/pinning.js +4 -4
  71. package/dist/mjs/modules/pss.js +1 -1
  72. package/dist/mjs/modules/soc.js +1 -1
  73. package/dist/mjs/modules/status.js +1 -1
  74. package/dist/mjs/modules/stewardship.js +1 -1
  75. package/dist/mjs/package.json +6 -2
  76. package/dist/mjs/types/index.js +4 -0
  77. package/dist/mjs/utils/collection.js +7 -22
  78. package/dist/mjs/utils/collection.node.js +2 -1
  79. package/dist/mjs/utils/data.browser.js +0 -57
  80. package/dist/mjs/utils/error.js +2 -6
  81. package/dist/mjs/utils/eth.js +1 -1
  82. package/dist/mjs/utils/expose.js +0 -1
  83. package/dist/mjs/utils/http.js +5 -2
  84. package/dist/mjs/utils/tar-uploader.browser.js +22 -0
  85. package/dist/mjs/utils/tar-uploader.js +23 -0
  86. package/dist/mjs/utils/tar-writer.browser.js +12 -0
  87. package/dist/mjs/utils/tar-writer.js +16 -0
  88. package/dist/mjs/utils/tar.browser.js +61 -0
  89. package/dist/mjs/utils/tar.js +45 -16
  90. package/dist/mjs/utils/type.js +4 -1
  91. package/dist/mjs/utils/url.js +1 -6
  92. package/dist/types/bee.d.ts +305 -4
  93. package/dist/types/chunk/soc.d.ts +2 -2
  94. package/dist/types/feed/identifier.d.ts +1 -1
  95. package/dist/types/feed/index.d.ts +1 -1
  96. package/dist/types/index.d.ts +1 -3
  97. package/dist/types/modules/bytes.d.ts +3 -3
  98. package/dist/types/modules/bzz.d.ts +14 -6
  99. package/dist/types/modules/chunk.d.ts +2 -2
  100. package/dist/types/modules/debug/balance.d.ts +4 -4
  101. package/dist/types/modules/debug/chequebook.d.ts +8 -8
  102. package/dist/types/modules/debug/chunk.d.ts +1 -10
  103. package/dist/types/modules/debug/settlements.d.ts +2 -2
  104. package/dist/types/modules/debug/stake.d.ts +3 -3
  105. package/dist/types/modules/debug/states.d.ts +3 -3
  106. package/dist/types/modules/debug/status.d.ts +10 -20
  107. package/dist/types/modules/debug/tag.d.ts +1 -1
  108. package/dist/types/modules/debug/transactions.d.ts +4 -4
  109. package/dist/types/modules/feed.d.ts +6 -9
  110. package/dist/types/modules/pinning.d.ts +4 -4
  111. package/dist/types/modules/pss.d.ts +1 -1
  112. package/dist/types/modules/soc.d.ts +1 -1
  113. package/dist/types/modules/status.d.ts +1 -1
  114. package/dist/types/modules/stewardship.d.ts +1 -1
  115. package/dist/types/types/debug.d.ts +0 -3
  116. package/dist/types/types/index.d.ts +9 -17
  117. package/dist/types/utils/collection.browser.d.ts +1 -1
  118. package/dist/types/utils/collection.d.ts +3 -3
  119. package/dist/types/utils/collection.node.d.ts +1 -1
  120. package/dist/types/utils/data.browser.d.ts +0 -7
  121. package/dist/types/utils/data.d.ts +1 -2
  122. package/dist/types/utils/error.d.ts +2 -7
  123. package/dist/types/utils/eth.d.ts +1 -1
  124. package/dist/types/utils/expose.d.ts +0 -1
  125. package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
  126. package/dist/types/utils/tar-uploader.d.ts +4 -0
  127. package/dist/types/utils/tar-writer.browser.d.ts +3 -0
  128. package/dist/types/utils/tar-writer.d.ts +3 -0
  129. package/dist/types/utils/tar.browser.d.ts +9 -0
  130. package/dist/types/utils/tar.d.ts +10 -2
  131. package/dist/types/utils/type.d.ts +4 -1
  132. package/package.json +4 -19
  133. package/dist/cjs/bee-debug.js +0 -590
  134. package/dist/cjs/chunk/serialize.js +0 -19
  135. package/dist/cjs/utils/stream.js +0 -146
  136. package/dist/cjs/utils/uint64.js +0 -29
  137. package/dist/mjs/bee-debug.js +0 -560
  138. package/dist/mjs/chunk/serialize.js +0 -15
  139. package/dist/mjs/utils/stream.js +0 -129
  140. package/dist/mjs/utils/uint64.js +0 -22
  141. package/dist/types/bee-debug.d.ts +0 -323
  142. package/dist/types/chunk/serialize.d.ts +0 -6
  143. package/dist/types/utils/stream.d.ts +0 -40
  144. package/dist/types/utils/uint64.d.ts +0 -4
@@ -1,560 +0,0 @@
1
- import * as balance from "./modules/debug/balance.js";
2
- import * as chequebook from "./modules/debug/chequebook.js";
3
- import * as connectivity from "./modules/debug/connectivity.js";
4
- import * as settlements from "./modules/debug/settlements.js";
5
- import * as stake from "./modules/debug/stake.js";
6
- import * as states from "./modules/debug/states.js";
7
- import * as status from "./modules/debug/status.js";
8
- import * as transactions from "./modules/debug/transactions.js";
9
- import { Objects, System } from 'cafe-utility';
10
- import * as stamps from "./modules/debug/stamps.js";
11
- import * as tag from "./modules/debug/tag.js";
12
- import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
13
- import { BeeArgumentError, BeeError } from "./utils/error.js";
14
- import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, assertTransactionOptions, isTag } from "./utils/type.js";
15
- import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
16
- export class BeeDebug {
17
- constructor(url, options) {
18
- assertBeeUrl(url);
19
- // Remove last slash if present, as our endpoint strings starts with `/...`
20
- // which could lead to double slash in URL to which Bee responds with
21
- // unnecessary redirects.
22
- this.url = stripLastSlash(url);
23
- this.requestOptions = {
24
- baseURL: this.url,
25
- timeout: options?.timeout ?? false,
26
- headers: options?.headers,
27
- onRequest: options?.onRequest,
28
- adapter: options?.adapter
29
- };
30
- }
31
- async getNodeAddresses(options) {
32
- assertRequestOptions(options);
33
- return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
34
- }
35
- async getBlocklist(options) {
36
- assertRequestOptions(options);
37
- return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
38
- }
39
- /**
40
- * Retrieve tag extended information from Bee node
41
- *
42
- * @param tagUid UID or tag object to be retrieved
43
- * @throws TypeError if tagUid is in not correct format
44
- *
45
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
46
- * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
47
- *
48
- */
49
- async retrieveExtendedTag(tagUid, options) {
50
- assertRequestOptions(options);
51
- if (isTag(tagUid)) {
52
- tagUid = tagUid.uid;
53
- } else if (typeof tagUid === 'number') {
54
- assertNonNegativeInteger(tagUid, 'UID');
55
- } else {
56
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
57
- }
58
- return tag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
59
- }
60
- /**
61
- * Get list of peers for this node
62
- */
63
- async getPeers(options) {
64
- assertRequestOptions(options);
65
- return connectivity.getPeers(this.getRequestOptionsForCall(options));
66
- }
67
- async removePeer(peer, options) {
68
- assertRequestOptions(options);
69
- assertAddress(peer);
70
- return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
71
- }
72
- async getTopology(options) {
73
- assertRequestOptions(options);
74
- return connectivity.getTopology(this.getRequestOptionsForCall(options));
75
- }
76
- async pingPeer(peer, options) {
77
- assertRequestOptions(options);
78
- assertAddress(peer);
79
- return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
80
- }
81
- /*
82
- * Balance endpoints
83
- */
84
- /**
85
- * Get the balances with all known peers including prepaid services
86
- */
87
- async getAllBalances(options) {
88
- assertRequestOptions(options);
89
- return balance.getAllBalances(this.getRequestOptionsForCall(options));
90
- }
91
- /**
92
- * Get the balances with a specific peer including prepaid services
93
- *
94
- * @param address Swarm address of peer
95
- */
96
- async getPeerBalance(address, options) {
97
- assertRequestOptions(options);
98
- assertAddress(address);
99
- return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
100
- }
101
- /**
102
- * Get the past due consumption balances with all known peers
103
- */
104
- async getPastDueConsumptionBalances(options) {
105
- assertRequestOptions(options);
106
- return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
107
- }
108
- /**
109
- * Get the past due consumption balance with a specific peer
110
- *
111
- * @param address Swarm address of peer
112
- */
113
- async getPastDueConsumptionPeerBalance(address, options) {
114
- assertRequestOptions(options);
115
- assertAddress(address);
116
- return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
117
- }
118
- /*
119
- * Chequebook endpoints
120
- */
121
- /**
122
- * Get the address of the chequebook contract used.
123
- *
124
- * **Warning:** The address is returned with 0x prefix unlike all other calls.
125
- * https://github.com/ethersphere/bee/issues/1443
126
- */
127
- async getChequebookAddress(options) {
128
- assertRequestOptions(options);
129
- return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
130
- }
131
- /**
132
- * Get the balance of the chequebook
133
- */
134
- async getChequebookBalance(options) {
135
- assertRequestOptions(options);
136
- return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
137
- }
138
- /**
139
- * Get last cheques for all peers
140
- */
141
- async getLastCheques(options) {
142
- assertRequestOptions(options);
143
- return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
144
- }
145
- /**
146
- * Get last cheques for the peer
147
- *
148
- * @param address Swarm address of peer
149
- */
150
- async getLastChequesForPeer(address, options) {
151
- assertRequestOptions(options);
152
- assertAddress(address);
153
- return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
154
- }
155
- /**
156
- * Get last cashout action for the peer
157
- *
158
- * @param address Swarm address of peer
159
- */
160
- async getLastCashoutAction(address, options) {
161
- assertRequestOptions(options);
162
- assertAddress(address);
163
- return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
164
- }
165
- /**
166
- * Cashout the last cheque for the peer
167
- *
168
- * @param address Swarm address of peer
169
- * @param options
170
- * @param options.gasPrice Gas price for the cashout transaction in WEI
171
- * @param options.gasLimit Gas limit for the cashout transaction in WEI
172
- */
173
- async cashoutLastCheque(address, options, requestOptions) {
174
- assertCashoutOptions(options);
175
- assertAddress(address);
176
- return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
177
- }
178
- /**
179
- * Deposit tokens from overlay address into chequebook
180
- *
181
- * @param amount Amount of tokens to deposit (must be positive integer)
182
- * @param gasPrice Gas Price in WEI for the transaction call
183
- * @return string Hash of the transaction
184
- */
185
- async depositTokens(amount, gasPrice, options) {
186
- assertRequestOptions(options);
187
- assertNonNegativeInteger(amount);
188
- if (gasPrice) {
189
- assertNonNegativeInteger(gasPrice);
190
- }
191
- return chequebook.depositTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
192
- }
193
- /**
194
- * Withdraw tokens from the chequebook to the overlay address
195
- *
196
- * @param amount Amount of tokens to withdraw (must be positive integer)
197
- * @param gasPrice Gas Price in WEI for the transaction call
198
- * @return string Hash of the transaction
199
- */
200
- async withdrawTokens(amount, gasPrice, options) {
201
- assertRequestOptions(options);
202
- assertNonNegativeInteger(amount);
203
- if (gasPrice) {
204
- assertNonNegativeInteger(gasPrice);
205
- }
206
- return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amount, gasPrice);
207
- }
208
- /*
209
- * Settlements endpoint
210
- */
211
- /**
212
- * Get amount of sent and received from settlements with a peer
213
- *
214
- * @param address Swarm address of peer
215
- */
216
- async getSettlements(address, options) {
217
- assertRequestOptions(options);
218
- assertAddress(address);
219
- return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
220
- }
221
- /**
222
- * Get settlements with all known peers and total amount sent or received
223
- */
224
- async getAllSettlements(options) {
225
- assertRequestOptions(options);
226
- return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
227
- }
228
- /**
229
- * Get status of node
230
- */
231
- async getStatus(options) {
232
- assertRequestOptions(options);
233
- return status.getDebugStatus(this.getRequestOptionsForCall(options));
234
- }
235
- /**
236
- * Get health of node
237
- */
238
- async getHealth(options) {
239
- assertRequestOptions(options);
240
- return status.getHealth(this.getRequestOptionsForCall(options));
241
- }
242
- /**
243
- * Get readiness of node
244
- */
245
- async getReadiness(options) {
246
- assertRequestOptions(options);
247
- return status.getReadiness(this.getRequestOptionsForCall(options));
248
- }
249
- /**
250
- * Get mode information of node
251
- */
252
- async getNodeInfo(options) {
253
- assertRequestOptions(options);
254
- return status.getNodeInfo(this.getRequestOptionsForCall(options));
255
- }
256
- /**
257
- * Connnects to a node and checks if it is a supported Bee version by the bee-js
258
- *
259
- * @returns true if the Bee node version is supported
260
- * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
261
- */
262
- async isSupportedVersion(options) {
263
- assertRequestOptions(options);
264
- return status.isSupportedVersion(this.getRequestOptionsForCall(options));
265
- }
266
- /**
267
- * Connects to a node and checks if its version matches with the one that bee-js supports.
268
- *
269
- * Be aware that this is the most strict version check and most probably
270
- * you will want to use more relaxed API-versions based checks like
271
- * `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
272
- * based on your use-case.
273
- *
274
- * @param options
275
- */
276
- async isSupportedExactVersion(options) {
277
- assertRequestOptions(options);
278
- return status.isSupportedExactVersion(this.getRequestOptionsForCall(options));
279
- }
280
- /**
281
- * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
282
- *
283
- * This is useful if you are not using `BeeDebug` class (for anything else then this check)
284
- * and want to make sure about compatibility.
285
- *
286
- * @param options
287
- */
288
- async isSupportedMainApiVersion(options) {
289
- assertRequestOptions(options);
290
- return status.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
291
- }
292
- /**
293
- * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
294
- *
295
- * This is useful if you are not using `Bee` class in your application and want to make sure
296
- * about compatibility.
297
- *
298
- * @param options
299
- */
300
- async isSupportedDebugApiVersion(options) {
301
- assertRequestOptions(options);
302
- return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
303
- }
304
- /**
305
- *
306
- * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
307
- *
308
- * This should be the main way how to check compatibility for your app and Bee node.
309
- *
310
- * @param options
311
- */
312
- async isSupportedApiVersion(options) {
313
- assertRequestOptions(options);
314
- return status.isSupportedDebugApiVersion(this.getRequestOptionsForCall(options));
315
- }
316
- /**
317
- * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
318
- * and versions that bee-js supports (properties prefixed with `supported*`).
319
- *
320
- * @param options
321
- */
322
- async getVersions(options) {
323
- assertRequestOptions(options);
324
- return status.getVersions(this.getRequestOptionsForCall(options));
325
- }
326
- /**
327
- * Get reserve state
328
- */
329
- async getReserveState(options) {
330
- assertRequestOptions(options);
331
- return states.getReserveState(this.getRequestOptionsForCall(options));
332
- }
333
- /**
334
- * Get chain state
335
- */
336
- async getChainState(options) {
337
- assertRequestOptions(options);
338
- return states.getChainState(this.getRequestOptionsForCall(options));
339
- }
340
- /**
341
- * Get wallet balances for xDai and BZZ of the Bee node
342
- *
343
- * @param options
344
- */
345
- async getWalletBalance(options) {
346
- assertRequestOptions(options);
347
- return states.getWalletBalance(this.getRequestOptionsForCall(options));
348
- }
349
- /**
350
- * Creates new postage batch from the funds that the node has available in its Ethereum account.
351
- *
352
- * For better understanding what each parameter means and what are the optimal values please see
353
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
354
- *
355
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
356
- *
357
- * @param amount Amount that represents the value per chunk, has to be greater or equal zero.
358
- * @param depth Logarithm of the number of chunks that can be stamped with the batch.
359
- * @param options Options for creation of postage batch
360
- * @throws BeeArgumentError when negative amount or depth is specified
361
- * @throws TypeError if non-integer value is passed to amount or depth
362
- *
363
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
364
- * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
365
- */
366
- async createPostageBatch(amount, depth, options, requestOptions) {
367
- assertPostageBatchOptions(options);
368
- assertPositiveInteger(amount);
369
- assertNonNegativeInteger(depth);
370
- if (depth < STAMPS_DEPTH_MIN) {
371
- throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth);
372
- }
373
- if (depth > STAMPS_DEPTH_MAX) {
374
- throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
375
- }
376
- const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amount, depth, options);
377
- if (options?.waitForUsable !== false) {
378
- await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
379
- }
380
- return stamp;
381
- }
382
- /**
383
- * Topup a fresh amount of BZZ to given Postage Batch.
384
- *
385
- * For better understanding what each parameter means and what are the optimal values please see
386
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
387
- *
388
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
389
- *
390
- * @param postageBatchId Batch ID
391
- * @param amount Amount to be added to the batch
392
- * @param options Request options
393
- *
394
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
395
- * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
396
- */
397
- async topUpBatch(postageBatchId, amount, options) {
398
- assertRequestOptions(options);
399
- assertNonNegativeInteger(amount, 'Amount');
400
- assertBatchId(postageBatchId);
401
- await stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amount);
402
- }
403
- /**
404
- * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
405
- * the Postage Batch to be used for more chunks.
406
- *
407
- * For better understanding what each parameter means and what are the optimal values please see
408
- * [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
409
- *
410
- * **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
411
- *
412
- * @param postageBatchId Batch ID
413
- * @param depth Amount to be added to the batch
414
- * @param options Request options
415
- *
416
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
417
- * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
418
- */
419
- async diluteBatch(postageBatchId, depth, options) {
420
- assertRequestOptions(options);
421
- assertNonNegativeInteger(depth, 'Depth');
422
- assertBatchId(postageBatchId);
423
- await stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
424
- }
425
- /**
426
- * Return details for specific postage batch.
427
- *
428
- * @param postageBatchId Batch ID
429
- *
430
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
431
- * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
432
- */
433
- async getPostageBatch(postageBatchId, options) {
434
- assertRequestOptions(options);
435
- assertBatchId(postageBatchId);
436
- return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
437
- }
438
- /**
439
- * Return detailed information related to buckets for specific postage batch.
440
- *
441
- * @param postageBatchId Batch ID
442
- *
443
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
444
- * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
445
- */
446
- async getPostageBatchBuckets(postageBatchId, options) {
447
- assertRequestOptions(options);
448
- assertBatchId(postageBatchId);
449
- return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
450
- }
451
- /**
452
- * Return all postage batches that has the node available.
453
- *
454
- * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
455
- * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
456
- */
457
- async getAllPostageBatch(options) {
458
- assertRequestOptions(options);
459
- return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
460
- }
461
- /**
462
- * Return all globally available postage batches.
463
- */
464
- async getAllGlobalPostageBatch(options) {
465
- assertRequestOptions(options);
466
- return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
467
- }
468
- /**
469
- * Return lists of all current pending transactions that the Bee made
470
- */
471
- async getAllPendingTransactions(options) {
472
- assertRequestOptions(options);
473
- return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
474
- }
475
- /**
476
- * Return transaction information for specific transaction
477
- * @param transactionHash
478
- */
479
- async getPendingTransaction(transactionHash, options) {
480
- assertRequestOptions(options);
481
- assertTransactionHash(transactionHash);
482
- return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
483
- }
484
- /**
485
- * Rebroadcast already created transaction.
486
- * This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
487
- *
488
- * @param transactionHash
489
- */
490
- async rebroadcastPendingTransaction(transactionHash, options) {
491
- assertRequestOptions(options);
492
- assertTransactionHash(transactionHash);
493
- return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
494
- }
495
- /**
496
- * Cancel currently pending transaction
497
- * @param transactionHash
498
- * @param gasPrice
499
- */
500
- async cancelPendingTransaction(transactionHash, gasPrice, options) {
501
- assertRequestOptions(options);
502
- assertTransactionHash(transactionHash);
503
- if (gasPrice) {
504
- assertNonNegativeInteger(gasPrice);
505
- }
506
- return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPrice);
507
- }
508
- /**
509
- * Gets the staked amount of BZZ (in PLUR unit) as number string.
510
- *
511
- * @param options
512
- */
513
- async getStake(options) {
514
- assertRequestOptions(options);
515
- return stake.getStake(this.getRequestOptionsForCall(options));
516
- }
517
- /**
518
- * Deposits given amount of BZZ token (in PLUR unit).
519
- *
520
- * Be aware that staked BZZ tokens can **not** be withdrawn.
521
- *
522
- * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
523
- * @param options
524
- */
525
- async depositStake(amount, options, requestOptions) {
526
- assertRequestOptions(options);
527
- assertTransactionOptions(options);
528
- await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
529
- }
530
- /**
531
- * Get current status of node in redistribution game
532
- *
533
- * @param options
534
- */
535
- async getRedistributionState(options) {
536
- assertRequestOptions(options);
537
- return stake.getRedistributionState(this.getRequestOptionsForCall(options));
538
- }
539
- async waitForUsablePostageStamp(id, timeout = 240000) {
540
- const TIME_STEP = 2000;
541
- for (let time = 0; time < timeout; time += TIME_STEP) {
542
- try {
543
- const stamp = await this.getPostageBatch(id);
544
- if (stamp.usable) {
545
- return;
546
- }
547
- } catch (error) {
548
- const message = error?.response?.data?.message || error?.message || '';
549
- if (!message.includes('batch not usable')) {
550
- throw error;
551
- }
552
- }
553
- await System.sleepMillis(TIME_STEP);
554
- }
555
- throw new BeeError('Timeout on waiting for postage stamp to become usable');
556
- }
557
- getRequestOptionsForCall(options) {
558
- return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
559
- }
560
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Helper function for serialize byte arrays
3
- *
4
- * @param arrays Any number of byte array arguments
5
- */
6
- export function serializeBytes(...arrays) {
7
- const length = arrays.reduce((prev, curr) => prev + curr.length, 0);
8
- const buffer = new Uint8Array(length);
9
- let offset = 0;
10
- arrays.forEach(arr => {
11
- buffer.set(arr, offset);
12
- offset += arr.length;
13
- });
14
- return buffer;
15
- }
@@ -1,129 +0,0 @@
1
- import { Readable as NodeReadableNative } from 'stream';
2
- import { ReadableStream } from 'web-streams-polyfill';
3
- import { isStrictlyObject } from "./type.js";
4
- const NodeReadable = NodeReadableNative || class {};
5
- /**
6
- * Validates if passed object is either browser's ReadableStream
7
- * or Node's Readable.
8
- *
9
- * @param entry
10
- */
11
- export function isReadable(entry) {
12
- return isReadableStream(entry) || isNodeReadable(entry);
13
- }
14
- export function isReadableStream(entry) {
15
- if (!isStrictlyObject(entry)) {
16
- return false;
17
- }
18
- const browserReadable = entry;
19
- if (typeof browserReadable.getReader === 'function' && browserReadable.locked !== undefined && typeof browserReadable.cancel === 'function' && typeof browserReadable.pipeTo === 'function' && typeof browserReadable.pipeThrough === 'function') {
20
- return true;
21
- }
22
- return false;
23
- }
24
- export function isNodeReadable(entry) {
25
- if (!isStrictlyObject(entry)) {
26
- return false;
27
- }
28
- const nodeReadable = entry;
29
- if (typeof nodeReadable.pipe === 'function' && nodeReadable.readable && typeof nodeReadable._read === 'function') {
30
- return true;
31
- }
32
- return false;
33
- }
34
- /**
35
- * Function that converts Node's Readable into WHATWG ReadableStream
36
- *
37
- * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
38
- * Because it uses forked web-streams-polyfill that are outdated.
39
- *
40
- * @author https://github.com/gwicke
41
- * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
42
- * @param nodeStream
43
- */
44
- export function readableNodeToWeb(nodeStream) {
45
- return new ReadableStream({
46
- start(controller) {
47
- nodeStream.pause();
48
- nodeStream.on('data', chunk => {
49
- if (Buffer.isBuffer(chunk)) {
50
- controller.enqueue(new Uint8Array(chunk.buffer));
51
- } else {
52
- controller.enqueue(chunk);
53
- }
54
- nodeStream.pause();
55
- });
56
- nodeStream.on('end', () => controller.close());
57
- nodeStream.on('error', e => controller.error(e));
58
- },
59
- pull() {
60
- nodeStream.resume();
61
- },
62
- cancel() {
63
- nodeStream.pause();
64
- }
65
- });
66
- }
67
- /**
68
- * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
69
- * Because it uses forked web-streams-polyfill that are outdated.
70
- *
71
- * @author https://github.com/gwicke
72
- * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
73
- */
74
- class NodeReadableWrapper extends NodeReadable {
75
- constructor(webStream, options) {
76
- super(options);
77
- this._webStream = webStream;
78
- this._reader = webStream.getReader();
79
- this._reading = false;
80
- }
81
- _read() {
82
- if (this._reading) {
83
- return;
84
- }
85
- this._reading = true;
86
- const doRead = () => {
87
- this._reader.read().then(res => {
88
- if (res.done) {
89
- this.push(null);
90
- return;
91
- }
92
- if (this.push(res.value)) {
93
- return doRead();
94
- } else {
95
- this._reading = false;
96
- }
97
- });
98
- };
99
- doRead();
100
- }
101
- }
102
- /**
103
- * Function that converts WHATWG ReadableStream into Node's Readable
104
- *
105
- * Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
106
- * Because it uses forked web-streams-polyfill that is outdated.
107
- *
108
- * **Warning!**
109
- * If you want to use this function in browser you have to polyfill `stream` package with your bundler.
110
- *
111
- * @author https://github.com/gwicke
112
- * @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
113
- * @param webStream
114
- * @param options
115
- */
116
- export function readableWebToNode(webStream, options) {
117
- if (!NodeReadableNative) {
118
- throw new Error("The Node's Readable is not available! If you are running this in browser you have to polyfill 'stream' package!");
119
- }
120
- return new NodeReadableWrapper(webStream, options);
121
- }
122
- export function normalizeToReadableStream(stream) {
123
- if (isNodeReadable(stream)) {
124
- return readableNodeToWeb(stream);
125
- } else if (isReadableStream(stream)) {
126
- return stream;
127
- }
128
- throw new TypeError('Passed stream is not Node Readable nor ReadableStream!');
129
- }