@ethersphere/bee-js 9.8.0 → 10.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.
- package/dist/cjs/bee.js +819 -364
- package/dist/cjs/manifest/manifest.js +6 -3
- package/dist/cjs/modules/debug/chequebook.js +1 -1
- package/dist/cjs/types/index.js +285 -4
- package/dist/cjs/utils/bytes.js +19 -1
- package/dist/cjs/utils/duration.js +6 -2
- package/dist/cjs/utils/stamps.js +36 -13
- package/dist/cjs/utils/type.js +2 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +818 -364
- package/dist/mjs/manifest/manifest.js +6 -3
- package/dist/mjs/modules/debug/chequebook.js +2 -2
- package/dist/mjs/types/index.js +1275 -4
- package/dist/mjs/utils/bytes.js +17 -0
- package/dist/mjs/utils/duration.js +7 -3
- package/dist/mjs/utils/stamps.js +35 -14
- package/dist/mjs/utils/type.js +6 -0
- package/dist/types/bee.d.ts +701 -249
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +108 -6
- package/dist/types/utils/bytes.d.ts +1 -0
- package/dist/types/utils/duration.d.ts +2 -0
- package/dist/types/utils/stamps.d.ts +4 -4
- package/package.json +1 -1
package/dist/mjs/bee.js
CHANGED
|
@@ -40,21 +40,23 @@ import { asNumberString, assertData, assertFileData, makeTagUid, prepareAllTagsO
|
|
|
40
40
|
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
41
41
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
42
42
|
/**
|
|
43
|
-
* The main component that abstracts operations available on the
|
|
43
|
+
* The main component that abstracts operations available on the Bee API.
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* Instantiate with `new Bee(url, options)` where `url` is the Bee node URL and `options` are optional parameters.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const bee = new Bee('http://localhost:1633')
|
|
47
49
|
*/
|
|
48
50
|
export class Bee {
|
|
49
51
|
/**
|
|
50
52
|
* @param url URL on which is the main API of Bee node exposed
|
|
51
53
|
* @param options
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const bee = new Bee('http://localhost:1633')
|
|
52
57
|
*/
|
|
53
58
|
constructor(url, options) {
|
|
54
59
|
assertBeeUrl(url);
|
|
55
|
-
// Remove last slash if present, as our endpoint strings starts with `/...`
|
|
56
|
-
// which could lead to double slash in URL to which Bee responds with
|
|
57
|
-
// unnecessary redirects.
|
|
58
60
|
this.url = stripLastSlash(url);
|
|
59
61
|
if (options?.signer) {
|
|
60
62
|
this.signer = new PrivateKey(options.signer);
|
|
@@ -70,15 +72,19 @@ export class Bee {
|
|
|
70
72
|
};
|
|
71
73
|
}
|
|
72
74
|
/**
|
|
73
|
-
*
|
|
75
|
+
* Uploads raw data to the network (as opposed to uploading chunks or files).
|
|
74
76
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
77
|
+
* Data uploaded with this method should be retrieved with the {@link downloadData} method.
|
|
78
|
+
*
|
|
79
|
+
* @param postageBatchId Usable Postage Batch ID with sufficient capacity to upload the data.
|
|
80
|
+
* @param data A `string` (text data) or `Uint8Array` (raw data) to be uploaded.
|
|
81
|
+
* @param options Additional options like tag, encryption, pinning, content-type and request options.
|
|
82
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
78
83
|
*
|
|
79
84
|
* @returns reference is a content hash of the data
|
|
80
|
-
*
|
|
85
|
+
*
|
|
81
86
|
* @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
|
|
87
|
+
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
82
88
|
*/
|
|
83
89
|
async uploadData(postageBatchId, data, options, requestOptions) {
|
|
84
90
|
postageBatchId = new BatchId(postageBatchId);
|
|
@@ -89,21 +95,32 @@ export class Bee {
|
|
|
89
95
|
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
|
-
*
|
|
98
|
+
* Fetches content length for a `/bytes` reference.
|
|
99
|
+
*
|
|
100
|
+
* @param reference
|
|
101
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
93
102
|
*
|
|
94
|
-
* @see [Bee API reference - `HEAD /bytes
|
|
103
|
+
* @see [Bee API reference - `HEAD /bytes/{reference}`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
|
|
95
104
|
*/
|
|
96
|
-
async probeData(reference,
|
|
105
|
+
async probeData(reference, requestOptions) {
|
|
97
106
|
reference = new Reference(reference);
|
|
98
|
-
return bytes.head(this.getRequestOptionsForCall(
|
|
107
|
+
return bytes.head(this.getRequestOptionsForCall(requestOptions), reference);
|
|
99
108
|
}
|
|
100
109
|
/**
|
|
101
|
-
*
|
|
110
|
+
* Downloads raw data through the `GET /bytes/{reference}` endpoint.
|
|
102
111
|
*
|
|
103
|
-
*
|
|
112
|
+
* This method may be used to download data that was uploaded with the {@link uploadData} method.
|
|
113
|
+
*
|
|
114
|
+
* For downloading files or using the `GET /bzz/{reference}/` endpoint, use the {@link downloadFile} method instead.
|
|
115
|
+
* For downloading chunks or using the `GET /chunks/{reference} endpoint, use the `downloadChunk` method instead.
|
|
116
|
+
*
|
|
117
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain.
|
|
104
118
|
* @param options Options that affects the request behavior
|
|
119
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
120
|
+
*
|
|
105
121
|
* @throws TypeError if some of the input parameters is not expected type
|
|
106
122
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
123
|
+
*
|
|
107
124
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
108
125
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
109
126
|
*/
|
|
@@ -114,12 +131,18 @@ export class Bee {
|
|
|
114
131
|
return bytes.download(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
115
132
|
}
|
|
116
133
|
/**
|
|
117
|
-
* Download data
|
|
134
|
+
* Download raw data through the `GET /bytes/{reference}` endpoint.
|
|
135
|
+
*
|
|
136
|
+
* This method may be used to download data that was uploaded with the {@link uploadData} method.
|
|
137
|
+
*
|
|
138
|
+
* Only tested in Node.js environment.
|
|
139
|
+
*
|
|
140
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain.
|
|
141
|
+
* @param options Options that affects the request behavior.
|
|
142
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
143
|
+
*
|
|
144
|
+
* @returns ReadableStream of Uint8Array
|
|
118
145
|
*
|
|
119
|
-
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
120
|
-
* @param options Options that affects the request behavior
|
|
121
|
-
* @throws TypeError if some of the input parameters is not expected type
|
|
122
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
123
146
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
124
147
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
125
148
|
*/
|
|
@@ -130,11 +153,14 @@ export class Bee {
|
|
|
130
153
|
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
131
154
|
}
|
|
132
155
|
/**
|
|
133
|
-
*
|
|
156
|
+
* Uploads a chunk to the network.
|
|
134
157
|
*
|
|
135
|
-
*
|
|
158
|
+
* Chunks uploaded with this method should be retrieved with the {@link downloadChunk} method.
|
|
159
|
+
*
|
|
160
|
+
* @param stamp Postage Batch ID or an Envelope created with the {@link createEnvelope} method.
|
|
136
161
|
* @param data Raw chunk to be uploaded
|
|
137
162
|
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
163
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
138
164
|
*
|
|
139
165
|
* @returns reference is a content hash of the data
|
|
140
166
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
@@ -154,12 +180,17 @@ export class Bee {
|
|
|
154
180
|
return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
|
|
155
181
|
}
|
|
156
182
|
/**
|
|
157
|
-
*
|
|
183
|
+
* Downloads a chunk as a `Uint8Array`.
|
|
184
|
+
*
|
|
185
|
+
* May be used to download chunks uploaded with the {@link uploadChunk} method.
|
|
186
|
+
*
|
|
187
|
+
* Use {@link downloadData} method to download raw data uploaded with the {@link uploadData} method.
|
|
188
|
+
* Use {@link downloadFile} method to download files uploaded with the {@link uploadFile} method.
|
|
158
189
|
*
|
|
159
190
|
* @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
160
191
|
* @param options Options that affects the request behavior
|
|
161
|
-
* @
|
|
162
|
-
*
|
|
192
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
193
|
+
*
|
|
163
194
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
164
195
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{address}/get)
|
|
165
196
|
*/
|
|
@@ -173,7 +204,7 @@ export class Bee {
|
|
|
173
204
|
/**
|
|
174
205
|
* Create a grantees list from the given array of public keys.
|
|
175
206
|
*
|
|
176
|
-
* The grantees list can be obtained with the
|
|
207
|
+
* The grantees list can be obtained with the {@link getGrantees} method.
|
|
177
208
|
*
|
|
178
209
|
* @param postageBatchId - The ID of the postage batch.
|
|
179
210
|
* @param grantees - An array of public keys representing the grantees.
|
|
@@ -203,7 +234,7 @@ export class Bee {
|
|
|
203
234
|
* @param history - The history.
|
|
204
235
|
* @param postageBatchId - The ID of the postage batch.
|
|
205
236
|
* @param grantees - The grantees.
|
|
206
|
-
* @param requestOptions
|
|
237
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
207
238
|
* @returns A Promise that resolves to to a `GranteesResult` object.
|
|
208
239
|
*/
|
|
209
240
|
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
|
|
@@ -217,12 +248,18 @@ export class Bee {
|
|
|
217
248
|
return grantee.patchGrantees(postageBatchId, reference, history, publicKeys, this.getRequestOptionsForCall(requestOptions));
|
|
218
249
|
}
|
|
219
250
|
/**
|
|
220
|
-
*
|
|
251
|
+
* Uploads a single file to a Bee node.
|
|
252
|
+
*
|
|
253
|
+
* To download the file, use the {@link downloadFile} method.
|
|
254
|
+
*
|
|
255
|
+
* Use {@link uploadData} method to upload raw data that can be downloaded with the {@link downloadData} method.
|
|
256
|
+
* Use {@link uploadChunk} method to upload chunks that can be downloaded with the {@link downloadChunk} method.
|
|
221
257
|
*
|
|
222
258
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
223
259
|
* @param data Data or file to be uploaded
|
|
224
260
|
* @param name Optional name of the uploaded file
|
|
225
261
|
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
262
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
226
263
|
*
|
|
227
264
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
228
265
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
@@ -252,14 +289,13 @@ export class Bee {
|
|
|
252
289
|
}
|
|
253
290
|
}
|
|
254
291
|
/**
|
|
255
|
-
*
|
|
292
|
+
* Downloads a single file.
|
|
256
293
|
*
|
|
257
|
-
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
294
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain.
|
|
258
295
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
259
296
|
* @param options Options that affects the request behavior
|
|
260
|
-
* @
|
|
261
|
-
*
|
|
262
|
-
* @see Data
|
|
297
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
298
|
+
*
|
|
263
299
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
264
300
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
265
301
|
*/
|
|
@@ -275,8 +311,7 @@ export class Bee {
|
|
|
275
311
|
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
276
312
|
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
277
313
|
* @param options Options that affects the request behavior
|
|
278
|
-
* @
|
|
279
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
314
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
280
315
|
*
|
|
281
316
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
282
317
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
@@ -299,6 +334,7 @@ export class Bee {
|
|
|
299
334
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
300
335
|
* @param fileList list of files to be uploaded
|
|
301
336
|
* @param options Additional options like tag, encryption, pinning and request options
|
|
337
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
302
338
|
*
|
|
303
339
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
304
340
|
* @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download#upload-a-directory)
|
|
@@ -312,13 +348,57 @@ export class Bee {
|
|
|
312
348
|
const data = makeCollectionFromFileList(fileList);
|
|
313
349
|
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
314
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Hashes a directory locally and returns the root hash (Swarm reference).
|
|
353
|
+
*
|
|
354
|
+
* The actual Swarm reference may be different as there is no canonical hashing of directories.
|
|
355
|
+
* For example, metadata may have different casing, or the order of metadata may differ.
|
|
356
|
+
* Such small differences will result in different Swarm references.
|
|
357
|
+
*
|
|
358
|
+
* Different implementations of the Mantaray structure may also result in different Swarm references.
|
|
359
|
+
*
|
|
360
|
+
* @param dir
|
|
361
|
+
* @returns
|
|
362
|
+
*/
|
|
315
363
|
async hashDirectory(dir) {
|
|
316
364
|
return hashDirectory(dir);
|
|
317
365
|
}
|
|
366
|
+
/**
|
|
367
|
+
* Uploads a directory to the network. The difference between this method and {@link uploadFilesFromDirectory} is that
|
|
368
|
+
* this method streams the directory contents directly to the Bee node, which supports arbitrary directory sizes,
|
|
369
|
+
* but may be slower due to uploading chunks one by one.
|
|
370
|
+
*
|
|
371
|
+
* Options such as encryption, erasure coding and ACT are not yet available for this method.
|
|
372
|
+
*
|
|
373
|
+
* Only intended for the Node.js environment.
|
|
374
|
+
*
|
|
375
|
+
* @param postageBatchId
|
|
376
|
+
* @param dir
|
|
377
|
+
* @param onUploadProgress
|
|
378
|
+
* @param options
|
|
379
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
380
|
+
* @returns
|
|
381
|
+
*/
|
|
318
382
|
async streamDirectory(postageBatchId, dir, onUploadProgress, options, requestOptions) {
|
|
319
383
|
postageBatchId = new BatchId(postageBatchId);
|
|
320
384
|
return streamDirectory(this, dir, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
321
385
|
}
|
|
386
|
+
/**
|
|
387
|
+
* Uploads a collection of files to the network. The difference between this method and {@link uploadFiles} is that
|
|
388
|
+
* this method streams the files to the Bee node, which supports arbitrary sizes,
|
|
389
|
+
* but may be slower due to uploading chunks one by one.
|
|
390
|
+
*
|
|
391
|
+
* Options such as encryption, erasure coding and ACT are not yet available for this method.
|
|
392
|
+
*
|
|
393
|
+
* Only intended for the browser environment.
|
|
394
|
+
*
|
|
395
|
+
* @param postageBatchId
|
|
396
|
+
* @param files
|
|
397
|
+
* @param onUploadProgress
|
|
398
|
+
* @param options
|
|
399
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
400
|
+
* @returns
|
|
401
|
+
*/
|
|
322
402
|
async streamFiles(postageBatchId, files, onUploadProgress, options, requestOptions) {
|
|
323
403
|
postageBatchId = new BatchId(postageBatchId);
|
|
324
404
|
return streamFiles(this, files, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
@@ -366,23 +446,23 @@ export class Bee {
|
|
|
366
446
|
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
367
447
|
}
|
|
368
448
|
/**
|
|
369
|
-
*
|
|
449
|
+
* Creates a new Tag which is meant for tracking upload and synchronization progress.
|
|
450
|
+
*
|
|
451
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
370
452
|
*
|
|
371
|
-
* @param options Options that affects the request behavior
|
|
372
453
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
373
454
|
* @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
|
|
374
455
|
*/
|
|
375
|
-
async createTag(
|
|
376
|
-
return tag.createTag(this.getRequestOptionsForCall(
|
|
456
|
+
async createTag(requestOptions) {
|
|
457
|
+
return tag.createTag(this.getRequestOptionsForCall(requestOptions));
|
|
377
458
|
}
|
|
378
459
|
/**
|
|
379
|
-
* Fetches all tags.
|
|
460
|
+
* Fetches all tags in a paginated manner.
|
|
380
461
|
*
|
|
381
462
|
* The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
|
|
382
463
|
*
|
|
383
|
-
* @param options
|
|
384
|
-
* @
|
|
385
|
-
* @throws BeeArgumentError if limit or offset have invalid options
|
|
464
|
+
* @param options Specify `limit` and `offset` to paginate through the tags.
|
|
465
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
386
466
|
*
|
|
387
467
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
388
468
|
* @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
|
|
@@ -394,34 +474,31 @@ export class Bee {
|
|
|
394
474
|
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
|
|
395
475
|
}
|
|
396
476
|
/**
|
|
397
|
-
*
|
|
477
|
+
* Retrieves tag information from Bee node.
|
|
398
478
|
*
|
|
399
479
|
* @param tagUid UID or tag object to be retrieved
|
|
400
|
-
* @param
|
|
401
|
-
* @throws TypeError if tagUid is in not correct format
|
|
480
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
402
481
|
*
|
|
403
482
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
404
483
|
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
|
|
405
484
|
*
|
|
406
485
|
*/
|
|
407
|
-
async retrieveTag(tagUid,
|
|
486
|
+
async retrieveTag(tagUid, requestOptions) {
|
|
408
487
|
tagUid = makeTagUid(tagUid);
|
|
409
|
-
return tag.retrieveTag(this.getRequestOptionsForCall(
|
|
488
|
+
return tag.retrieveTag(this.getRequestOptionsForCall(requestOptions), tagUid);
|
|
410
489
|
}
|
|
411
490
|
/**
|
|
412
|
-
*
|
|
491
|
+
* Deletes Tag.
|
|
413
492
|
*
|
|
414
493
|
* @param tagUid UID or tag object to be retrieved
|
|
415
|
-
* @param
|
|
416
|
-
* @throws TypeError if tagUid is in not correct format
|
|
417
|
-
* @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
|
|
494
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
418
495
|
*
|
|
419
496
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
420
497
|
* @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
|
|
421
498
|
*/
|
|
422
|
-
async deleteTag(tagUid,
|
|
499
|
+
async deleteTag(tagUid, requestOptions) {
|
|
423
500
|
tagUid = makeTagUid(tagUid);
|
|
424
|
-
return tag.deleteTag(this.getRequestOptionsForCall(
|
|
501
|
+
return tag.deleteTag(this.getRequestOptionsForCall(requestOptions), tagUid);
|
|
425
502
|
}
|
|
426
503
|
/**
|
|
427
504
|
* Update tag's total chunks count.
|
|
@@ -431,99 +508,90 @@ export class Bee {
|
|
|
431
508
|
*
|
|
432
509
|
* @param tagUid UID or tag object to be retrieved
|
|
433
510
|
* @param reference The root reference that contains all the chunks to be counted
|
|
434
|
-
* @param
|
|
435
|
-
* @throws TypeError if tagUid is in not correct format
|
|
436
|
-
* @throws BeeResponse error if something went wrong on the Bee node side while deleting the tag.
|
|
511
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
437
512
|
*
|
|
438
513
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
439
514
|
* @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
|
|
440
515
|
*/
|
|
441
|
-
async updateTag(tagUid, reference,
|
|
516
|
+
async updateTag(tagUid, reference, requestOptions) {
|
|
442
517
|
reference = new Reference(reference);
|
|
443
518
|
tagUid = makeTagUid(tagUid);
|
|
444
|
-
return tag.updateTag(this.getRequestOptionsForCall(
|
|
519
|
+
return tag.updateTag(this.getRequestOptionsForCall(requestOptions), tagUid, reference);
|
|
445
520
|
}
|
|
446
521
|
/**
|
|
447
|
-
*
|
|
522
|
+
* Pins local data with given reference.
|
|
448
523
|
*
|
|
449
524
|
* @param reference Data reference
|
|
450
|
-
* @param
|
|
451
|
-
* @throws TypeError if reference is in not correct format
|
|
525
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
452
526
|
*
|
|
453
527
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
454
528
|
*/
|
|
455
|
-
async pin(reference,
|
|
529
|
+
async pin(reference, requestOptions) {
|
|
456
530
|
reference = new Reference(reference);
|
|
457
|
-
return pinning.pin(this.getRequestOptionsForCall(
|
|
531
|
+
return pinning.pin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
458
532
|
}
|
|
459
533
|
/**
|
|
460
|
-
*
|
|
534
|
+
* Unpins local data with given reference.
|
|
461
535
|
*
|
|
462
536
|
* @param reference Data reference
|
|
463
|
-
* @param
|
|
464
|
-
* @throws TypeError if reference is in not correct format
|
|
537
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
465
538
|
*
|
|
466
539
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
467
540
|
*/
|
|
468
|
-
async unpin(reference,
|
|
541
|
+
async unpin(reference, requestOptions) {
|
|
469
542
|
reference = new Reference(reference);
|
|
470
|
-
return pinning.unpin(this.getRequestOptionsForCall(
|
|
543
|
+
return pinning.unpin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
471
544
|
}
|
|
472
545
|
/**
|
|
473
|
-
*
|
|
546
|
+
* Gets list of all locally pinned references.
|
|
547
|
+
*
|
|
548
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
474
549
|
*
|
|
475
|
-
* @param options Options that affects the request behavior
|
|
476
550
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
477
551
|
*/
|
|
478
|
-
async getAllPins(
|
|
479
|
-
return pinning.getAllPins(this.getRequestOptionsForCall(
|
|
552
|
+
async getAllPins(requestOptions) {
|
|
553
|
+
return pinning.getAllPins(this.getRequestOptionsForCall(requestOptions));
|
|
480
554
|
}
|
|
481
555
|
/**
|
|
482
556
|
* Get pinning status of chunk with given reference
|
|
483
557
|
*
|
|
484
558
|
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
485
|
-
* @param
|
|
486
|
-
* @throws TypeError if some of the input parameters is not expected type
|
|
487
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
559
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
488
560
|
*
|
|
489
561
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
490
562
|
*/
|
|
491
|
-
async getPin(reference,
|
|
563
|
+
async getPin(reference, requestOptions) {
|
|
492
564
|
reference = new Reference(reference);
|
|
493
|
-
return pinning.getPin(this.getRequestOptionsForCall(
|
|
565
|
+
return pinning.getPin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
494
566
|
}
|
|
495
567
|
/**
|
|
496
568
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
497
569
|
*
|
|
570
|
+
* @param postageBatchId Postage Batch ID that will be used to re-upload the data.
|
|
498
571
|
* @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
|
|
499
|
-
* @param
|
|
500
|
-
* @throws BeeArgumentError if the reference is not locally pinned
|
|
501
|
-
* @throws TypeError if some of the input parameters is not expected type
|
|
502
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
572
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
503
573
|
*
|
|
504
574
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
505
575
|
*/
|
|
506
|
-
async reuploadPinnedData(postageBatchId, reference,
|
|
576
|
+
async reuploadPinnedData(postageBatchId, reference, requestOptions) {
|
|
507
577
|
postageBatchId = new BatchId(postageBatchId);
|
|
508
578
|
reference = new Reference(reference);
|
|
509
|
-
await stewardship.reupload(this.getRequestOptionsForCall(
|
|
579
|
+
await stewardship.reupload(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
510
580
|
}
|
|
511
581
|
/**
|
|
512
582
|
* Checks if content specified by reference is retrievable from the network.
|
|
513
583
|
*
|
|
514
584
|
* @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
|
|
515
|
-
* @param
|
|
516
|
-
* @throws TypeError if some of the input parameters is not expected type
|
|
517
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
585
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
518
586
|
*
|
|
519
587
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
520
588
|
*/
|
|
521
|
-
async isReferenceRetrievable(reference,
|
|
589
|
+
async isReferenceRetrievable(reference, requestOptions) {
|
|
522
590
|
reference = new Reference(reference);
|
|
523
|
-
return stewardship.isRetrievable(this.getRequestOptionsForCall(
|
|
591
|
+
return stewardship.isRetrievable(this.getRequestOptionsForCall(requestOptions), reference);
|
|
524
592
|
}
|
|
525
593
|
/**
|
|
526
|
-
* Functions that
|
|
594
|
+
* Functions that validate if feed is retrievable in the network.
|
|
527
595
|
*
|
|
528
596
|
* If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
|
|
529
597
|
* sure what is the "latest" update.
|
|
@@ -536,6 +604,7 @@ export class Bee {
|
|
|
536
604
|
* @param topic
|
|
537
605
|
* @param index
|
|
538
606
|
* @param options
|
|
607
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
539
608
|
*/
|
|
540
609
|
async isFeedRetrievable(owner, topic, index, options, requestOptions) {
|
|
541
610
|
owner = new EthAddress(owner);
|
|
@@ -565,35 +634,32 @@ export class Bee {
|
|
|
565
634
|
* most likely for setting up an encrypted communication
|
|
566
635
|
* channel by sending an one-off message.
|
|
567
636
|
*
|
|
568
|
-
* **Warning!
|
|
569
|
-
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
637
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
570
638
|
*
|
|
571
639
|
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
572
640
|
* @param topic Topic name
|
|
573
641
|
* @param target Target message address prefix. Has a limit on length. Recommend to use `Utils.Pss.makeMaxTarget()` to get the most specific target that Bee node will accept.
|
|
574
642
|
* @param data Message to be sent
|
|
575
643
|
* @param recipient Recipient public key
|
|
576
|
-
* @param
|
|
577
|
-
* @throws TypeError if `data`, `batchId`, `target` or `recipient` are in invalid format
|
|
644
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
578
645
|
*
|
|
579
646
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
580
647
|
* @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
|
|
581
648
|
*/
|
|
582
|
-
async pssSend(postageBatchId, topic, target, data, recipient,
|
|
649
|
+
async pssSend(postageBatchId, topic, target, data, recipient, requestOptions) {
|
|
583
650
|
postageBatchId = new BatchId(postageBatchId);
|
|
584
651
|
assertData(data);
|
|
585
652
|
if (recipient) {
|
|
586
653
|
recipient = new PublicKey(recipient);
|
|
587
|
-
return pss.send(this.getRequestOptionsForCall(
|
|
654
|
+
return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId, recipient);
|
|
588
655
|
} else {
|
|
589
|
-
return pss.send(this.getRequestOptionsForCall(
|
|
656
|
+
return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId);
|
|
590
657
|
}
|
|
591
658
|
}
|
|
592
659
|
/**
|
|
593
|
-
*
|
|
660
|
+
* Subscribes to messages for given topic with the Postal Service for Swarm.
|
|
594
661
|
*
|
|
595
|
-
* **Warning!
|
|
596
|
-
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
662
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
597
663
|
*
|
|
598
664
|
* @param topic Topic name
|
|
599
665
|
* @param handler Message handler interface
|
|
@@ -608,16 +674,13 @@ export class Bee {
|
|
|
608
674
|
const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
|
|
609
675
|
let cancelled = false;
|
|
610
676
|
const cancel = () => {
|
|
611
|
-
if (cancelled
|
|
677
|
+
if (!cancelled) {
|
|
612
678
|
cancelled = true;
|
|
613
|
-
// although the WebSocket API offers a `close` function, it seems that
|
|
614
|
-
// with the library that we are using (isomorphic-ws) it doesn't close
|
|
615
|
-
// the websocket properly, whereas `terminate` does
|
|
616
679
|
if (ws.terminate) {
|
|
617
680
|
ws.terminate();
|
|
618
681
|
} else {
|
|
619
682
|
ws.close();
|
|
620
|
-
}
|
|
683
|
+
}
|
|
621
684
|
}
|
|
622
685
|
};
|
|
623
686
|
const subscription = {
|
|
@@ -631,28 +694,24 @@ export class Bee {
|
|
|
631
694
|
}
|
|
632
695
|
};
|
|
633
696
|
ws.onerror = event => {
|
|
634
|
-
// ignore errors after subscription was cancelled
|
|
635
697
|
if (!cancelled) {
|
|
636
698
|
handler.onError(new BeeError(event.message), subscription);
|
|
637
699
|
}
|
|
638
700
|
};
|
|
701
|
+
ws.onclose = () => {
|
|
702
|
+
handler.onClose(subscription);
|
|
703
|
+
};
|
|
639
704
|
return subscription;
|
|
640
705
|
}
|
|
641
706
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
* Because sending a PSS message is slow and CPU intensive,
|
|
645
|
-
* it is not supposed to be used for general messaging but
|
|
646
|
-
* most likely for setting up an encrypted communication
|
|
647
|
-
* channel by sending an one-off message.
|
|
707
|
+
* Receives message using the Postal Service for Swarm.
|
|
648
708
|
*
|
|
649
709
|
* This is a helper function to wait for exactly one message to
|
|
650
710
|
* arrive and then cancel the subscription. Additionally a
|
|
651
711
|
* timeout can be provided for the message to arrive or else
|
|
652
712
|
* an error will be thrown.
|
|
653
713
|
*
|
|
654
|
-
* **Warning!
|
|
655
|
-
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
714
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
656
715
|
*
|
|
657
716
|
* @param topic Topic name
|
|
658
717
|
* @param timeoutMsec Timeout in milliseconds
|
|
@@ -678,6 +737,10 @@ export class Bee {
|
|
|
678
737
|
clearTimeout(timeout);
|
|
679
738
|
subscription.cancel();
|
|
680
739
|
resolve(message);
|
|
740
|
+
},
|
|
741
|
+
onClose: () => {
|
|
742
|
+
clearTimeout(timeout);
|
|
743
|
+
subscription.cancel();
|
|
681
744
|
}
|
|
682
745
|
});
|
|
683
746
|
if (timeoutMsec > 0) {
|
|
@@ -688,6 +751,22 @@ export class Bee {
|
|
|
688
751
|
}
|
|
689
752
|
});
|
|
690
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* Mines the signer (a private key) to be used to send GSOC messages to the specific target overlay address.
|
|
756
|
+
*
|
|
757
|
+
* Use {@link gsocSend} to send GSOC messages with the mined signer.
|
|
758
|
+
*
|
|
759
|
+
* Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
|
|
760
|
+
*
|
|
761
|
+
* See {@link gsocSend} or {@link gsocSubscribe} for concrete examples of usage.
|
|
762
|
+
*
|
|
763
|
+
* **Warning! Only full nodes can accept GSOC messages.**
|
|
764
|
+
*
|
|
765
|
+
* @param targetOverlay
|
|
766
|
+
* @param identifier
|
|
767
|
+
* @param proximity
|
|
768
|
+
* @returns
|
|
769
|
+
*/
|
|
691
770
|
gsocMine(targetOverlay, identifier, proximity = 12) {
|
|
692
771
|
targetOverlay = new PeerAddress(targetOverlay);
|
|
693
772
|
identifier = new Identifier(identifier);
|
|
@@ -703,6 +782,29 @@ export class Bee {
|
|
|
703
782
|
}
|
|
704
783
|
throw Error('Could not mine a valid signer');
|
|
705
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Sends a GSOC message with the specified signer and identifier.
|
|
787
|
+
*
|
|
788
|
+
* Use {@link gsocMine} to mine a signer for the target overlay address.
|
|
789
|
+
*
|
|
790
|
+
* Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
|
|
791
|
+
*
|
|
792
|
+
* **Warning! Only full nodes can accept GSOC messages.**
|
|
793
|
+
*
|
|
794
|
+
* @param postageBatchId
|
|
795
|
+
* @param signer
|
|
796
|
+
* @param identifier
|
|
797
|
+
* @param data
|
|
798
|
+
* @param options
|
|
799
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
800
|
+
* @returns
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* const identifier = NULL_IDENTIFIER
|
|
804
|
+
* const overlay = '0x1234567890123456789012345678901234567890'
|
|
805
|
+
* const signer = bee.gsocMine(overlay, identifier)
|
|
806
|
+
* await bee.gsocSend(postageBatchId, signer, identifier, 'GSOC!')
|
|
807
|
+
*/
|
|
706
808
|
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
707
809
|
postageBatchId = new BatchId(postageBatchId);
|
|
708
810
|
signer = new PrivateKey(signer);
|
|
@@ -711,6 +813,37 @@ export class Bee {
|
|
|
711
813
|
const soc = makeSingleOwnerChunk(cac, identifier, signer);
|
|
712
814
|
return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
|
|
713
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* Subscribes to GSOC messages for the specified owner (of the signer) and identifier.
|
|
818
|
+
*
|
|
819
|
+
* Use {@link gsocMine} to mine a signer for the target overlay address.
|
|
820
|
+
*
|
|
821
|
+
* Use {@link gsocSend} to send GSOC messages with the mined signer.
|
|
822
|
+
*
|
|
823
|
+
* **Warning! Only full nodes can accept GSOC messages.**
|
|
824
|
+
*
|
|
825
|
+
* @param address
|
|
826
|
+
* @param identifier
|
|
827
|
+
* @param handler
|
|
828
|
+
* @returns
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* const identifier = NULL_IDENTIFIER
|
|
832
|
+
* const { overlay } = await bee.getNodeAddresses()
|
|
833
|
+
* const signer = bee.gsocMine(overlay, identifier)
|
|
834
|
+
*
|
|
835
|
+
* const subscription = bee.gsocSubscribe(signer.publicKey().address(), identifier, {
|
|
836
|
+
* onMessage(message) {
|
|
837
|
+
* // handle
|
|
838
|
+
* },
|
|
839
|
+
* onError(error) {
|
|
840
|
+
* // handle
|
|
841
|
+
* },
|
|
842
|
+
* onClose() {
|
|
843
|
+
* // handle
|
|
844
|
+
* }
|
|
845
|
+
* })
|
|
846
|
+
*/
|
|
714
847
|
gsocSubscribe(address, identifier, handler) {
|
|
715
848
|
address = new EthAddress(address);
|
|
716
849
|
identifier = new Identifier(identifier);
|
|
@@ -719,7 +852,7 @@ export class Bee {
|
|
|
719
852
|
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
720
853
|
let cancelled = false;
|
|
721
854
|
const cancel = () => {
|
|
722
|
-
if (cancelled
|
|
855
|
+
if (!cancelled) {
|
|
723
856
|
cancelled = true;
|
|
724
857
|
if (ws.terminate) {
|
|
725
858
|
ws.terminate();
|
|
@@ -743,17 +876,21 @@ export class Bee {
|
|
|
743
876
|
handler.onError(new BeeError(event.message), subscription);
|
|
744
877
|
}
|
|
745
878
|
};
|
|
879
|
+
ws.onclose = () => {
|
|
880
|
+
handler.onClose(subscription);
|
|
881
|
+
};
|
|
746
882
|
return subscription;
|
|
747
883
|
}
|
|
748
884
|
/**
|
|
749
|
-
*
|
|
885
|
+
* Creates a feed manifest chunk and returns the reference to it.
|
|
750
886
|
*
|
|
751
|
-
* Feed manifest
|
|
887
|
+
* Feed manifest chunks allow for a feed to be able to be resolved through `/bzz` endpoint.
|
|
752
888
|
*
|
|
753
889
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
754
890
|
* @param topic Topic in hex or bytes
|
|
755
891
|
* @param owner Owner's ethereum address in hex or bytes
|
|
756
892
|
* @param options Options that affects the request behavior
|
|
893
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
757
894
|
*
|
|
758
895
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
759
896
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
@@ -768,35 +905,35 @@ export class Bee {
|
|
|
768
905
|
return createFeedManifest(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
|
|
769
906
|
}
|
|
770
907
|
/**
|
|
771
|
-
*
|
|
908
|
+
* Makes a new feed reader for downloading feed updates.
|
|
772
909
|
*
|
|
773
910
|
* @param topic Topic in hex or bytes
|
|
774
911
|
* @param owner Owner's ethereum address in hex or bytes
|
|
775
|
-
* @param
|
|
912
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
776
913
|
*
|
|
777
914
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
778
915
|
*/
|
|
779
|
-
makeFeedReader(topic, owner,
|
|
916
|
+
makeFeedReader(topic, owner, requestOptions) {
|
|
780
917
|
topic = new Topic(topic);
|
|
781
918
|
owner = new EthAddress(owner);
|
|
782
|
-
return makeFeedReader(this.getRequestOptionsForCall(
|
|
919
|
+
return makeFeedReader(this.getRequestOptionsForCall(requestOptions), topic, owner);
|
|
783
920
|
}
|
|
784
921
|
/**
|
|
785
|
-
*
|
|
922
|
+
* Makes a new feed writer for updating feeds
|
|
786
923
|
*
|
|
787
924
|
* @param topic Topic in hex or bytes
|
|
788
925
|
* @param signer The signer's private key or a Signer instance that can sign data
|
|
789
|
-
* @param
|
|
926
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
790
927
|
*
|
|
791
928
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
792
929
|
*/
|
|
793
|
-
makeFeedWriter(topic, signer,
|
|
930
|
+
makeFeedWriter(topic, signer, requestOptions) {
|
|
794
931
|
topic = new Topic(topic);
|
|
795
932
|
signer = signer ? new PrivateKey(signer) : this.signer;
|
|
796
933
|
if (!signer) {
|
|
797
934
|
throw Error('No signer provided');
|
|
798
935
|
}
|
|
799
|
-
return makeFeedWriter(this.getRequestOptionsForCall(
|
|
936
|
+
return makeFeedWriter(this.getRequestOptionsForCall(requestOptions), topic, signer);
|
|
800
937
|
}
|
|
801
938
|
async fetchLatestFeedUpdate(topic, owner, requestOptions) {
|
|
802
939
|
topic = new Topic(topic);
|
|
@@ -807,62 +944,91 @@ export class Bee {
|
|
|
807
944
|
* Returns an object for reading single owner chunks
|
|
808
945
|
*
|
|
809
946
|
* @param ownerAddress The ethereum address of the owner
|
|
810
|
-
* @param
|
|
947
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
811
948
|
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
812
949
|
*/
|
|
813
|
-
makeSOCReader(ownerAddress,
|
|
950
|
+
makeSOCReader(ownerAddress, requestOptions) {
|
|
814
951
|
ownerAddress = new EthAddress(ownerAddress);
|
|
815
952
|
return {
|
|
816
953
|
owner: ownerAddress,
|
|
817
|
-
download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(
|
|
954
|
+
download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(requestOptions), ownerAddress)
|
|
818
955
|
};
|
|
819
956
|
}
|
|
820
957
|
/**
|
|
821
958
|
* Returns an object for reading and writing single owner chunks
|
|
822
959
|
*
|
|
823
960
|
* @param signer The signer's private key or a Signer instance that can sign data
|
|
824
|
-
* @param
|
|
961
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
825
962
|
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
826
963
|
*/
|
|
827
|
-
makeSOCWriter(signer,
|
|
964
|
+
makeSOCWriter(signer, requestOptions) {
|
|
828
965
|
signer = signer ? new PrivateKey(signer) : this.signer;
|
|
829
966
|
if (!signer) {
|
|
830
967
|
throw Error('No signer provided');
|
|
831
968
|
}
|
|
832
969
|
return {
|
|
833
|
-
...this.makeSOCReader(signer.publicKey().address(),
|
|
834
|
-
upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(
|
|
970
|
+
...this.makeSOCReader(signer.publicKey().address(), requestOptions),
|
|
971
|
+
upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(requestOptions), signer)
|
|
835
972
|
};
|
|
836
973
|
}
|
|
837
|
-
|
|
974
|
+
/**
|
|
975
|
+
* Creates the postage batch signature for a specific chunk address.
|
|
976
|
+
*
|
|
977
|
+
* This is for advanced usage, where a pre-signed chunk can be uploaded
|
|
978
|
+
* through a different Bee node.
|
|
979
|
+
*
|
|
980
|
+
* @param postageBatchId
|
|
981
|
+
* @param reference
|
|
982
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* const envelope = await bee.createEnvelope(batchId, chunk.address)
|
|
986
|
+
* await bee.uploadChunk(envelope, chunk)
|
|
987
|
+
*
|
|
988
|
+
* @returns
|
|
989
|
+
*/
|
|
990
|
+
async createEnvelope(postageBatchId, reference, requestOptions) {
|
|
838
991
|
postageBatchId = new BatchId(postageBatchId);
|
|
839
992
|
reference = new Reference(reference);
|
|
840
|
-
return postEnvelope(this.getRequestOptionsForCall(
|
|
993
|
+
return postEnvelope(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
841
994
|
}
|
|
842
995
|
/**
|
|
843
|
-
*
|
|
996
|
+
* Gets reserve commitment hash duration seconds.
|
|
997
|
+
*
|
|
998
|
+
* To be able to participe in the storage incentives and not get frozen, this should
|
|
999
|
+
* ideally run under 5 minutes.
|
|
1000
|
+
*
|
|
1001
|
+
* This is a CPU intensice operation, as roughly 2^22 chunks are hashed in the process.
|
|
1002
|
+
*
|
|
1003
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
1006
|
+
* const addresses = await bee.getNodeAddresses()
|
|
1007
|
+
* const topology = await bee.getTopology()
|
|
1008
|
+
* const result = await bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex())
|
|
1009
|
+
* // result is a number of seconds
|
|
844
1010
|
*/
|
|
845
|
-
async rchash(depth, anchor1, anchor2,
|
|
846
|
-
return rchash(this.getRequestOptionsForCall(
|
|
1011
|
+
async rchash(depth, anchor1, anchor2, requestOptions) {
|
|
1012
|
+
return rchash(this.getRequestOptionsForCall(requestOptions), depth, anchor1, anchor2);
|
|
847
1013
|
}
|
|
848
1014
|
/**
|
|
849
|
-
*
|
|
1015
|
+
* Pings the Bee node to see if there is a live Bee node on the given URL.
|
|
850
1016
|
*
|
|
851
|
-
* @param
|
|
1017
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
852
1018
|
* @throws If connection was not successful throw error
|
|
853
1019
|
*/
|
|
854
|
-
async checkConnection(
|
|
855
|
-
return status.checkConnection(this.getRequestOptionsForCall(
|
|
1020
|
+
async checkConnection(requestOptions) {
|
|
1021
|
+
return status.checkConnection(this.getRequestOptionsForCall(requestOptions));
|
|
856
1022
|
}
|
|
857
1023
|
/**
|
|
858
|
-
*
|
|
1024
|
+
* Pings the Bee node to see if there is a live Bee node on the given URL.
|
|
859
1025
|
*
|
|
860
|
-
* @param
|
|
1026
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
861
1027
|
* @returns true if successful, false on error
|
|
862
1028
|
*/
|
|
863
|
-
async isConnected(
|
|
1029
|
+
async isConnected(requestOptions) {
|
|
864
1030
|
try {
|
|
865
|
-
await status.checkConnection(this.getRequestOptionsForCall(
|
|
1031
|
+
await status.checkConnection(this.getRequestOptionsForCall(requestOptions));
|
|
866
1032
|
} catch (e) {
|
|
867
1033
|
return false;
|
|
868
1034
|
}
|
|
@@ -874,117 +1040,170 @@ export class Bee {
|
|
|
874
1040
|
* Do note that this is not a standard way to check for gateway nodes,
|
|
875
1041
|
* but some of the gateway tooling expose this endpoint.
|
|
876
1042
|
*
|
|
877
|
-
* @param
|
|
1043
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
878
1044
|
*/
|
|
879
|
-
async isGateway(
|
|
880
|
-
return status.isGateway(this.getRequestOptionsForCall(
|
|
1045
|
+
async isGateway(requestOptions) {
|
|
1046
|
+
return status.isGateway(this.getRequestOptionsForCall(requestOptions));
|
|
881
1047
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
1048
|
+
/**
|
|
1049
|
+
* Fetches the overlay, underlay, Ethereum, and other addresses of the Bee node.
|
|
1050
|
+
*
|
|
1051
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1052
|
+
* @returns
|
|
1053
|
+
*/
|
|
1054
|
+
async getNodeAddresses(requestOptions) {
|
|
1055
|
+
return connectivity.getNodeAddresses(this.getRequestOptionsForCall(requestOptions));
|
|
885
1056
|
}
|
|
886
|
-
|
|
887
|
-
|
|
1057
|
+
/**
|
|
1058
|
+
* Fetches the list of blocked peers for this node.
|
|
1059
|
+
*
|
|
1060
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1061
|
+
* @returns
|
|
1062
|
+
*/
|
|
1063
|
+
async getBlocklist(requestOptions) {
|
|
1064
|
+
return connectivity.getBlocklist(this.getRequestOptionsForCall(requestOptions));
|
|
888
1065
|
}
|
|
889
1066
|
/**
|
|
890
|
-
*
|
|
1067
|
+
* Gets list of peers for this node.
|
|
1068
|
+
*
|
|
1069
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
891
1070
|
*/
|
|
892
|
-
async getPeers(
|
|
893
|
-
return connectivity.getPeers(this.getRequestOptionsForCall(
|
|
1071
|
+
async getPeers(requestOptions) {
|
|
1072
|
+
return connectivity.getPeers(this.getRequestOptionsForCall(requestOptions));
|
|
894
1073
|
}
|
|
895
|
-
|
|
1074
|
+
/**
|
|
1075
|
+
* Disconnects from a specific peer.
|
|
1076
|
+
*
|
|
1077
|
+
* @param peer Overlay address of the peer to be removed.
|
|
1078
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1079
|
+
* @returns
|
|
1080
|
+
*/
|
|
1081
|
+
async removePeer(peer, requestOptions) {
|
|
896
1082
|
peer = new PeerAddress(peer);
|
|
897
|
-
return connectivity.removePeer(this.getRequestOptionsForCall(
|
|
1083
|
+
return connectivity.removePeer(this.getRequestOptionsForCall(requestOptions), peer);
|
|
898
1084
|
}
|
|
899
|
-
|
|
900
|
-
|
|
1085
|
+
/**
|
|
1086
|
+
* Fetches topology and connectivity information of the Bee node.
|
|
1087
|
+
*
|
|
1088
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1089
|
+
* @returns
|
|
1090
|
+
*/
|
|
1091
|
+
async getTopology(requestOptions) {
|
|
1092
|
+
return connectivity.getTopology(this.getRequestOptionsForCall(requestOptions));
|
|
901
1093
|
}
|
|
902
|
-
|
|
1094
|
+
/**
|
|
1095
|
+
* Pings a specific peer to check its availability.
|
|
1096
|
+
*
|
|
1097
|
+
* @param peer Overlay address of the peer to be pinged.
|
|
1098
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1099
|
+
* @returns
|
|
1100
|
+
*/
|
|
1101
|
+
async pingPeer(peer, requestOptions) {
|
|
903
1102
|
peer = new PeerAddress(peer);
|
|
904
|
-
return connectivity.pingPeer(this.getRequestOptionsForCall(
|
|
1103
|
+
return connectivity.pingPeer(this.getRequestOptionsForCall(requestOptions), peer);
|
|
905
1104
|
}
|
|
906
|
-
/*
|
|
907
|
-
* Balance endpoints
|
|
908
|
-
*/
|
|
909
1105
|
/**
|
|
910
|
-
*
|
|
1106
|
+
* Gets the SWAP balances with all known peers including prepaid services.
|
|
1107
|
+
*
|
|
1108
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1109
|
+
*
|
|
1110
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
911
1111
|
*/
|
|
912
|
-
async getAllBalances(
|
|
913
|
-
return balance.getAllBalances(this.getRequestOptionsForCall(
|
|
1112
|
+
async getAllBalances(requestOptions) {
|
|
1113
|
+
return balance.getAllBalances(this.getRequestOptionsForCall(requestOptions));
|
|
914
1114
|
}
|
|
915
1115
|
/**
|
|
916
|
-
*
|
|
1116
|
+
* Gets the SWAP balances for a specific peer including prepaid services.
|
|
917
1117
|
*
|
|
918
1118
|
* @param address Swarm address of peer
|
|
1119
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
919
1120
|
*/
|
|
920
|
-
async getPeerBalance(address,
|
|
1121
|
+
async getPeerBalance(address, requestOptions) {
|
|
921
1122
|
address = new PeerAddress(address);
|
|
922
|
-
return balance.getPeerBalance(this.getRequestOptionsForCall(
|
|
1123
|
+
return balance.getPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
|
|
923
1124
|
}
|
|
924
1125
|
/**
|
|
925
|
-
*
|
|
1126
|
+
* Gets the past due consumption balances for all known peers.
|
|
1127
|
+
*
|
|
1128
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1129
|
+
*
|
|
1130
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
926
1131
|
*/
|
|
927
|
-
async getPastDueConsumptionBalances(
|
|
928
|
-
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(
|
|
1132
|
+
async getPastDueConsumptionBalances(requestOptions) {
|
|
1133
|
+
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(requestOptions));
|
|
929
1134
|
}
|
|
930
1135
|
/**
|
|
931
|
-
*
|
|
1136
|
+
* Gets the past due consumption balance for a specific peer.
|
|
1137
|
+
*
|
|
1138
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
932
1139
|
*
|
|
933
1140
|
* @param address Swarm address of peer
|
|
1141
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
934
1142
|
*/
|
|
935
|
-
async getPastDueConsumptionPeerBalance(address,
|
|
1143
|
+
async getPastDueConsumptionPeerBalance(address, requestOptions) {
|
|
936
1144
|
address = new PeerAddress(address);
|
|
937
|
-
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(
|
|
1145
|
+
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
|
|
938
1146
|
}
|
|
939
|
-
/*
|
|
940
|
-
* Chequebook endpoints
|
|
941
|
-
*/
|
|
942
1147
|
/**
|
|
943
|
-
*
|
|
1148
|
+
* Gets the address of the deloyed chequebook.
|
|
944
1149
|
*
|
|
945
|
-
*
|
|
946
|
-
* https://github.com/ethersphere/bee/issues/1443
|
|
1150
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
947
1151
|
*/
|
|
948
|
-
async getChequebookAddress(
|
|
949
|
-
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(
|
|
1152
|
+
async getChequebookAddress(requestOptions) {
|
|
1153
|
+
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(requestOptions));
|
|
950
1154
|
}
|
|
951
1155
|
/**
|
|
952
|
-
*
|
|
1156
|
+
* Gets the balance of the chequebook.
|
|
1157
|
+
*
|
|
1158
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
953
1159
|
*/
|
|
954
|
-
async getChequebookBalance(
|
|
955
|
-
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(
|
|
1160
|
+
async getChequebookBalance(requestOptions) {
|
|
1161
|
+
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(requestOptions));
|
|
956
1162
|
}
|
|
957
1163
|
/**
|
|
958
|
-
*
|
|
1164
|
+
* Gets the last cheques for all peers.
|
|
1165
|
+
*
|
|
1166
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1167
|
+
*
|
|
1168
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
959
1169
|
*/
|
|
960
|
-
async getLastCheques(
|
|
961
|
-
return chequebook.getLastCheques(this.getRequestOptionsForCall(
|
|
1170
|
+
async getLastCheques(requestOptions) {
|
|
1171
|
+
return chequebook.getLastCheques(this.getRequestOptionsForCall(requestOptions));
|
|
962
1172
|
}
|
|
963
1173
|
/**
|
|
964
|
-
*
|
|
1174
|
+
* Gets the last cheques for a specific peer.
|
|
965
1175
|
*
|
|
966
|
-
*
|
|
1176
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1177
|
+
*
|
|
1178
|
+
* @param address Overlay address of peer.
|
|
1179
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
967
1180
|
*/
|
|
968
|
-
async getLastChequesForPeer(address,
|
|
1181
|
+
async getLastChequesForPeer(address, requestOptions) {
|
|
969
1182
|
address = new PeerAddress(address);
|
|
970
|
-
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(
|
|
1183
|
+
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(requestOptions), address);
|
|
971
1184
|
}
|
|
972
1185
|
/**
|
|
973
|
-
*
|
|
1186
|
+
* Gets the last cashout action for a specific peer.
|
|
974
1187
|
*
|
|
975
|
-
*
|
|
1188
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1189
|
+
*
|
|
1190
|
+
* @param address Overlay address of peer.
|
|
1191
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
976
1192
|
*/
|
|
977
|
-
async getLastCashoutAction(address,
|
|
1193
|
+
async getLastCashoutAction(address, requestOptions) {
|
|
978
1194
|
address = new PeerAddress(address);
|
|
979
|
-
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(
|
|
1195
|
+
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(requestOptions), address);
|
|
980
1196
|
}
|
|
981
1197
|
/**
|
|
982
|
-
*
|
|
1198
|
+
* Cashes out the last cheque for a specific peer.
|
|
1199
|
+
*
|
|
1200
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
983
1201
|
*
|
|
984
1202
|
* @param address Swarm address of peer
|
|
985
1203
|
* @param options
|
|
986
1204
|
* @param options.gasPrice Gas price for the cashout transaction in WEI
|
|
987
1205
|
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
1206
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
988
1207
|
*/
|
|
989
1208
|
async cashoutLastCheque(address, options, requestOptions) {
|
|
990
1209
|
address = new PeerAddress(address);
|
|
@@ -994,24 +1213,28 @@ export class Bee {
|
|
|
994
1213
|
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
995
1214
|
}
|
|
996
1215
|
/**
|
|
997
|
-
*
|
|
1216
|
+
* Deposits tokens from the node wallet into the chequebook.
|
|
998
1217
|
*
|
|
999
1218
|
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
1000
1219
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1220
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1221
|
+
*
|
|
1001
1222
|
* @return string Hash of the transaction
|
|
1002
1223
|
* @deprecated Use `depositBZZToChequebook` instead.
|
|
1003
1224
|
*/
|
|
1004
|
-
async depositTokens(amount, gasPrice,
|
|
1005
|
-
return this.depositBZZToChequebook(amount, gasPrice,
|
|
1225
|
+
async depositTokens(amount, gasPrice, requestOptions) {
|
|
1226
|
+
return this.depositBZZToChequebook(amount, gasPrice, requestOptions);
|
|
1006
1227
|
}
|
|
1007
1228
|
/**
|
|
1008
|
-
*
|
|
1229
|
+
* Deposits tokens from the node wallet into the chequebook.
|
|
1009
1230
|
*
|
|
1010
1231
|
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
1011
1232
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1233
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1234
|
+
*
|
|
1012
1235
|
* @return string Hash of the transaction
|
|
1013
1236
|
*/
|
|
1014
|
-
async depositBZZToChequebook(amount, gasPrice,
|
|
1237
|
+
async depositBZZToChequebook(amount, gasPrice, requestOptions) {
|
|
1015
1238
|
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
1016
1239
|
min: 1n,
|
|
1017
1240
|
name: 'amount'
|
|
@@ -1023,27 +1246,29 @@ export class Bee {
|
|
|
1023
1246
|
name: 'gasPrice'
|
|
1024
1247
|
});
|
|
1025
1248
|
}
|
|
1026
|
-
return chequebook.depositTokens(this.getRequestOptionsForCall(
|
|
1249
|
+
return chequebook.depositTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
|
|
1027
1250
|
}
|
|
1028
1251
|
/**
|
|
1029
|
-
*
|
|
1252
|
+
* Withdraws tokens from the chequebook to the node wallet.
|
|
1030
1253
|
*
|
|
1031
1254
|
* @param amount Amount of tokens to withdraw (must be positive integer)
|
|
1032
1255
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1256
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1257
|
+
*
|
|
1033
1258
|
* @return string Hash of the transaction
|
|
1034
1259
|
* @deprecated Use `withdrawBZZFromChequebook` instead.
|
|
1035
1260
|
*/
|
|
1036
|
-
async withdrawTokens(amount, gasPrice,
|
|
1037
|
-
return this.withdrawBZZFromChequebook(amount, gasPrice,
|
|
1261
|
+
async withdrawTokens(amount, gasPrice, requestOptions) {
|
|
1262
|
+
return this.withdrawBZZFromChequebook(amount, gasPrice, requestOptions);
|
|
1038
1263
|
}
|
|
1039
1264
|
/**
|
|
1040
|
-
*
|
|
1265
|
+
* Withdraws tokens from the chequebook to the node wallet.
|
|
1041
1266
|
*
|
|
1042
|
-
* @param amount
|
|
1043
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1044
|
-
* @return
|
|
1267
|
+
* @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
1268
|
+
* @param gasPrice Gas Price in WEI for the transaction call.
|
|
1269
|
+
* @return Transaction ID
|
|
1045
1270
|
*/
|
|
1046
|
-
async withdrawBZZFromChequebook(amount, gasPrice,
|
|
1271
|
+
async withdrawBZZFromChequebook(amount, gasPrice, requestOptions) {
|
|
1047
1272
|
// TODO: check BZZ in tests
|
|
1048
1273
|
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
1049
1274
|
min: 1n,
|
|
@@ -1056,67 +1281,95 @@ export class Bee {
|
|
|
1056
1281
|
name: 'gasPrice'
|
|
1057
1282
|
});
|
|
1058
1283
|
}
|
|
1059
|
-
return chequebook.withdrawTokens(this.getRequestOptionsForCall(
|
|
1284
|
+
return chequebook.withdrawTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
|
|
1060
1285
|
}
|
|
1061
|
-
|
|
1286
|
+
/**
|
|
1287
|
+
* Withdraws BZZ from the node wallet (not chequebook) to a whitelisted external wallet address.
|
|
1288
|
+
*
|
|
1289
|
+
* @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
1290
|
+
* @param address
|
|
1291
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1292
|
+
* @return Transaction ID
|
|
1293
|
+
*/
|
|
1294
|
+
async withdrawBZZToExternalWallet(amount, address, requestOptions) {
|
|
1062
1295
|
amount = amount instanceof BZZ ? amount : BZZ.fromPLUR(amount);
|
|
1063
1296
|
address = new EthAddress(address);
|
|
1064
|
-
return states.withdrawBZZ(this.getRequestOptionsForCall(
|
|
1297
|
+
return states.withdrawBZZ(this.getRequestOptionsForCall(requestOptions), amount, address);
|
|
1065
1298
|
}
|
|
1066
|
-
|
|
1299
|
+
/**
|
|
1300
|
+
* Withdraws DAI from the node wallet (not chequebook) to a whitelisted external wallet address.
|
|
1301
|
+
*
|
|
1302
|
+
* @param amount Amount of DAI tokens to withdraw. If not providing a `DAI` instance, the amount is denoted in wei.
|
|
1303
|
+
* @param address
|
|
1304
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1305
|
+
* @return Transaction ID
|
|
1306
|
+
*/
|
|
1307
|
+
async withdrawDAIToExternalWallet(amount, address, requestOptions) {
|
|
1067
1308
|
amount = amount instanceof DAI ? amount : DAI.fromWei(amount);
|
|
1068
1309
|
address = new EthAddress(address);
|
|
1069
|
-
return states.withdrawDAI(this.getRequestOptionsForCall(
|
|
1310
|
+
return states.withdrawDAI(this.getRequestOptionsForCall(requestOptions), amount, address);
|
|
1070
1311
|
}
|
|
1071
|
-
/*
|
|
1072
|
-
* Settlements endpoint
|
|
1073
|
-
*/
|
|
1074
1312
|
/**
|
|
1075
|
-
*
|
|
1313
|
+
* Gets the amount of sent and received micropayments from settlements with a peer.
|
|
1314
|
+
*
|
|
1315
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1076
1316
|
*
|
|
1077
1317
|
* @param address Swarm address of peer
|
|
1318
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1078
1319
|
*/
|
|
1079
|
-
async getSettlements(address,
|
|
1320
|
+
async getSettlements(address, requestOptions) {
|
|
1080
1321
|
address = new PeerAddress(address);
|
|
1081
|
-
return settlements.getSettlements(this.getRequestOptionsForCall(
|
|
1322
|
+
return settlements.getSettlements(this.getRequestOptionsForCall(requestOptions), address);
|
|
1082
1323
|
}
|
|
1083
1324
|
/**
|
|
1084
|
-
*
|
|
1325
|
+
* Gets settlements with all known peers and total amount sent or received.
|
|
1326
|
+
*
|
|
1327
|
+
* This is related to the bandwidth incentives and the chequebook.
|
|
1328
|
+
*
|
|
1329
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1085
1330
|
*/
|
|
1086
|
-
async getAllSettlements(
|
|
1087
|
-
return settlements.getAllSettlements(this.getRequestOptionsForCall(
|
|
1331
|
+
async getAllSettlements(requestOptions) {
|
|
1332
|
+
return settlements.getAllSettlements(this.getRequestOptionsForCall(requestOptions));
|
|
1088
1333
|
}
|
|
1089
1334
|
/**
|
|
1090
|
-
*
|
|
1335
|
+
* Gets the general status of the node.
|
|
1336
|
+
*
|
|
1337
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1091
1338
|
*/
|
|
1092
|
-
async getStatus(
|
|
1093
|
-
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(
|
|
1339
|
+
async getStatus(requestOptions) {
|
|
1340
|
+
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(requestOptions));
|
|
1094
1341
|
}
|
|
1095
1342
|
/**
|
|
1096
|
-
*
|
|
1343
|
+
* Gets the health of the node.
|
|
1344
|
+
*
|
|
1345
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1097
1346
|
*/
|
|
1098
|
-
async getHealth(
|
|
1099
|
-
return debugStatus.getHealth(this.getRequestOptionsForCall(
|
|
1347
|
+
async getHealth(requestOptions) {
|
|
1348
|
+
return debugStatus.getHealth(this.getRequestOptionsForCall(requestOptions));
|
|
1100
1349
|
}
|
|
1101
1350
|
/**
|
|
1102
|
-
*
|
|
1351
|
+
* Gets the readiness status of the node.
|
|
1352
|
+
*
|
|
1353
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1103
1354
|
*/
|
|
1104
|
-
async getReadiness(
|
|
1105
|
-
return debugStatus.getReadiness(this.getRequestOptionsForCall(
|
|
1355
|
+
async getReadiness(requestOptions) {
|
|
1356
|
+
return debugStatus.getReadiness(this.getRequestOptionsForCall(requestOptions));
|
|
1106
1357
|
}
|
|
1107
1358
|
/**
|
|
1108
|
-
* Get mode information of node
|
|
1359
|
+
* Get mode information of node.
|
|
1360
|
+
*
|
|
1361
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1109
1362
|
*/
|
|
1110
|
-
async getNodeInfo(
|
|
1111
|
-
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(
|
|
1363
|
+
async getNodeInfo(requestOptions) {
|
|
1364
|
+
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(requestOptions));
|
|
1112
1365
|
}
|
|
1113
1366
|
/**
|
|
1114
1367
|
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
1115
1368
|
*
|
|
1116
|
-
* @param
|
|
1369
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1117
1370
|
*/
|
|
1118
|
-
async isSupportedExactVersion(
|
|
1119
|
-
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(
|
|
1371
|
+
async isSupportedExactVersion(requestOptions) {
|
|
1372
|
+
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(requestOptions));
|
|
1120
1373
|
}
|
|
1121
1374
|
/**
|
|
1122
1375
|
*
|
|
@@ -1124,53 +1377,56 @@ export class Bee {
|
|
|
1124
1377
|
*
|
|
1125
1378
|
* This should be the main way how to check compatibility for your app and Bee node.
|
|
1126
1379
|
*
|
|
1127
|
-
* @param
|
|
1380
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1128
1381
|
*/
|
|
1129
|
-
async isSupportedApiVersion(
|
|
1130
|
-
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(
|
|
1382
|
+
async isSupportedApiVersion(requestOptions) {
|
|
1383
|
+
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(requestOptions));
|
|
1131
1384
|
}
|
|
1132
1385
|
/**
|
|
1133
1386
|
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
1134
1387
|
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
1135
1388
|
*
|
|
1136
|
-
* @param
|
|
1389
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1137
1390
|
*/
|
|
1138
|
-
async getVersions(
|
|
1139
|
-
return debugStatus.getVersions(this.getRequestOptionsForCall(
|
|
1391
|
+
async getVersions(requestOptions) {
|
|
1392
|
+
return debugStatus.getVersions(this.getRequestOptionsForCall(requestOptions));
|
|
1140
1393
|
}
|
|
1141
1394
|
/**
|
|
1142
|
-
* Get reserve state
|
|
1395
|
+
* Get reserve state.
|
|
1396
|
+
*
|
|
1397
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1143
1398
|
*/
|
|
1144
|
-
async getReserveState(
|
|
1145
|
-
return states.getReserveState(this.getRequestOptionsForCall(
|
|
1399
|
+
async getReserveState(requestOptions) {
|
|
1400
|
+
return states.getReserveState(this.getRequestOptionsForCall(requestOptions));
|
|
1146
1401
|
}
|
|
1147
1402
|
/**
|
|
1148
|
-
*
|
|
1403
|
+
* Gets chain state.
|
|
1404
|
+
*
|
|
1405
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1149
1406
|
*/
|
|
1150
|
-
async getChainState(
|
|
1151
|
-
return states.getChainState(this.getRequestOptionsForCall(
|
|
1407
|
+
async getChainState(requestOptions) {
|
|
1408
|
+
return states.getChainState(this.getRequestOptionsForCall(requestOptions));
|
|
1152
1409
|
}
|
|
1153
1410
|
/**
|
|
1154
|
-
*
|
|
1411
|
+
* Gets DAI and BZZ balances of the Bee node wallet.
|
|
1155
1412
|
*
|
|
1156
|
-
* @param
|
|
1413
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1157
1414
|
*/
|
|
1158
|
-
async getWalletBalance(
|
|
1159
|
-
return states.getWalletBalance(this.getRequestOptionsForCall(
|
|
1415
|
+
async getWalletBalance(requestOptions) {
|
|
1416
|
+
return states.getWalletBalance(this.getRequestOptionsForCall(requestOptions));
|
|
1160
1417
|
}
|
|
1161
1418
|
/**
|
|
1162
|
-
* Creates new postage batch
|
|
1419
|
+
* Creates a new postage batch, spending BZZ tokens from the node wallet.
|
|
1163
1420
|
*
|
|
1164
|
-
*
|
|
1165
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction#keep-your-data-alive).
|
|
1421
|
+
* Use {@link buyStorage} for a more convenient way to create postage batch.
|
|
1166
1422
|
*
|
|
1167
|
-
*
|
|
1423
|
+
* For better understanding what each parameter means and what the optimal values are, see
|
|
1424
|
+
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction#keep-your-data-alive).
|
|
1168
1425
|
*
|
|
1169
|
-
* @param amount
|
|
1170
|
-
* @param depth
|
|
1426
|
+
* @param amount TTL parameter - 1 day at the minimum of 24,000 storage price requires an amount of 414,720,000.
|
|
1427
|
+
* @param depth Capacity parameter - 17..255 - depth 17 provides 512MB of theoretical capacity, 18 provides 1GB, 19 provides 2GB, etc.
|
|
1171
1428
|
* @param options Options for creation of postage batch
|
|
1172
|
-
* @
|
|
1173
|
-
* @throws TypeError if non-integer value is passed to amount or depth
|
|
1429
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1174
1430
|
*
|
|
1175
1431
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1176
1432
|
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
@@ -1197,193 +1453,388 @@ export class Bee {
|
|
|
1197
1453
|
}
|
|
1198
1454
|
return stamp;
|
|
1199
1455
|
}
|
|
1200
|
-
|
|
1456
|
+
/**
|
|
1457
|
+
* A more convenient method to create a postage batch, which is analogous
|
|
1458
|
+
* to buying storage for a certain size and duration on the Swarm network.
|
|
1459
|
+
*
|
|
1460
|
+
* Use {@link getStorageCost} to calculate the cost of creating a postage batch.
|
|
1461
|
+
*
|
|
1462
|
+
* For the low level API, use {@link createPostageBatch}.
|
|
1463
|
+
*
|
|
1464
|
+
* @example const batchId = await bee.buyStorage(Size.fromGigabytes(8), Duration.fromDays(31))
|
|
1465
|
+
* @param size
|
|
1466
|
+
* @param duration
|
|
1467
|
+
* @param options
|
|
1468
|
+
* @param requestOptions
|
|
1469
|
+
* @param encryption
|
|
1470
|
+
* @param erasureCodeLevel
|
|
1471
|
+
* @returns
|
|
1472
|
+
*/
|
|
1473
|
+
async buyStorage(size, duration, options, requestOptions, encryption, erasureCodeLevel) {
|
|
1201
1474
|
const chainState = await this.getChainState(requestOptions);
|
|
1202
1475
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1203
|
-
const depth = getDepthForSize(size);
|
|
1476
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1204
1477
|
if (options) {
|
|
1205
1478
|
options = preparePostageBatchOptions(options);
|
|
1206
1479
|
}
|
|
1207
1480
|
return this.createPostageBatch(amount, depth, options, requestOptions);
|
|
1208
1481
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1482
|
+
/**
|
|
1483
|
+
* Calculates the estimated BZZ cost for creating a postage batch for the given size and duration.
|
|
1484
|
+
*
|
|
1485
|
+
* Use {@link buyStorage} to create a postage batch with the calculated cost.
|
|
1486
|
+
*
|
|
1487
|
+
* @example const bzz = await bee.getStorageCost(Size.fromGigabytes(1), Duration.fromDays(30))
|
|
1488
|
+
*
|
|
1489
|
+
* @param size Size of the data to be stored.
|
|
1490
|
+
* @param duration Duration for which the data should be stored.
|
|
1491
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1492
|
+
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1493
|
+
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1494
|
+
* @returns
|
|
1495
|
+
*/
|
|
1496
|
+
async getStorageCost(size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1497
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1211
1498
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1212
|
-
const depth = getDepthForSize(size);
|
|
1499
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1213
1500
|
return getStampCost(depth, amount);
|
|
1214
1501
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1502
|
+
/**
|
|
1503
|
+
* Extends the storage of a postage batch by either increasing its size, duration or both.
|
|
1504
|
+
*
|
|
1505
|
+
* The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
|
|
1506
|
+
*
|
|
1507
|
+
* Use {@link getExtensionCost} to calculate the cost of extending the storage.
|
|
1508
|
+
*
|
|
1509
|
+
* @example
|
|
1510
|
+
* // Increases the size to 8GB (unless it is already at 8GB or higher)
|
|
1511
|
+
* // and extends the duration by 30 days (regardless of the current duration).
|
|
1512
|
+
* await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromDays(30))
|
|
1513
|
+
*
|
|
1514
|
+
* @example
|
|
1515
|
+
* // To increase the duration to a desired date, pass a second parameter to `Duration.fromEndDate`.
|
|
1516
|
+
* // With the second parameter, the duration is set to the difference between the current end date and the desired end date.
|
|
1517
|
+
* const oneMonth = new Date(Date.now() + Dates.days(31))
|
|
1518
|
+
* const batch = await bee.getPostageBatch(batchId)
|
|
1519
|
+
* await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromEndDate(oneMonth, batch.duration.toEndDate()))
|
|
1520
|
+
*
|
|
1521
|
+
* @param postageBatchId Batch ID of the postage batch to extend.
|
|
1522
|
+
* @param size Absolute size to extend the postage batch to.
|
|
1523
|
+
* @param duration Relative duration to extend the postage batch by.
|
|
1524
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1525
|
+
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1526
|
+
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1527
|
+
* @returns
|
|
1528
|
+
*/
|
|
1529
|
+
async extendStorage(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1530
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1531
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1532
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1533
|
+
const depthDelta = depth - batch.depth;
|
|
1534
|
+
const multiplier = depthDelta <= 0 ? 1n : 2n ** BigInt(depthDelta);
|
|
1535
|
+
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1536
|
+
const additionalAmount = getAmountForDuration(duration, chainState.currentPrice, blockTime);
|
|
1537
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
|
|
1538
|
+
const targetAmount = duration.isZero() ? currentAmount * multiplier : currentAmount + additionalAmount * multiplier;
|
|
1539
|
+
const amountDelta = targetAmount - currentAmount;
|
|
1540
|
+
const transactionId = await this.topUpBatch(batch.batchID, amountDelta, requestOptions);
|
|
1541
|
+
if (depthDelta > 0) {
|
|
1542
|
+
return this.diluteBatch(batch.batchID, depth, requestOptions);
|
|
1543
|
+
}
|
|
1544
|
+
return transactionId;
|
|
1545
|
+
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Extends the storage size of a postage batch by increasing its depth.
|
|
1548
|
+
*
|
|
1549
|
+
* Use {@link getSizeExtensionCost} to calculate the cost of extending the size.
|
|
1550
|
+
* Use {@link extendStorage} to extend both size and duration.
|
|
1551
|
+
*
|
|
1552
|
+
* @param postageBatchId
|
|
1553
|
+
* @param size Absolute size to extend the postage batch to.
|
|
1554
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1555
|
+
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1556
|
+
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1557
|
+
* @returns
|
|
1558
|
+
*/
|
|
1559
|
+
async extendStorageSize(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
|
|
1560
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1561
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1562
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1218
1563
|
const delta = depth - batch.depth;
|
|
1219
1564
|
if (delta <= 0) {
|
|
1220
1565
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1221
1566
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1567
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1568
|
+
await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, requestOptions);
|
|
1569
|
+
return this.diluteBatch(batch.batchID, depth, requestOptions);
|
|
1224
1570
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1571
|
+
/**
|
|
1572
|
+
* Extends the duration of a postage batch.
|
|
1573
|
+
*
|
|
1574
|
+
* Use {@link getDurationExtensionCost} to calculate the cost of extending the duration.
|
|
1575
|
+
* Use {@link extendStorage} to extend both size and duration.
|
|
1576
|
+
*
|
|
1577
|
+
* @param postageBatchId
|
|
1578
|
+
* @param duration Relative duration to extend the postage batch by.
|
|
1579
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1580
|
+
* @returns
|
|
1581
|
+
*/
|
|
1582
|
+
async extendStorageDuration(postageBatchId, duration, requestOptions) {
|
|
1583
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1584
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1228
1585
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1229
|
-
return this.topUpBatch(batch.batchID, amount,
|
|
1586
|
+
return this.topUpBatch(batch.batchID, amount, requestOptions);
|
|
1230
1587
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1588
|
+
/**
|
|
1589
|
+
* Calculates the cost of extending both the duration and the capacity of a postage batch.
|
|
1590
|
+
*
|
|
1591
|
+
* The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
|
|
1592
|
+
*
|
|
1593
|
+
* Use {@link extendStorage} to extend the the duration and capacity of a postage batch.
|
|
1594
|
+
*
|
|
1595
|
+
* @param postageBatchId
|
|
1596
|
+
* @param size Absolute size to extend the postage batch to.
|
|
1597
|
+
* @param duration Relative duration to extend the postage batch by.
|
|
1598
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1599
|
+
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1600
|
+
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1601
|
+
* @returns
|
|
1602
|
+
*/
|
|
1603
|
+
async getExtensionCost(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1604
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1605
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1606
|
+
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1607
|
+
const amount = duration.isZero() ? 0n : getAmountForDuration(duration, chainState.currentPrice, blockTime);
|
|
1608
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1609
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
|
|
1610
|
+
const currentCost = getStampCost(batch.depth, currentAmount);
|
|
1611
|
+
const newCost = getStampCost(depth, currentAmount + amount);
|
|
1612
|
+
return newCost.minus(currentCost);
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* Calculates the cost of extending the size of a postage batch.
|
|
1616
|
+
*
|
|
1617
|
+
* The size is ABSOLUTE, so if the postage batch already equals or is greater than the given size,
|
|
1618
|
+
* the cost will be zero.
|
|
1619
|
+
*
|
|
1620
|
+
* Use {@link extendStorageSize} to extend the size of a postage batch.
|
|
1621
|
+
*
|
|
1622
|
+
* Use {@link getExtensionCost} to get the cost of extending both size and duration.
|
|
1623
|
+
* Use {@link getDurationExtensionCost} to get the cost of extending only the duration.
|
|
1624
|
+
*
|
|
1625
|
+
* @param postageBatchId
|
|
1626
|
+
* @param size
|
|
1627
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1628
|
+
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1629
|
+
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1630
|
+
* @returns
|
|
1631
|
+
*/
|
|
1632
|
+
async getSizeExtensionCost(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
|
|
1633
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1634
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1635
|
+
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1243
1636
|
const delta = depth - batch.depth;
|
|
1244
1637
|
if (delta <= 0) {
|
|
1245
1638
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1246
1639
|
}
|
|
1247
|
-
const
|
|
1248
|
-
const
|
|
1249
|
-
|
|
1640
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1641
|
+
const currentCost = getStampCost(batch.depth, currentAmount);
|
|
1642
|
+
const newCost = getStampCost(depth, currentAmount);
|
|
1643
|
+
return newCost.minus(currentCost);
|
|
1250
1644
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1645
|
+
/**
|
|
1646
|
+
* Calculates the cost of extending the duration of a postage batch.
|
|
1647
|
+
*
|
|
1648
|
+
* The duration is RELATIVE to the current duration of the postage batch,
|
|
1649
|
+
* e.g. specifying `Duration.fromDays(30)` will extend the current duration by 30 days,
|
|
1650
|
+
* regardless of the current duration.
|
|
1651
|
+
*
|
|
1652
|
+
* Use {@link extendStorageDuration} to extend the duration of a postage batch.
|
|
1653
|
+
*
|
|
1654
|
+
* Use {@link getExtensionCost} to get the cost of extending both size and duration.
|
|
1655
|
+
* Use {@link getSizeExtensionCost} to get the cost of extending only the size.
|
|
1656
|
+
*
|
|
1657
|
+
* @param postageBatchId
|
|
1658
|
+
* @param duration
|
|
1659
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1660
|
+
* @returns
|
|
1661
|
+
*/
|
|
1662
|
+
async getDurationExtensionCost(postageBatchId, duration, requestOptions) {
|
|
1663
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1664
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1254
1665
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1255
1666
|
return getStampCost(batch.depth, amount);
|
|
1256
1667
|
}
|
|
1257
1668
|
/**
|
|
1258
|
-
*
|
|
1669
|
+
* Increases the duration of a postage batch by increasing its amount.
|
|
1670
|
+
*
|
|
1671
|
+
* For a more convenient way to extend the postage batch, refer to the methods below.
|
|
1672
|
+
*
|
|
1673
|
+
* Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
|
|
1674
|
+
* to calculate the costs of extending the postage batch properties.
|
|
1675
|
+
*
|
|
1676
|
+
* Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
|
|
1677
|
+
* to extend the postage batch properties.
|
|
1259
1678
|
*
|
|
1260
1679
|
* For better understanding what each parameter means and what are the optimal values please see
|
|
1261
1680
|
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1262
1681
|
*
|
|
1263
1682
|
* @param postageBatchId Batch ID
|
|
1264
1683
|
* @param amount Amount to be added to the batch
|
|
1265
|
-
* @param
|
|
1684
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1266
1685
|
*
|
|
1267
1686
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1268
1687
|
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
|
|
1269
1688
|
*/
|
|
1270
|
-
async topUpBatch(postageBatchId, amount,
|
|
1689
|
+
async topUpBatch(postageBatchId, amount, requestOptions) {
|
|
1271
1690
|
postageBatchId = new BatchId(postageBatchId);
|
|
1272
1691
|
const amountString = asNumberString(amount, {
|
|
1273
1692
|
min: 1n,
|
|
1274
1693
|
name: 'amount'
|
|
1275
1694
|
});
|
|
1276
|
-
return stamps.topUpBatch(this.getRequestOptionsForCall(
|
|
1695
|
+
return stamps.topUpBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, amountString);
|
|
1277
1696
|
}
|
|
1278
1697
|
/**
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1698
|
+
* Dilutes a postage batch to extend its capacity by increasing its depth.
|
|
1699
|
+
*
|
|
1700
|
+
* This is a free operation, as for every depth increase, the capacity is doubled,
|
|
1701
|
+
* but the amount (duration) is halved.
|
|
1702
|
+
*
|
|
1703
|
+
* To increase the capacity of the postage batch while retaining the same amount (duration),
|
|
1704
|
+
* you need to top up the postage batch first using {@link topUpBatch}.
|
|
1705
|
+
*
|
|
1706
|
+
* For a more convenient way to extend the postage batch, refer to the methods below.
|
|
1707
|
+
*
|
|
1708
|
+
* Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
|
|
1709
|
+
* to calculate the costs of extending the postage batch properties.
|
|
1710
|
+
*
|
|
1711
|
+
* Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
|
|
1712
|
+
* to extend the postage batch properties.
|
|
1281
1713
|
*
|
|
1282
1714
|
* For better understanding what each parameter means and what are the optimal values please see
|
|
1283
1715
|
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1284
1716
|
*
|
|
1285
1717
|
* @param postageBatchId Batch ID
|
|
1286
1718
|
* @param depth Amount to be added to the batch
|
|
1287
|
-
* @param
|
|
1719
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1288
1720
|
*
|
|
1289
1721
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1290
1722
|
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
|
|
1291
1723
|
*/
|
|
1292
|
-
async diluteBatch(postageBatchId, depth,
|
|
1724
|
+
async diluteBatch(postageBatchId, depth, requestOptions) {
|
|
1293
1725
|
postageBatchId = new BatchId(postageBatchId);
|
|
1294
1726
|
depth = Types.asNumber(depth, {
|
|
1295
1727
|
name: 'depth',
|
|
1296
1728
|
min: 18,
|
|
1297
1729
|
max: 255
|
|
1298
1730
|
});
|
|
1299
|
-
return stamps.diluteBatch(this.getRequestOptionsForCall(
|
|
1731
|
+
return stamps.diluteBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, depth);
|
|
1300
1732
|
}
|
|
1301
1733
|
/**
|
|
1302
|
-
*
|
|
1734
|
+
* Returns details for specific postage batch.
|
|
1303
1735
|
*
|
|
1304
1736
|
* @param postageBatchId Batch ID
|
|
1737
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1305
1738
|
*
|
|
1306
1739
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1307
1740
|
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
|
|
1308
1741
|
*/
|
|
1309
|
-
async getPostageBatch(postageBatchId,
|
|
1742
|
+
async getPostageBatch(postageBatchId, requestOptions) {
|
|
1310
1743
|
postageBatchId = new BatchId(postageBatchId);
|
|
1311
|
-
return stamps.getPostageBatch(this.getRequestOptionsForCall(
|
|
1744
|
+
return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId);
|
|
1312
1745
|
}
|
|
1313
1746
|
/**
|
|
1314
1747
|
* Return detailed information related to buckets for specific postage batch.
|
|
1315
1748
|
*
|
|
1316
1749
|
* @param postageBatchId Batch ID
|
|
1750
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1317
1751
|
*
|
|
1318
1752
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1319
1753
|
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
|
|
1320
1754
|
*/
|
|
1321
|
-
async getPostageBatchBuckets(postageBatchId,
|
|
1755
|
+
async getPostageBatchBuckets(postageBatchId, requestOptions) {
|
|
1322
1756
|
postageBatchId = new BatchId(postageBatchId);
|
|
1323
|
-
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(
|
|
1757
|
+
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(requestOptions), postageBatchId);
|
|
1324
1758
|
}
|
|
1325
1759
|
/**
|
|
1326
|
-
*
|
|
1760
|
+
* Returns all postage batches that belongs to the node.
|
|
1761
|
+
*
|
|
1762
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1327
1763
|
*
|
|
1328
1764
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1329
1765
|
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1330
1766
|
* @deprecated Use `getPostageBatches` instead
|
|
1331
1767
|
*/
|
|
1332
|
-
async getAllPostageBatch(
|
|
1333
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(
|
|
1768
|
+
async getAllPostageBatch(requestOptions) {
|
|
1769
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
|
|
1334
1770
|
}
|
|
1335
1771
|
/**
|
|
1336
|
-
*
|
|
1772
|
+
* Returns all postage batches that are globally available on the Swarm network.
|
|
1773
|
+
*
|
|
1774
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1775
|
+
*
|
|
1337
1776
|
* @deprecated Use `getGlobalPostageBatches` instead
|
|
1338
1777
|
*/
|
|
1339
|
-
async getAllGlobalPostageBatch(
|
|
1340
|
-
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(
|
|
1778
|
+
async getAllGlobalPostageBatch(requestOptions) {
|
|
1779
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
|
|
1341
1780
|
}
|
|
1342
1781
|
/**
|
|
1343
|
-
*
|
|
1782
|
+
* Returns all postage batches that belong to the node.
|
|
1783
|
+
*
|
|
1784
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1344
1785
|
*
|
|
1345
1786
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1346
1787
|
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1347
1788
|
*/
|
|
1348
|
-
async getPostageBatches(
|
|
1349
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(
|
|
1789
|
+
async getPostageBatches(requestOptions) {
|
|
1790
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions));
|
|
1350
1791
|
}
|
|
1351
1792
|
/**
|
|
1352
|
-
*
|
|
1793
|
+
* Returns all globally available postage batches.
|
|
1794
|
+
*
|
|
1795
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1353
1796
|
*/
|
|
1354
|
-
async getGlobalPostageBatches(
|
|
1355
|
-
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(
|
|
1797
|
+
async getGlobalPostageBatches(requestOptions) {
|
|
1798
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions));
|
|
1356
1799
|
}
|
|
1357
1800
|
/**
|
|
1358
|
-
*
|
|
1801
|
+
* Fetches the list of all current pending transactions for the Bee node.
|
|
1802
|
+
*
|
|
1803
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1359
1804
|
*/
|
|
1360
|
-
async getAllPendingTransactions(
|
|
1361
|
-
return transactions.getAllTransactions(this.getRequestOptionsForCall(
|
|
1805
|
+
async getAllPendingTransactions(requestOptions) {
|
|
1806
|
+
return transactions.getAllTransactions(this.getRequestOptionsForCall(requestOptions));
|
|
1362
1807
|
}
|
|
1363
1808
|
/**
|
|
1364
|
-
*
|
|
1809
|
+
* Fetches the transaction information for a specific transaction.
|
|
1810
|
+
*
|
|
1365
1811
|
* @param transactionHash
|
|
1812
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1366
1813
|
*/
|
|
1367
|
-
async getPendingTransaction(transactionHash,
|
|
1814
|
+
async getPendingTransaction(transactionHash, requestOptions) {
|
|
1368
1815
|
transactionHash = new TransactionId(transactionHash);
|
|
1369
|
-
return transactions.getTransaction(this.getRequestOptionsForCall(
|
|
1816
|
+
return transactions.getTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
|
|
1370
1817
|
}
|
|
1371
1818
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1819
|
+
* Rebroadcasts already created transaction.
|
|
1820
|
+
*
|
|
1821
|
+
* This is mainly needed when the transaction falls off mempool or is not incorporated into any block.
|
|
1374
1822
|
*
|
|
1375
1823
|
* @param transactionHash
|
|
1824
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1376
1825
|
*/
|
|
1377
|
-
async rebroadcastPendingTransaction(transactionHash,
|
|
1826
|
+
async rebroadcastPendingTransaction(transactionHash, requestOptions) {
|
|
1378
1827
|
transactionHash = new TransactionId(transactionHash);
|
|
1379
|
-
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(
|
|
1828
|
+
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
|
|
1380
1829
|
}
|
|
1381
1830
|
/**
|
|
1382
|
-
* Cancels a currently pending transaction
|
|
1831
|
+
* Cancels a currently pending transaction.
|
|
1832
|
+
*
|
|
1383
1833
|
* @param transactionHash
|
|
1384
1834
|
* @param gasPrice
|
|
1835
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1385
1836
|
*/
|
|
1386
|
-
async cancelPendingTransaction(transactionHash, gasPrice,
|
|
1837
|
+
async cancelPendingTransaction(transactionHash, gasPrice, requestOptions) {
|
|
1387
1838
|
transactionHash = new TransactionId(transactionHash);
|
|
1388
1839
|
let gasPriceString;
|
|
1389
1840
|
if (gasPrice) {
|
|
@@ -1392,43 +1843,43 @@ export class Bee {
|
|
|
1392
1843
|
name: 'gasPrice'
|
|
1393
1844
|
});
|
|
1394
1845
|
}
|
|
1395
|
-
return transactions.cancelTransaction(this.getRequestOptionsForCall(
|
|
1846
|
+
return transactions.cancelTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash, gasPriceString);
|
|
1396
1847
|
}
|
|
1397
1848
|
/**
|
|
1398
|
-
* Gets the amount of staked BZZ
|
|
1849
|
+
* Gets the amount of staked BZZ.
|
|
1399
1850
|
*
|
|
1400
|
-
* @param
|
|
1851
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1401
1852
|
*/
|
|
1402
|
-
async getStake(
|
|
1403
|
-
return stake.getStake(this.getRequestOptionsForCall(
|
|
1853
|
+
async getStake(requestOptions) {
|
|
1854
|
+
return stake.getStake(this.getRequestOptionsForCall(requestOptions));
|
|
1404
1855
|
}
|
|
1405
1856
|
/**
|
|
1406
1857
|
* Gets the amount of withdrawable staked BZZ.
|
|
1407
1858
|
*
|
|
1408
|
-
* @param
|
|
1859
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1409
1860
|
*/
|
|
1410
|
-
async getWithdrawableStake(
|
|
1411
|
-
return stake.getWithdrawableStake(this.getRequestOptionsForCall(
|
|
1861
|
+
async getWithdrawableStake(requestOptions) {
|
|
1862
|
+
return stake.getWithdrawableStake(this.getRequestOptionsForCall(requestOptions));
|
|
1412
1863
|
}
|
|
1413
1864
|
/**
|
|
1414
|
-
* Withdraws
|
|
1865
|
+
* Withdraws all surplus staked BZZ to the node wallet.
|
|
1415
1866
|
*
|
|
1416
|
-
* Use the
|
|
1867
|
+
* Use the {@link getWithdrawableStake} method to check how much surplus stake is available.
|
|
1417
1868
|
*
|
|
1418
|
-
* @param
|
|
1869
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1419
1870
|
*/
|
|
1420
|
-
async withdrawSurplusStake(
|
|
1421
|
-
return stake.withdrawSurplusStake(this.getRequestOptionsForCall(
|
|
1871
|
+
async withdrawSurplusStake(requestOptions) {
|
|
1872
|
+
return stake.withdrawSurplusStake(this.getRequestOptionsForCall(requestOptions));
|
|
1422
1873
|
}
|
|
1423
1874
|
/**
|
|
1424
1875
|
* Withdraws all staked BZZ to the node wallet.
|
|
1425
1876
|
*
|
|
1426
1877
|
* **Only available when the staking contract is paused and is in the process of being migrated to a new contract!**
|
|
1427
1878
|
*
|
|
1428
|
-
* @param
|
|
1879
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1429
1880
|
*/
|
|
1430
|
-
async migrateStake(
|
|
1431
|
-
return stake.migrateStake(this.getRequestOptionsForCall(
|
|
1881
|
+
async migrateStake(requestOptions) {
|
|
1882
|
+
return stake.migrateStake(this.getRequestOptionsForCall(requestOptions));
|
|
1432
1883
|
}
|
|
1433
1884
|
/**
|
|
1434
1885
|
* Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
|
|
@@ -1436,7 +1887,8 @@ export class Bee {
|
|
|
1436
1887
|
* Be aware that staked BZZ tokens can **not** be withdrawn.
|
|
1437
1888
|
*
|
|
1438
1889
|
* @param amount Amount of BZZ tokens to be staked. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
1439
|
-
* @param options
|
|
1890
|
+
* @param options
|
|
1891
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1440
1892
|
*/
|
|
1441
1893
|
async depositStake(amount, options, requestOptions) {
|
|
1442
1894
|
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
@@ -1449,12 +1901,14 @@ export class Bee {
|
|
|
1449
1901
|
return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
|
|
1450
1902
|
}
|
|
1451
1903
|
/**
|
|
1452
|
-
* Gets current status of node in redistribution game
|
|
1904
|
+
* Gets current status of node in redistribution game.
|
|
1453
1905
|
*
|
|
1454
|
-
* @param
|
|
1906
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1907
|
+
*
|
|
1908
|
+
* @see [Bee API reference - `GET /redistributionstate`](https://docs.ethswarm.org/api/#tag/RedistributionState/paths/~1redistributionstate/get)
|
|
1455
1909
|
*/
|
|
1456
|
-
async getRedistributionState(
|
|
1457
|
-
return stake.getRedistributionState(this.getRequestOptionsForCall(
|
|
1910
|
+
async getRedistributionState(requestOptions) {
|
|
1911
|
+
return stake.getRedistributionState(this.getRequestOptionsForCall(requestOptions));
|
|
1458
1912
|
}
|
|
1459
1913
|
async waitForUsablePostageStamp(id, timeout = 240000) {
|
|
1460
1914
|
const TIME_STEP = 3000;
|
|
@@ -1471,10 +1925,10 @@ export class Bee {
|
|
|
1471
1925
|
}
|
|
1472
1926
|
throw new BeeError('Timeout on waiting for postage stamp to become usable');
|
|
1473
1927
|
}
|
|
1474
|
-
getRequestOptionsForCall(
|
|
1475
|
-
if (
|
|
1476
|
-
|
|
1928
|
+
getRequestOptionsForCall(requestOptions) {
|
|
1929
|
+
if (requestOptions) {
|
|
1930
|
+
requestOptions = prepareBeeRequestOptions(requestOptions);
|
|
1477
1931
|
}
|
|
1478
|
-
return
|
|
1932
|
+
return requestOptions ? Objects.deepMerge2(this.requestOptions, requestOptions) : this.requestOptions;
|
|
1479
1933
|
}
|
|
1480
1934
|
}
|