@ethersphere/bee-js 8.3.0 → 9.0.1
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/README.md +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tar-writer.js +4 -0
- package/dist/cjs/utils/tar.browser.js +1 -1
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +141 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tar-writer.js +3 -0
- package/dist/mjs/utils/tar.browser.js +1 -1
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +215 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
package/dist/mjs/bee.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { Objects, System } from 'cafe-utility';
|
|
2
|
-
import {
|
|
3
|
-
import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
|
|
1
|
+
import { Binary, Objects, System, Types } from 'cafe-utility';
|
|
2
|
+
import { makeContentAddressedChunk } from "./chunk/cac.js";
|
|
3
|
+
import { downloadSingleOwnerChunk, makeSOCAddress, makeSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
|
|
4
4
|
import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
|
|
5
|
-
import { getJsonData, setJsonData } from "./feed/json.js";
|
|
6
5
|
import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
|
|
7
|
-
import { makeTopic, makeTopicFromString } from "./feed/topic.js";
|
|
8
|
-
import { DEFAULT_FEED_TYPE, assertFeedType } from "./feed/type.js";
|
|
9
6
|
import * as bytes from "./modules/bytes.js";
|
|
10
7
|
import * as bzz from "./modules/bzz.js";
|
|
11
8
|
import * as chunk from "./modules/chunk.js";
|
|
@@ -17,25 +14,29 @@ import * as stake from "./modules/debug/stake.js";
|
|
|
17
14
|
import * as stamps from "./modules/debug/stamps.js";
|
|
18
15
|
import * as states from "./modules/debug/states.js";
|
|
19
16
|
import * as debugStatus from "./modules/debug/status.js";
|
|
20
|
-
import * as debugTag from "./modules/debug/tag.js";
|
|
21
17
|
import * as transactions from "./modules/debug/transactions.js";
|
|
22
18
|
import { postEnvelope } from "./modules/envelope.js";
|
|
23
|
-
import { createFeedManifest } from "./modules/feed.js";
|
|
19
|
+
import { createFeedManifest, fetchLatestFeedUpdate } from "./modules/feed.js";
|
|
24
20
|
import * as grantee from "./modules/grantee.js";
|
|
21
|
+
import * as gsoc from "./modules/gsoc.js";
|
|
25
22
|
import * as pinning from "./modules/pinning.js";
|
|
26
23
|
import * as pss from "./modules/pss.js";
|
|
27
24
|
import * as status from "./modules/status.js";
|
|
28
25
|
import * as stewardship from "./modules/stewardship.js";
|
|
29
26
|
import * as tag from "./modules/tag.js";
|
|
30
|
-
import { CHUNK_SIZE,
|
|
31
|
-
import {
|
|
27
|
+
import { CHUNK_SIZE, STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
|
|
28
|
+
import { Bytes } from "./utils/bytes.js";
|
|
29
|
+
import { hashDirectory, streamDirectory, streamFiles } from "./utils/chunk-stream.js";
|
|
32
30
|
import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
|
|
33
31
|
import { makeCollectionFromFS } from "./utils/collection.node.js";
|
|
34
32
|
import { prepareWebsocketData } from "./utils/data.js";
|
|
35
33
|
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
36
|
-
import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
|
|
37
34
|
import { fileArrayBuffer, isFile } from "./utils/file.js";
|
|
38
|
-
import {
|
|
35
|
+
import { ResourceLocator } from "./utils/resource-locator.js";
|
|
36
|
+
import { getAmountForDuration, getDepthForSize, getStampCost } from "./utils/stamps.js";
|
|
37
|
+
import { BZZ } from "./utils/tokens.js";
|
|
38
|
+
import { asNumberString, assertData, assertFileData, makeTagUid, prepareAllTagsOptions, prepareBeeRequestOptions, prepareCollectionUploadOptions, prepareDownloadOptions, prepareFileUploadOptions, prepareGsocMessageHandler, preparePostageBatchOptions, preparePssMessageHandler, prepareRedundantUploadOptions, prepareTransactionOptions, prepareUploadOptions } from "./utils/type.js";
|
|
39
|
+
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
39
40
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
40
41
|
/**
|
|
41
42
|
* The main component that abstracts operations available on the main Bee API.
|
|
@@ -55,11 +56,11 @@ export class Bee {
|
|
|
55
56
|
// unnecessary redirects.
|
|
56
57
|
this.url = stripLastSlash(url);
|
|
57
58
|
if (options?.signer) {
|
|
58
|
-
this.signer =
|
|
59
|
+
this.signer = new PrivateKey(options.signer);
|
|
59
60
|
}
|
|
60
61
|
this.requestOptions = {
|
|
61
62
|
baseURL: this.url,
|
|
62
|
-
timeout: options?.timeout ??
|
|
63
|
+
timeout: options?.timeout ?? 0,
|
|
63
64
|
headers: options?.headers,
|
|
64
65
|
onRequest: options?.onRequest,
|
|
65
66
|
httpAgent: options?.httpAgent,
|
|
@@ -78,11 +79,10 @@ export class Bee {
|
|
|
78
79
|
* @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
|
|
79
80
|
*/
|
|
80
81
|
async uploadData(postageBatchId, data, options, requestOptions) {
|
|
81
|
-
|
|
82
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
82
83
|
assertData(data);
|
|
83
|
-
assertRequestOptions(requestOptions);
|
|
84
84
|
if (options) {
|
|
85
|
-
|
|
85
|
+
options = prepareRedundantUploadOptions(options);
|
|
86
86
|
}
|
|
87
87
|
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
88
88
|
}
|
|
@@ -92,39 +92,40 @@ export class Bee {
|
|
|
92
92
|
* @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
|
|
93
93
|
*/
|
|
94
94
|
async probeData(reference, options) {
|
|
95
|
-
|
|
96
|
-
assertReferenceOrEns(reference);
|
|
95
|
+
reference = new Reference(reference);
|
|
97
96
|
return bytes.head(this.getRequestOptionsForCall(options), reference);
|
|
98
97
|
}
|
|
99
98
|
/**
|
|
100
99
|
* Download data as a byte array
|
|
101
100
|
*
|
|
102
|
-
* @param
|
|
101
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
103
102
|
* @param options Options that affects the request behavior
|
|
104
103
|
* @throws TypeError if some of the input parameters is not expected type
|
|
105
104
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
106
105
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
107
106
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
108
107
|
*/
|
|
109
|
-
async downloadData(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
async downloadData(resource, options, requestOptions) {
|
|
109
|
+
if (options) {
|
|
110
|
+
options = prepareDownloadOptions(options);
|
|
111
|
+
}
|
|
112
|
+
return bytes.download(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* Download data as a Readable stream
|
|
116
116
|
*
|
|
117
|
-
* @param
|
|
117
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
118
118
|
* @param options Options that affects the request behavior
|
|
119
119
|
* @throws TypeError if some of the input parameters is not expected type
|
|
120
120
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
121
121
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
122
122
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
123
123
|
*/
|
|
124
|
-
async downloadReadableData(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
async downloadReadableData(resource, options, requestOptions) {
|
|
125
|
+
if (options) {
|
|
126
|
+
options = prepareDownloadOptions(options);
|
|
127
|
+
}
|
|
128
|
+
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Upload chunk to a Bee node
|
|
@@ -138,18 +139,15 @@ export class Bee {
|
|
|
138
139
|
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
139
140
|
*/
|
|
140
141
|
async uploadChunk(stamp, data, options, requestOptions) {
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
if (data.length < SPAN_SIZE) {
|
|
146
|
-
throw new BeeArgumentError(`Chunk has to have size of at least ${SPAN_SIZE}.`, data);
|
|
142
|
+
data = data instanceof Uint8Array ? data : data.data;
|
|
143
|
+
if (options) {
|
|
144
|
+
options = prepareUploadOptions(options);
|
|
147
145
|
}
|
|
148
|
-
if (data.length
|
|
149
|
-
throw new BeeArgumentError(`Chunk has to have size of at
|
|
146
|
+
if (data.length < Span.LENGTH) {
|
|
147
|
+
throw new BeeArgumentError(`Chunk has to have size of at least ${Span.LENGTH}.`, data);
|
|
150
148
|
}
|
|
151
|
-
if (
|
|
152
|
-
|
|
149
|
+
if (data.length > CHUNK_SIZE + Span.LENGTH) {
|
|
150
|
+
throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE + Span.LENGTH}.`, data);
|
|
153
151
|
}
|
|
154
152
|
return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
|
|
155
153
|
}
|
|
@@ -163,10 +161,12 @@ export class Bee {
|
|
|
163
161
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
164
162
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{address}/get)
|
|
165
163
|
*/
|
|
166
|
-
async downloadChunk(reference, options) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
async downloadChunk(reference, options, requestOptions) {
|
|
165
|
+
reference = new Reference(reference);
|
|
166
|
+
if (options) {
|
|
167
|
+
options = prepareDownloadOptions(options);
|
|
168
|
+
}
|
|
169
|
+
return chunk.download(this.getRequestOptionsForCall(requestOptions), reference, options);
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* Create a grantees list from the given array of public keys.
|
|
@@ -179,8 +179,8 @@ export class Bee {
|
|
|
179
179
|
* @returns A promise that resolves to a `GranteesResult` object.
|
|
180
180
|
*/
|
|
181
181
|
async createGrantees(postageBatchId, grantees, requestOptions) {
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
183
|
+
grantees = grantees.map(x => new PublicKey(x));
|
|
184
184
|
return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
@@ -191,7 +191,7 @@ export class Bee {
|
|
|
191
191
|
* @returns A promise that resolves to a `GetGranteesResult` object.
|
|
192
192
|
*/
|
|
193
193
|
async getGrantees(reference, requestOptions) {
|
|
194
|
-
|
|
194
|
+
reference = new Reference(reference);
|
|
195
195
|
return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
@@ -205,19 +205,18 @@ export class Bee {
|
|
|
205
205
|
* @returns A Promise that resolves to to a `GranteesResult` object.
|
|
206
206
|
*/
|
|
207
207
|
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
209
|
+
reference = new Reference(reference);
|
|
210
|
+
history = new Reference(history);
|
|
211
|
+
const publicKeys = {
|
|
212
|
+
add: grantees.add?.map(x => new PublicKey(x)) ?? [],
|
|
213
|
+
revoke: grantees.revoke?.map(x => new PublicKey(x)) ?? []
|
|
214
|
+
};
|
|
215
|
+
return grantee.patchGrantees(postageBatchId, reference, history, publicKeys, this.getRequestOptionsForCall(requestOptions));
|
|
214
216
|
}
|
|
215
217
|
/**
|
|
216
218
|
* Upload single file to a Bee node.
|
|
217
219
|
*
|
|
218
|
-
* **To make sure that you won't lose critical data it is highly recommended to also
|
|
219
|
-
* locally pin the data with `options.pin = true`**
|
|
220
|
-
*
|
|
221
220
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
222
221
|
* @param data Data or file to be uploaded
|
|
223
222
|
* @param name Optional name of the uploaded file
|
|
@@ -229,11 +228,10 @@ export class Bee {
|
|
|
229
228
|
* @returns reference is a content hash of the file
|
|
230
229
|
*/
|
|
231
230
|
async uploadFile(postageBatchId, data, name, options, requestOptions) {
|
|
232
|
-
|
|
233
|
-
assertBatchId(postageBatchId);
|
|
231
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
234
232
|
assertFileData(data);
|
|
235
233
|
if (options) {
|
|
236
|
-
|
|
234
|
+
options = prepareFileUploadOptions(options);
|
|
237
235
|
}
|
|
238
236
|
if (name && typeof name !== 'string') {
|
|
239
237
|
throw new TypeError('name has to be string or undefined!');
|
|
@@ -246,20 +244,15 @@ export class Bee {
|
|
|
246
244
|
contentType,
|
|
247
245
|
...options
|
|
248
246
|
};
|
|
249
|
-
return
|
|
250
|
-
} else if (isReadable(data) && options?.tag && !options.size) {
|
|
251
|
-
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
252
|
-
const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
253
|
-
await this.updateTag(options.tag, result.reference);
|
|
254
|
-
return addCidConversionFunction(result, 'manifest');
|
|
247
|
+
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
255
248
|
} else {
|
|
256
|
-
return
|
|
249
|
+
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
257
250
|
}
|
|
258
251
|
}
|
|
259
252
|
/**
|
|
260
253
|
* Download single file.
|
|
261
254
|
*
|
|
262
|
-
* @param
|
|
255
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
263
256
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
264
257
|
* @param options Options that affects the request behavior
|
|
265
258
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -268,10 +261,11 @@ export class Bee {
|
|
|
268
261
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
269
262
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
270
263
|
*/
|
|
271
|
-
async downloadFile(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
264
|
+
async downloadFile(resource, path = '', options, requestOptions) {
|
|
265
|
+
if (options) {
|
|
266
|
+
options = prepareDownloadOptions(options);
|
|
267
|
+
}
|
|
268
|
+
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), path, options);
|
|
275
269
|
}
|
|
276
270
|
/**
|
|
277
271
|
* Download single file as a readable stream
|
|
@@ -285,10 +279,12 @@ export class Bee {
|
|
|
285
279
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
286
280
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
287
281
|
*/
|
|
288
|
-
async downloadReadableFile(reference, path = '', options) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
282
|
+
async downloadReadableFile(reference, path = '', options, requestOptions) {
|
|
283
|
+
reference = new Reference(reference);
|
|
284
|
+
if (options) {
|
|
285
|
+
options = prepareDownloadOptions(options);
|
|
286
|
+
}
|
|
287
|
+
return bzz.downloadFileReadable(this.getRequestOptionsForCall(requestOptions), reference, path, options);
|
|
292
288
|
}
|
|
293
289
|
/**
|
|
294
290
|
* Upload collection of files to a Bee node
|
|
@@ -307,13 +303,23 @@ export class Bee {
|
|
|
307
303
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
308
304
|
*/
|
|
309
305
|
async uploadFiles(postageBatchId, fileList, options, requestOptions) {
|
|
310
|
-
|
|
311
|
-
assertBatchId(postageBatchId);
|
|
306
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
312
307
|
if (options) {
|
|
313
|
-
|
|
308
|
+
options = prepareCollectionUploadOptions(options);
|
|
314
309
|
}
|
|
315
|
-
const data =
|
|
316
|
-
return
|
|
310
|
+
const data = makeCollectionFromFileList(fileList);
|
|
311
|
+
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
312
|
+
}
|
|
313
|
+
async hashDirectory(dir) {
|
|
314
|
+
return hashDirectory(dir);
|
|
315
|
+
}
|
|
316
|
+
async streamDirectory(postageBatchId, dir, onUploadProgress, options, requestOptions) {
|
|
317
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
318
|
+
return streamDirectory(this, dir, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
319
|
+
}
|
|
320
|
+
async streamFiles(postageBatchId, files, onUploadProgress, options, requestOptions) {
|
|
321
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
322
|
+
return streamFiles(this, files, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
317
323
|
}
|
|
318
324
|
/**
|
|
319
325
|
* Upload Collection that you can assembly yourself.
|
|
@@ -326,11 +332,12 @@ export class Bee {
|
|
|
326
332
|
* @param options Collections and request options
|
|
327
333
|
*/
|
|
328
334
|
async uploadCollection(postageBatchId, collection, options, requestOptions) {
|
|
329
|
-
|
|
330
|
-
assertBatchId(postageBatchId);
|
|
335
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
331
336
|
assertCollection(collection);
|
|
332
|
-
if (options)
|
|
333
|
-
|
|
337
|
+
if (options) {
|
|
338
|
+
options = prepareCollectionUploadOptions(options);
|
|
339
|
+
}
|
|
340
|
+
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), collection, postageBatchId, options);
|
|
334
341
|
}
|
|
335
342
|
/**
|
|
336
343
|
* Upload collection of files.
|
|
@@ -349,11 +356,12 @@ export class Bee {
|
|
|
349
356
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
350
357
|
*/
|
|
351
358
|
async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
359
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
360
|
+
if (options) {
|
|
361
|
+
options = prepareCollectionUploadOptions(options);
|
|
362
|
+
}
|
|
355
363
|
const data = await makeCollectionFromFS(dir);
|
|
356
|
-
return
|
|
364
|
+
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
357
365
|
}
|
|
358
366
|
/**
|
|
359
367
|
* Create a new Tag which is meant for tracking progres of syncing data across network.
|
|
@@ -363,7 +371,6 @@ export class Bee {
|
|
|
363
371
|
* @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
|
|
364
372
|
*/
|
|
365
373
|
async createTag(options) {
|
|
366
|
-
assertRequestOptions(options);
|
|
367
374
|
return tag.createTag(this.getRequestOptionsForCall(options));
|
|
368
375
|
}
|
|
369
376
|
/**
|
|
@@ -379,8 +386,9 @@ export class Bee {
|
|
|
379
386
|
* @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
|
|
380
387
|
*/
|
|
381
388
|
async getAllTags(options, requestOptions) {
|
|
382
|
-
|
|
383
|
-
|
|
389
|
+
if (options) {
|
|
390
|
+
options = prepareAllTagsOptions(options);
|
|
391
|
+
}
|
|
384
392
|
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
|
|
385
393
|
}
|
|
386
394
|
/**
|
|
@@ -395,7 +403,6 @@ export class Bee {
|
|
|
395
403
|
*
|
|
396
404
|
*/
|
|
397
405
|
async retrieveTag(tagUid, options) {
|
|
398
|
-
assertRequestOptions(options);
|
|
399
406
|
tagUid = makeTagUid(tagUid);
|
|
400
407
|
return tag.retrieveTag(this.getRequestOptionsForCall(options), tagUid);
|
|
401
408
|
}
|
|
@@ -411,7 +418,6 @@ export class Bee {
|
|
|
411
418
|
* @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
|
|
412
419
|
*/
|
|
413
420
|
async deleteTag(tagUid, options) {
|
|
414
|
-
assertRequestOptions(options);
|
|
415
421
|
tagUid = makeTagUid(tagUid);
|
|
416
422
|
return tag.deleteTag(this.getRequestOptionsForCall(options), tagUid);
|
|
417
423
|
}
|
|
@@ -431,8 +437,7 @@ export class Bee {
|
|
|
431
437
|
* @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
|
|
432
438
|
*/
|
|
433
439
|
async updateTag(tagUid, reference, options) {
|
|
434
|
-
|
|
435
|
-
assertRequestOptions(options);
|
|
440
|
+
reference = new Reference(reference);
|
|
436
441
|
tagUid = makeTagUid(tagUid);
|
|
437
442
|
return tag.updateTag(this.getRequestOptionsForCall(options), tagUid, reference);
|
|
438
443
|
}
|
|
@@ -446,8 +451,7 @@ export class Bee {
|
|
|
446
451
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
447
452
|
*/
|
|
448
453
|
async pin(reference, options) {
|
|
449
|
-
|
|
450
|
-
assertReference(reference);
|
|
454
|
+
reference = new Reference(reference);
|
|
451
455
|
return pinning.pin(this.getRequestOptionsForCall(options), reference);
|
|
452
456
|
}
|
|
453
457
|
/**
|
|
@@ -460,8 +464,7 @@ export class Bee {
|
|
|
460
464
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
461
465
|
*/
|
|
462
466
|
async unpin(reference, options) {
|
|
463
|
-
|
|
464
|
-
assertReference(reference);
|
|
467
|
+
reference = new Reference(reference);
|
|
465
468
|
return pinning.unpin(this.getRequestOptionsForCall(options), reference);
|
|
466
469
|
}
|
|
467
470
|
/**
|
|
@@ -471,7 +474,6 @@ export class Bee {
|
|
|
471
474
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
472
475
|
*/
|
|
473
476
|
async getAllPins(options) {
|
|
474
|
-
assertRequestOptions(options);
|
|
475
477
|
return pinning.getAllPins(this.getRequestOptionsForCall(options));
|
|
476
478
|
}
|
|
477
479
|
/**
|
|
@@ -485,8 +487,7 @@ export class Bee {
|
|
|
485
487
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
486
488
|
*/
|
|
487
489
|
async getPin(reference, options) {
|
|
488
|
-
|
|
489
|
-
assertReference(reference);
|
|
490
|
+
reference = new Reference(reference);
|
|
490
491
|
return pinning.getPin(this.getRequestOptionsForCall(options), reference);
|
|
491
492
|
}
|
|
492
493
|
/**
|
|
@@ -500,10 +501,10 @@ export class Bee {
|
|
|
500
501
|
*
|
|
501
502
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
502
503
|
*/
|
|
503
|
-
async reuploadPinnedData(reference, options) {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
await stewardship.reupload(this.getRequestOptionsForCall(options), reference);
|
|
504
|
+
async reuploadPinnedData(postageBatchId, reference, options) {
|
|
505
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
506
|
+
reference = new Reference(reference);
|
|
507
|
+
await stewardship.reupload(this.getRequestOptionsForCall(options), postageBatchId, reference);
|
|
507
508
|
}
|
|
508
509
|
/**
|
|
509
510
|
* Checks if content specified by reference is retrievable from the network.
|
|
@@ -516,8 +517,7 @@ export class Bee {
|
|
|
516
517
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
517
518
|
*/
|
|
518
519
|
async isReferenceRetrievable(reference, options) {
|
|
519
|
-
|
|
520
|
-
assertReferenceOrEns(reference);
|
|
520
|
+
reference = new Reference(reference);
|
|
521
521
|
return stewardship.isRetrievable(this.getRequestOptionsForCall(options), reference);
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
@@ -535,24 +535,25 @@ export class Bee {
|
|
|
535
535
|
* @param index
|
|
536
536
|
* @param options
|
|
537
537
|
*/
|
|
538
|
-
async isFeedRetrievable(
|
|
539
|
-
|
|
540
|
-
|
|
538
|
+
async isFeedRetrievable(owner, topic, index, options, requestOptions) {
|
|
539
|
+
owner = new EthAddress(owner);
|
|
540
|
+
topic = new Topic(topic);
|
|
541
|
+
if (options) {
|
|
542
|
+
options = prepareDownloadOptions(options);
|
|
543
|
+
}
|
|
541
544
|
if (!index) {
|
|
542
545
|
try {
|
|
543
|
-
await this.makeFeedReader(
|
|
546
|
+
await this.makeFeedReader(topic, owner, requestOptions).download();
|
|
544
547
|
return true;
|
|
545
548
|
} catch (e) {
|
|
546
|
-
|
|
549
|
+
const status = Objects.getDeep(e, 'status');
|
|
550
|
+
if (status === 404 || status === 500) {
|
|
547
551
|
return false;
|
|
548
552
|
}
|
|
549
553
|
throw e;
|
|
550
554
|
}
|
|
551
555
|
}
|
|
552
|
-
|
|
553
|
-
throw new BeeError('Only Sequence type of Feeds is supported at the moment');
|
|
554
|
-
}
|
|
555
|
-
return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, this.getRequestOptionsForCall(options));
|
|
556
|
+
return areAllSequentialFeedsUpdateRetrievable(this, owner, topic, index, options, this.getRequestOptionsForCall(requestOptions));
|
|
556
557
|
}
|
|
557
558
|
/**
|
|
558
559
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
@@ -577,15 +578,10 @@ export class Bee {
|
|
|
577
578
|
* @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
|
|
578
579
|
*/
|
|
579
580
|
async pssSend(postageBatchId, topic, target, data, recipient, options) {
|
|
580
|
-
|
|
581
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
581
582
|
assertData(data);
|
|
582
|
-
assertBatchId(postageBatchId);
|
|
583
|
-
assertAddressPrefix(target);
|
|
584
|
-
if (typeof topic !== 'string') {
|
|
585
|
-
throw new TypeError('topic has to be an string!');
|
|
586
|
-
}
|
|
587
583
|
if (recipient) {
|
|
588
|
-
|
|
584
|
+
recipient = new PublicKey(recipient);
|
|
589
585
|
return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId, recipient);
|
|
590
586
|
} else {
|
|
591
587
|
return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId);
|
|
@@ -606,11 +602,8 @@ export class Bee {
|
|
|
606
602
|
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
607
603
|
*/
|
|
608
604
|
pssSubscribe(topic, handler) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
throw new TypeError('topic has to be an string!');
|
|
612
|
-
}
|
|
613
|
-
const ws = pss.subscribe(this.url, topic);
|
|
605
|
+
handler = preparePssMessageHandler(handler);
|
|
606
|
+
const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
|
|
614
607
|
let cancelled = false;
|
|
615
608
|
const cancel = () => {
|
|
616
609
|
if (cancelled === false) {
|
|
@@ -618,24 +611,27 @@ export class Bee {
|
|
|
618
611
|
// although the WebSocket API offers a `close` function, it seems that
|
|
619
612
|
// with the library that we are using (isomorphic-ws) it doesn't close
|
|
620
613
|
// the websocket properly, whereas `terminate` does
|
|
621
|
-
if (ws.terminate)
|
|
614
|
+
if (ws.terminate) {
|
|
615
|
+
ws.terminate();
|
|
616
|
+
} else {
|
|
617
|
+
ws.close();
|
|
618
|
+
} // standard Websocket in browser does not have terminate function
|
|
622
619
|
}
|
|
623
620
|
};
|
|
624
621
|
const subscription = {
|
|
625
622
|
topic,
|
|
626
623
|
cancel
|
|
627
624
|
};
|
|
628
|
-
ws.onmessage = async
|
|
629
|
-
const data = await prepareWebsocketData(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
handler.onMessage(wrapBytesWithHelpers(data), subscription);
|
|
625
|
+
ws.onmessage = async event => {
|
|
626
|
+
const data = await prepareWebsocketData(event.data);
|
|
627
|
+
if (data.length) {
|
|
628
|
+
handler.onMessage(new Bytes(data), subscription);
|
|
633
629
|
}
|
|
634
630
|
};
|
|
635
|
-
ws.onerror =
|
|
631
|
+
ws.onerror = event => {
|
|
636
632
|
// ignore errors after subscription was cancelled
|
|
637
633
|
if (!cancelled) {
|
|
638
|
-
handler.onError(new BeeError(
|
|
634
|
+
handler.onError(new BeeError(event.message), subscription);
|
|
639
635
|
}
|
|
640
636
|
};
|
|
641
637
|
return subscription;
|
|
@@ -665,9 +661,6 @@ export class Bee {
|
|
|
665
661
|
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
666
662
|
*/
|
|
667
663
|
async pssReceive(topic, timeoutMsec = 0) {
|
|
668
|
-
if (typeof topic !== 'string') {
|
|
669
|
-
throw new TypeError('topic has to be an string!');
|
|
670
|
-
}
|
|
671
664
|
if (typeof timeoutMsec !== 'number') {
|
|
672
665
|
throw new TypeError('timeoutMsc parameter has to be a number!');
|
|
673
666
|
}
|
|
@@ -686,8 +679,6 @@ export class Bee {
|
|
|
686
679
|
}
|
|
687
680
|
});
|
|
688
681
|
if (timeoutMsec > 0) {
|
|
689
|
-
// we need to cast the type because Typescript is getting confused with Node.js'
|
|
690
|
-
// alternative type definitions
|
|
691
682
|
timeout = setTimeout(() => {
|
|
692
683
|
subscription.cancel();
|
|
693
684
|
reject(new BeeError('pssReceive timeout'));
|
|
@@ -695,13 +686,68 @@ export class Bee {
|
|
|
695
686
|
}
|
|
696
687
|
});
|
|
697
688
|
}
|
|
689
|
+
gsocMine(targetOverlay, identifier, proximity = 12) {
|
|
690
|
+
targetOverlay = new PeerAddress(targetOverlay);
|
|
691
|
+
identifier = new Identifier(identifier);
|
|
692
|
+
const start = 0xb33n;
|
|
693
|
+
for (let i = 0n; i < 0xffffn; i++) {
|
|
694
|
+
const signer = new PrivateKey(Binary.numberToUint256(start + i, 'BE'));
|
|
695
|
+
const socAddress = makeSOCAddress(identifier, signer.publicKey().address());
|
|
696
|
+
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256);
|
|
697
|
+
if (actualProximity <= 256 - proximity) {
|
|
698
|
+
return signer;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
throw Error('Could not mine a valid signer');
|
|
702
|
+
}
|
|
703
|
+
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
704
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
705
|
+
signer = new PrivateKey(signer);
|
|
706
|
+
identifier = new Identifier(identifier);
|
|
707
|
+
const cac = makeContentAddressedChunk(data);
|
|
708
|
+
const soc = makeSingleOwnerChunk(cac, identifier, signer);
|
|
709
|
+
return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
|
|
710
|
+
}
|
|
711
|
+
gsocSubscribe(address, identifier, handler) {
|
|
712
|
+
address = new EthAddress(address);
|
|
713
|
+
identifier = new Identifier(identifier);
|
|
714
|
+
handler = prepareGsocMessageHandler(handler);
|
|
715
|
+
const socAddress = makeSOCAddress(identifier, address);
|
|
716
|
+
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
717
|
+
let cancelled = false;
|
|
718
|
+
const cancel = () => {
|
|
719
|
+
if (cancelled === false) {
|
|
720
|
+
cancelled = true;
|
|
721
|
+
if (ws.terminate) {
|
|
722
|
+
ws.terminate();
|
|
723
|
+
} else {
|
|
724
|
+
ws.close();
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
const subscription = {
|
|
729
|
+
address,
|
|
730
|
+
cancel
|
|
731
|
+
};
|
|
732
|
+
ws.onmessage = async event => {
|
|
733
|
+
const data = await prepareWebsocketData(event.data);
|
|
734
|
+
if (data.length) {
|
|
735
|
+
handler.onMessage(new Bytes(data), subscription);
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
ws.onerror = event => {
|
|
739
|
+
if (!cancelled) {
|
|
740
|
+
handler.onError(new BeeError(event.message), subscription);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
return subscription;
|
|
744
|
+
}
|
|
698
745
|
/**
|
|
699
746
|
* Create feed manifest chunk and return the reference to it.
|
|
700
747
|
*
|
|
701
748
|
* Feed manifest chunk allows for a feed to be able to be resolved through `/bzz` endpoint.
|
|
702
749
|
*
|
|
703
750
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
704
|
-
* @param type The type of the feed, can be 'epoch' or 'sequence'
|
|
705
751
|
* @param topic Topic in hex or bytes
|
|
706
752
|
* @param owner Owner's ethereum address in hex or bytes
|
|
707
753
|
* @param options Options that affects the request behavior
|
|
@@ -709,129 +755,50 @@ export class Bee {
|
|
|
709
755
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
710
756
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
711
757
|
*/
|
|
712
|
-
async createFeedManifest(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}, 'feed');
|
|
758
|
+
async createFeedManifest(postageBatchId, topic, owner, options, requestOptions) {
|
|
759
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
760
|
+
topic = new Topic(topic);
|
|
761
|
+
owner = new EthAddress(owner);
|
|
762
|
+
if (options) {
|
|
763
|
+
options = prepareUploadOptions(options);
|
|
764
|
+
}
|
|
765
|
+
return createFeedManifest(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
|
|
721
766
|
}
|
|
722
767
|
/**
|
|
723
768
|
* Make a new feed reader for downloading feed updates.
|
|
724
769
|
*
|
|
725
|
-
* @param type The type of the feed, can be 'epoch' or 'sequence'
|
|
726
770
|
* @param topic Topic in hex or bytes
|
|
727
771
|
* @param owner Owner's ethereum address in hex or bytes
|
|
728
772
|
* @param options Options that affects the request behavior
|
|
729
773
|
*
|
|
730
774
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
731
775
|
*/
|
|
732
|
-
makeFeedReader(
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const canonicalOwner = makeHexEthAddress(owner);
|
|
737
|
-
return makeFeedReader(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalOwner);
|
|
776
|
+
makeFeedReader(topic, owner, options) {
|
|
777
|
+
topic = new Topic(topic);
|
|
778
|
+
owner = new EthAddress(owner);
|
|
779
|
+
return makeFeedReader(this.getRequestOptionsForCall(options), topic, owner);
|
|
738
780
|
}
|
|
739
781
|
/**
|
|
740
782
|
* Make a new feed writer for updating feeds
|
|
741
783
|
*
|
|
742
|
-
* @param type The type of the feed, can be 'epoch' or 'sequence'
|
|
743
784
|
* @param topic Topic in hex or bytes
|
|
744
785
|
* @param signer The signer's private key or a Signer instance that can sign data
|
|
745
786
|
* @param options Options that affects the request behavior
|
|
746
787
|
*
|
|
747
788
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
748
789
|
*/
|
|
749
|
-
makeFeedWriter(
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
return makeFeedWriter(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalSigner);
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* High-level function that allows you to easily set JSON data to feed.
|
|
758
|
-
* JSON-like data types are supported.
|
|
759
|
-
*
|
|
760
|
-
* The default Signer of Bee instance is used if `options.signer` is not specified.
|
|
761
|
-
* If none of those two is set error is thrown.
|
|
762
|
-
*
|
|
763
|
-
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
764
|
-
* @param topic Human readable string, that is internally hashed so there are no constrains there.
|
|
765
|
-
* @param data JSON compatible data
|
|
766
|
-
* @param options
|
|
767
|
-
* @param options.signer Custom instance of Signer or string with private key.
|
|
768
|
-
* @param options.type Type of Feed
|
|
769
|
-
*
|
|
770
|
-
* @throws BeeError if `options.signer` is not specified nor the default Signer on Bee's instance is specified.
|
|
771
|
-
*
|
|
772
|
-
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
773
|
-
*/
|
|
774
|
-
async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
|
|
775
|
-
assertRequestOptions(requestOptions, 'JsonFeedOptions');
|
|
776
|
-
assertBatchId(postageBatchId);
|
|
777
|
-
const hashedTopic = this.makeFeedTopic(topic);
|
|
778
|
-
const feedType = options?.type ?? DEFAULT_FEED_TYPE;
|
|
779
|
-
const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, requestOptions);
|
|
780
|
-
return setJsonData(this, writer, postageBatchId, data, options, requestOptions);
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* High-level function that allows you to easily get data from feed.
|
|
784
|
-
* Returned data are parsed using JSON.parse().
|
|
785
|
-
*
|
|
786
|
-
* This method also supports specification of `signer` object passed to constructor. The order of evaluation is:
|
|
787
|
-
* - `options.address`
|
|
788
|
-
* - `options.signer`
|
|
789
|
-
* - `this.signer`
|
|
790
|
-
*
|
|
791
|
-
* At least one of these has to be specified!
|
|
792
|
-
*
|
|
793
|
-
* @param topic Human readable string, that is internally hashed so there are no constrains there.
|
|
794
|
-
* @param options
|
|
795
|
-
* @param options.signer Custom instance of Signer or string with private key. This option is exclusive with `address` option.
|
|
796
|
-
* @param options.address Ethereum address of owner of the feed that signed it. This option is exclusive with `signer` option.
|
|
797
|
-
* @param options.type Type of Feed
|
|
798
|
-
*
|
|
799
|
-
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
800
|
-
*/
|
|
801
|
-
async getJsonFeed(topic, options, requestOptions) {
|
|
802
|
-
assertRequestOptions(requestOptions);
|
|
803
|
-
const hashedTopic = this.makeFeedTopic(topic);
|
|
804
|
-
const feedType = options?.type ?? DEFAULT_FEED_TYPE;
|
|
805
|
-
if (options?.signer && options?.address) {
|
|
806
|
-
throw new BeeError('Both options "signer" and "address" can not be specified at one time!');
|
|
807
|
-
}
|
|
808
|
-
let address;
|
|
809
|
-
if (options?.address) {
|
|
810
|
-
address = makeEthAddress(options?.address);
|
|
811
|
-
} else {
|
|
812
|
-
try {
|
|
813
|
-
address = this.resolveSigner(options?.signer).address;
|
|
814
|
-
} catch (e) {
|
|
815
|
-
if (e instanceof BeeError) {
|
|
816
|
-
throw new BeeError('Either address, signer or default signer has to be specified!');
|
|
817
|
-
} else {
|
|
818
|
-
throw e;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
790
|
+
makeFeedWriter(topic, signer, options) {
|
|
791
|
+
topic = new Topic(topic);
|
|
792
|
+
signer = signer ? new PrivateKey(signer) : this.signer;
|
|
793
|
+
if (!signer) {
|
|
794
|
+
throw Error('No signer provided');
|
|
821
795
|
}
|
|
822
|
-
|
|
823
|
-
return getJsonData(this, reader);
|
|
796
|
+
return makeFeedWriter(this.getRequestOptionsForCall(options), topic, signer);
|
|
824
797
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
* hashes the input string to create a topic string of arbitrary length.
|
|
830
|
-
*
|
|
831
|
-
* @param topic The input string
|
|
832
|
-
*/
|
|
833
|
-
makeFeedTopic(topic) {
|
|
834
|
-
return makeTopicFromString(topic);
|
|
798
|
+
async fetchLatestFeedUpdate(topic, owner, requestOptions) {
|
|
799
|
+
topic = new Topic(topic);
|
|
800
|
+
owner = new EthAddress(owner);
|
|
801
|
+
return fetchLatestFeedUpdate(this.getRequestOptionsForCall(requestOptions), owner, topic);
|
|
835
802
|
}
|
|
836
803
|
/**
|
|
837
804
|
* Returns an object for reading single owner chunks
|
|
@@ -841,11 +808,10 @@ export class Bee {
|
|
|
841
808
|
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
842
809
|
*/
|
|
843
810
|
makeSOCReader(ownerAddress, options) {
|
|
844
|
-
|
|
845
|
-
const canonicalOwner = makeEthAddress(ownerAddress);
|
|
811
|
+
ownerAddress = new EthAddress(ownerAddress);
|
|
846
812
|
return {
|
|
847
|
-
owner:
|
|
848
|
-
download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options),
|
|
813
|
+
owner: ownerAddress,
|
|
814
|
+
download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options), ownerAddress)
|
|
849
815
|
};
|
|
850
816
|
}
|
|
851
817
|
/**
|
|
@@ -856,15 +822,18 @@ export class Bee {
|
|
|
856
822
|
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
857
823
|
*/
|
|
858
824
|
makeSOCWriter(signer, options) {
|
|
859
|
-
|
|
860
|
-
|
|
825
|
+
signer = signer ? new PrivateKey(signer) : this.signer;
|
|
826
|
+
if (!signer) {
|
|
827
|
+
throw Error('No signer provided');
|
|
828
|
+
}
|
|
861
829
|
return {
|
|
862
|
-
...this.makeSOCReader(
|
|
863
|
-
upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options),
|
|
830
|
+
...this.makeSOCReader(signer.publicKey().address(), options),
|
|
831
|
+
upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), signer)
|
|
864
832
|
};
|
|
865
833
|
}
|
|
866
834
|
async createEnvelope(postageBatchId, reference, options) {
|
|
867
|
-
|
|
835
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
836
|
+
reference = new Reference(reference);
|
|
868
837
|
return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
|
|
869
838
|
}
|
|
870
839
|
/**
|
|
@@ -874,7 +843,6 @@ export class Bee {
|
|
|
874
843
|
* @throws If connection was not successful throw error
|
|
875
844
|
*/
|
|
876
845
|
async checkConnection(options) {
|
|
877
|
-
assertRequestOptions(options, 'PostageBatchOptions');
|
|
878
846
|
return status.checkConnection(this.getRequestOptionsForCall(options));
|
|
879
847
|
}
|
|
880
848
|
/**
|
|
@@ -884,7 +852,6 @@ export class Bee {
|
|
|
884
852
|
* @returns true if successful, false on error
|
|
885
853
|
*/
|
|
886
854
|
async isConnected(options) {
|
|
887
|
-
assertRequestOptions(options, 'PostageBatchOptions');
|
|
888
855
|
try {
|
|
889
856
|
await status.checkConnection(this.getRequestOptionsForCall(options));
|
|
890
857
|
} catch (e) {
|
|
@@ -894,53 +861,26 @@ export class Bee {
|
|
|
894
861
|
}
|
|
895
862
|
// Legacy debug API
|
|
896
863
|
async getNodeAddresses(options) {
|
|
897
|
-
assertRequestOptions(options);
|
|
898
864
|
return connectivity.getNodeAddresses(this.getRequestOptionsForCall(options));
|
|
899
865
|
}
|
|
900
866
|
async getBlocklist(options) {
|
|
901
|
-
assertRequestOptions(options);
|
|
902
867
|
return connectivity.getBlocklist(this.getRequestOptionsForCall(options));
|
|
903
868
|
}
|
|
904
|
-
/**
|
|
905
|
-
* Retrieve tag extended information from Bee node
|
|
906
|
-
*
|
|
907
|
-
* @param tagUid UID or tag object to be retrieved
|
|
908
|
-
* @throws TypeError if tagUid is in not correct format
|
|
909
|
-
*
|
|
910
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
911
|
-
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
|
|
912
|
-
*
|
|
913
|
-
*/
|
|
914
|
-
async retrieveExtendedTag(tagUid, options) {
|
|
915
|
-
assertRequestOptions(options);
|
|
916
|
-
if (isTag(tagUid)) {
|
|
917
|
-
tagUid = tagUid.uid;
|
|
918
|
-
} else if (typeof tagUid === 'number') {
|
|
919
|
-
assertNonNegativeInteger(tagUid, 'UID');
|
|
920
|
-
} else {
|
|
921
|
-
throw new TypeError('tagUid has to be either Tag or a number (UID)!');
|
|
922
|
-
}
|
|
923
|
-
return debugTag.retrieveExtendedTag(this.getRequestOptionsForCall(options), tagUid);
|
|
924
|
-
}
|
|
925
869
|
/**
|
|
926
870
|
* Get list of peers for this node
|
|
927
871
|
*/
|
|
928
872
|
async getPeers(options) {
|
|
929
|
-
assertRequestOptions(options);
|
|
930
873
|
return connectivity.getPeers(this.getRequestOptionsForCall(options));
|
|
931
874
|
}
|
|
932
875
|
async removePeer(peer, options) {
|
|
933
|
-
|
|
934
|
-
assertAddress(peer);
|
|
876
|
+
peer = new PeerAddress(peer);
|
|
935
877
|
return connectivity.removePeer(this.getRequestOptionsForCall(options), peer);
|
|
936
878
|
}
|
|
937
879
|
async getTopology(options) {
|
|
938
|
-
assertRequestOptions(options);
|
|
939
880
|
return connectivity.getTopology(this.getRequestOptionsForCall(options));
|
|
940
881
|
}
|
|
941
882
|
async pingPeer(peer, options) {
|
|
942
|
-
|
|
943
|
-
assertAddress(peer);
|
|
883
|
+
peer = new PeerAddress(peer);
|
|
944
884
|
return connectivity.pingPeer(this.getRequestOptionsForCall(options), peer);
|
|
945
885
|
}
|
|
946
886
|
/*
|
|
@@ -950,7 +890,6 @@ export class Bee {
|
|
|
950
890
|
* Get the balances with all known peers including prepaid services
|
|
951
891
|
*/
|
|
952
892
|
async getAllBalances(options) {
|
|
953
|
-
assertRequestOptions(options);
|
|
954
893
|
return balance.getAllBalances(this.getRequestOptionsForCall(options));
|
|
955
894
|
}
|
|
956
895
|
/**
|
|
@@ -959,15 +898,13 @@ export class Bee {
|
|
|
959
898
|
* @param address Swarm address of peer
|
|
960
899
|
*/
|
|
961
900
|
async getPeerBalance(address, options) {
|
|
962
|
-
|
|
963
|
-
assertAddress(address);
|
|
901
|
+
address = new PeerAddress(address);
|
|
964
902
|
return balance.getPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
965
903
|
}
|
|
966
904
|
/**
|
|
967
905
|
* Get the past due consumption balances with all known peers
|
|
968
906
|
*/
|
|
969
907
|
async getPastDueConsumptionBalances(options) {
|
|
970
|
-
assertRequestOptions(options);
|
|
971
908
|
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(options));
|
|
972
909
|
}
|
|
973
910
|
/**
|
|
@@ -976,8 +913,7 @@ export class Bee {
|
|
|
976
913
|
* @param address Swarm address of peer
|
|
977
914
|
*/
|
|
978
915
|
async getPastDueConsumptionPeerBalance(address, options) {
|
|
979
|
-
|
|
980
|
-
assertAddress(address);
|
|
916
|
+
address = new PeerAddress(address);
|
|
981
917
|
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(options), address);
|
|
982
918
|
}
|
|
983
919
|
/*
|
|
@@ -990,21 +926,18 @@ export class Bee {
|
|
|
990
926
|
* https://github.com/ethersphere/bee/issues/1443
|
|
991
927
|
*/
|
|
992
928
|
async getChequebookAddress(options) {
|
|
993
|
-
assertRequestOptions(options);
|
|
994
929
|
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(options));
|
|
995
930
|
}
|
|
996
931
|
/**
|
|
997
932
|
* Get the balance of the chequebook
|
|
998
933
|
*/
|
|
999
934
|
async getChequebookBalance(options) {
|
|
1000
|
-
assertRequestOptions(options);
|
|
1001
935
|
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(options));
|
|
1002
936
|
}
|
|
1003
937
|
/**
|
|
1004
938
|
* Get last cheques for all peers
|
|
1005
939
|
*/
|
|
1006
940
|
async getLastCheques(options) {
|
|
1007
|
-
assertRequestOptions(options);
|
|
1008
941
|
return chequebook.getLastCheques(this.getRequestOptionsForCall(options));
|
|
1009
942
|
}
|
|
1010
943
|
/**
|
|
@@ -1013,8 +946,7 @@ export class Bee {
|
|
|
1013
946
|
* @param address Swarm address of peer
|
|
1014
947
|
*/
|
|
1015
948
|
async getLastChequesForPeer(address, options) {
|
|
1016
|
-
|
|
1017
|
-
assertAddress(address);
|
|
949
|
+
address = new PeerAddress(address);
|
|
1018
950
|
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(options), address);
|
|
1019
951
|
}
|
|
1020
952
|
/**
|
|
@@ -1023,8 +955,7 @@ export class Bee {
|
|
|
1023
955
|
* @param address Swarm address of peer
|
|
1024
956
|
*/
|
|
1025
957
|
async getLastCashoutAction(address, options) {
|
|
1026
|
-
|
|
1027
|
-
assertAddress(address);
|
|
958
|
+
address = new PeerAddress(address);
|
|
1028
959
|
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(options), address);
|
|
1029
960
|
}
|
|
1030
961
|
/**
|
|
@@ -1036,9 +967,10 @@ export class Bee {
|
|
|
1036
967
|
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
1037
968
|
*/
|
|
1038
969
|
async cashoutLastCheque(address, options, requestOptions) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
970
|
+
address = new PeerAddress(address);
|
|
971
|
+
if (options) {
|
|
972
|
+
prepareTransactionOptions(options);
|
|
973
|
+
}
|
|
1042
974
|
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
1043
975
|
}
|
|
1044
976
|
/**
|
|
@@ -1049,12 +981,18 @@ export class Bee {
|
|
|
1049
981
|
* @return string Hash of the transaction
|
|
1050
982
|
*/
|
|
1051
983
|
async depositTokens(amount, gasPrice, options) {
|
|
1052
|
-
|
|
1053
|
-
|
|
984
|
+
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
985
|
+
min: 1n,
|
|
986
|
+
name: 'amount'
|
|
987
|
+
});
|
|
988
|
+
let gasPriceString;
|
|
1054
989
|
if (gasPrice) {
|
|
1055
|
-
|
|
990
|
+
gasPriceString = asNumberString(amount, {
|
|
991
|
+
min: 0n,
|
|
992
|
+
name: 'gasPrice'
|
|
993
|
+
});
|
|
1056
994
|
}
|
|
1057
|
-
return chequebook.depositTokens(this.getRequestOptionsForCall(options),
|
|
995
|
+
return chequebook.depositTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
|
|
1058
996
|
}
|
|
1059
997
|
/**
|
|
1060
998
|
* Withdraw tokens from the chequebook to the overlay address
|
|
@@ -1064,12 +1002,19 @@ export class Bee {
|
|
|
1064
1002
|
* @return string Hash of the transaction
|
|
1065
1003
|
*/
|
|
1066
1004
|
async withdrawTokens(amount, gasPrice, options) {
|
|
1067
|
-
|
|
1068
|
-
|
|
1005
|
+
// TODO: check BZZ in tests
|
|
1006
|
+
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
1007
|
+
min: 1n,
|
|
1008
|
+
name: 'amount'
|
|
1009
|
+
});
|
|
1010
|
+
let gasPriceString;
|
|
1069
1011
|
if (gasPrice) {
|
|
1070
|
-
|
|
1012
|
+
gasPriceString = asNumberString(amount, {
|
|
1013
|
+
min: 0n,
|
|
1014
|
+
name: 'gasPrice'
|
|
1015
|
+
});
|
|
1071
1016
|
}
|
|
1072
|
-
return chequebook.withdrawTokens(this.getRequestOptionsForCall(options),
|
|
1017
|
+
return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
|
|
1073
1018
|
}
|
|
1074
1019
|
/*
|
|
1075
1020
|
* Settlements endpoint
|
|
@@ -1080,81 +1025,47 @@ export class Bee {
|
|
|
1080
1025
|
* @param address Swarm address of peer
|
|
1081
1026
|
*/
|
|
1082
1027
|
async getSettlements(address, options) {
|
|
1083
|
-
|
|
1084
|
-
assertAddress(address);
|
|
1028
|
+
address = new PeerAddress(address);
|
|
1085
1029
|
return settlements.getSettlements(this.getRequestOptionsForCall(options), address);
|
|
1086
1030
|
}
|
|
1087
1031
|
/**
|
|
1088
1032
|
* Get settlements with all known peers and total amount sent or received
|
|
1089
1033
|
*/
|
|
1090
1034
|
async getAllSettlements(options) {
|
|
1091
|
-
assertRequestOptions(options);
|
|
1092
1035
|
return settlements.getAllSettlements(this.getRequestOptionsForCall(options));
|
|
1093
1036
|
}
|
|
1094
1037
|
/**
|
|
1095
1038
|
* Get status of node
|
|
1096
1039
|
*/
|
|
1097
1040
|
async getStatus(options) {
|
|
1098
|
-
assertRequestOptions(options);
|
|
1099
1041
|
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(options));
|
|
1100
1042
|
}
|
|
1101
1043
|
/**
|
|
1102
1044
|
* Get health of node
|
|
1103
1045
|
*/
|
|
1104
1046
|
async getHealth(options) {
|
|
1105
|
-
assertRequestOptions(options);
|
|
1106
1047
|
return debugStatus.getHealth(this.getRequestOptionsForCall(options));
|
|
1107
1048
|
}
|
|
1108
1049
|
/**
|
|
1109
1050
|
* Get readiness of node
|
|
1110
1051
|
*/
|
|
1111
1052
|
async getReadiness(options) {
|
|
1112
|
-
assertRequestOptions(options);
|
|
1113
1053
|
return debugStatus.getReadiness(this.getRequestOptionsForCall(options));
|
|
1114
1054
|
}
|
|
1115
1055
|
/**
|
|
1116
1056
|
* Get mode information of node
|
|
1117
1057
|
*/
|
|
1118
1058
|
async getNodeInfo(options) {
|
|
1119
|
-
assertRequestOptions(options);
|
|
1120
1059
|
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(options));
|
|
1121
1060
|
}
|
|
1122
|
-
/**
|
|
1123
|
-
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
1124
|
-
*
|
|
1125
|
-
* @returns true if the Bee node version is supported
|
|
1126
|
-
* @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
|
|
1127
|
-
*/
|
|
1128
|
-
async isSupportedVersion(options) {
|
|
1129
|
-
assertRequestOptions(options);
|
|
1130
|
-
return debugStatus.isSupportedVersion(this.getRequestOptionsForCall(options));
|
|
1131
|
-
}
|
|
1132
1061
|
/**
|
|
1133
1062
|
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
1134
1063
|
*
|
|
1135
|
-
* Be aware that this is the most strict version check and most probably
|
|
1136
|
-
* you will want to use more relaxed API-versions based checks like
|
|
1137
|
-
* `BeeDebug.isSupportedApiVersion()`, `BeeDebug.isSupportedMainApiVersion()` or `BeeDebug.isSupportedDebugApiVersion()`
|
|
1138
|
-
* based on your use-case.
|
|
1139
|
-
*
|
|
1140
1064
|
* @param options
|
|
1141
1065
|
*/
|
|
1142
1066
|
async isSupportedExactVersion(options) {
|
|
1143
|
-
assertRequestOptions(options);
|
|
1144
1067
|
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(options));
|
|
1145
1068
|
}
|
|
1146
|
-
/**
|
|
1147
|
-
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
1148
|
-
*
|
|
1149
|
-
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
1150
|
-
* and want to make sure about compatibility.
|
|
1151
|
-
*
|
|
1152
|
-
* @param options
|
|
1153
|
-
*/
|
|
1154
|
-
async isSupportedMainApiVersion(options) {
|
|
1155
|
-
assertRequestOptions(options);
|
|
1156
|
-
return debugStatus.isSupportedMainApiVersion(this.getRequestOptionsForCall(options));
|
|
1157
|
-
}
|
|
1158
1069
|
/**
|
|
1159
1070
|
*
|
|
1160
1071
|
* Connects to a node and checks if its Main API version matches with the one that bee-js supports.
|
|
@@ -1164,7 +1075,6 @@ export class Bee {
|
|
|
1164
1075
|
* @param options
|
|
1165
1076
|
*/
|
|
1166
1077
|
async isSupportedApiVersion(options) {
|
|
1167
|
-
assertRequestOptions(options);
|
|
1168
1078
|
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(options));
|
|
1169
1079
|
}
|
|
1170
1080
|
/**
|
|
@@ -1174,21 +1084,18 @@ export class Bee {
|
|
|
1174
1084
|
* @param options
|
|
1175
1085
|
*/
|
|
1176
1086
|
async getVersions(options) {
|
|
1177
|
-
assertRequestOptions(options);
|
|
1178
1087
|
return debugStatus.getVersions(this.getRequestOptionsForCall(options));
|
|
1179
1088
|
}
|
|
1180
1089
|
/**
|
|
1181
1090
|
* Get reserve state
|
|
1182
1091
|
*/
|
|
1183
1092
|
async getReserveState(options) {
|
|
1184
|
-
assertRequestOptions(options);
|
|
1185
1093
|
return states.getReserveState(this.getRequestOptionsForCall(options));
|
|
1186
1094
|
}
|
|
1187
1095
|
/**
|
|
1188
1096
|
* Get chain state
|
|
1189
1097
|
*/
|
|
1190
1098
|
async getChainState(options) {
|
|
1191
|
-
assertRequestOptions(options);
|
|
1192
1099
|
return states.getChainState(this.getRequestOptionsForCall(options));
|
|
1193
1100
|
}
|
|
1194
1101
|
/**
|
|
@@ -1197,7 +1104,6 @@ export class Bee {
|
|
|
1197
1104
|
* @param options
|
|
1198
1105
|
*/
|
|
1199
1106
|
async getWalletBalance(options) {
|
|
1200
|
-
assertRequestOptions(options);
|
|
1201
1107
|
return states.getWalletBalance(this.getRequestOptionsForCall(options));
|
|
1202
1108
|
}
|
|
1203
1109
|
/**
|
|
@@ -1215,48 +1121,107 @@ export class Bee {
|
|
|
1215
1121
|
* @throws TypeError if non-integer value is passed to amount or depth
|
|
1216
1122
|
*
|
|
1217
1123
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1218
|
-
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/
|
|
1124
|
+
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
1219
1125
|
*/
|
|
1220
1126
|
async createPostageBatch(amount, depth, options, requestOptions) {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1127
|
+
const amountString = asNumberString(amount, {
|
|
1128
|
+
min: 0n,
|
|
1129
|
+
name: 'amount'
|
|
1130
|
+
});
|
|
1131
|
+
if (options) {
|
|
1132
|
+
options = preparePostageBatchOptions(options);
|
|
1227
1133
|
}
|
|
1228
|
-
if (depth > STAMPS_DEPTH_MAX) {
|
|
1229
|
-
throw new BeeArgumentError(`Depth has to be
|
|
1134
|
+
if (depth < STAMPS_DEPTH_MIN || depth > STAMPS_DEPTH_MAX) {
|
|
1135
|
+
throw new BeeArgumentError(`Depth has to be between ${STAMPS_DEPTH_MIN}..${STAMPS_DEPTH_MAX}`, depth);
|
|
1230
1136
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1137
|
+
const chainState = await this.getChainState();
|
|
1138
|
+
const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
|
|
1139
|
+
if (BigInt(amountString) < minimumAmount) {
|
|
1140
|
+
throw new BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
|
|
1233
1141
|
}
|
|
1234
|
-
const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions),
|
|
1142
|
+
const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amountString, depth, options);
|
|
1235
1143
|
if (options?.waitForUsable !== false) {
|
|
1236
1144
|
await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
|
|
1237
1145
|
}
|
|
1238
1146
|
return stamp;
|
|
1239
1147
|
}
|
|
1148
|
+
async buyStorage(size, duration, options, requestOptions) {
|
|
1149
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1150
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1151
|
+
const depth = getDepthForSize(size);
|
|
1152
|
+
if (options) {
|
|
1153
|
+
options = preparePostageBatchOptions(options);
|
|
1154
|
+
}
|
|
1155
|
+
return this.createPostageBatch(amount, depth, options, requestOptions);
|
|
1156
|
+
}
|
|
1157
|
+
async getStorageCost(size, duration, options) {
|
|
1158
|
+
const chainState = await this.getChainState(options);
|
|
1159
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1160
|
+
const depth = getDepthForSize(size);
|
|
1161
|
+
return getStampCost(depth, amount);
|
|
1162
|
+
}
|
|
1163
|
+
async extendStorageSize(postageBatchId, size, options) {
|
|
1164
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1165
|
+
const depth = getDepthForSize(size);
|
|
1166
|
+
const delta = depth - batch.depth;
|
|
1167
|
+
if (delta <= 0) {
|
|
1168
|
+
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1169
|
+
}
|
|
1170
|
+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
|
|
1171
|
+
return this.diluteBatch(batch.batchID, depth, options);
|
|
1172
|
+
}
|
|
1173
|
+
async extendStorageDuration(postageBatchId, duration, options) {
|
|
1174
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1175
|
+
const chainState = await this.getChainState(options);
|
|
1176
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1177
|
+
return this.topUpBatch(batch.batchID, amount, options);
|
|
1178
|
+
}
|
|
1179
|
+
async getExtensionCost(postageBatchId, size, duration, options) {
|
|
1180
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1181
|
+
const chainState = await this.getChainState(options);
|
|
1182
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1183
|
+
const depth = getDepthForSize(size);
|
|
1184
|
+
const currentValue = getStampCost(batch.depth, batch.amount);
|
|
1185
|
+
const newValue = getStampCost(depth, amount);
|
|
1186
|
+
return newValue.minus(currentValue);
|
|
1187
|
+
}
|
|
1188
|
+
async getSizeExtensionCost(postageBatchId, size, options) {
|
|
1189
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1190
|
+
const depth = getDepthForSize(size);
|
|
1191
|
+
const delta = depth - batch.depth;
|
|
1192
|
+
if (delta <= 0) {
|
|
1193
|
+
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1194
|
+
}
|
|
1195
|
+
const currentPaid = getStampCost(batch.depth, batch.amount);
|
|
1196
|
+
const newPaid = getStampCost(depth, batch.amount);
|
|
1197
|
+
return newPaid.minus(currentPaid);
|
|
1198
|
+
}
|
|
1199
|
+
async getDurationExtensionCost(postageBatchId, duration, options) {
|
|
1200
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1201
|
+
const chainState = await this.getChainState(options);
|
|
1202
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1203
|
+
return getStampCost(batch.depth, amount);
|
|
1204
|
+
}
|
|
1240
1205
|
/**
|
|
1241
1206
|
* Topup a fresh amount of BZZ to given Postage Batch.
|
|
1242
1207
|
*
|
|
1243
1208
|
* For better understanding what each parameter means and what are the optimal values please see
|
|
1244
1209
|
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1245
1210
|
*
|
|
1246
|
-
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1247
|
-
*
|
|
1248
1211
|
* @param postageBatchId Batch ID
|
|
1249
1212
|
* @param amount Amount to be added to the batch
|
|
1250
1213
|
* @param options Request options
|
|
1251
1214
|
*
|
|
1252
1215
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1253
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
1216
|
+
* @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)
|
|
1254
1217
|
*/
|
|
1255
1218
|
async topUpBatch(postageBatchId, amount, options) {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1219
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1220
|
+
const amountString = asNumberString(amount, {
|
|
1221
|
+
min: 1n,
|
|
1222
|
+
name: 'amount'
|
|
1223
|
+
});
|
|
1224
|
+
return stamps.topUpBatch(this.getRequestOptionsForCall(options), postageBatchId, amountString);
|
|
1260
1225
|
}
|
|
1261
1226
|
/**
|
|
1262
1227
|
* Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
|
|
@@ -1265,20 +1230,21 @@ export class Bee {
|
|
|
1265
1230
|
* For better understanding what each parameter means and what are the optimal values please see
|
|
1266
1231
|
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1267
1232
|
*
|
|
1268
|
-
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
1269
|
-
*
|
|
1270
1233
|
* @param postageBatchId Batch ID
|
|
1271
1234
|
* @param depth Amount to be added to the batch
|
|
1272
1235
|
* @param options Request options
|
|
1273
1236
|
*
|
|
1274
1237
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1275
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
1238
|
+
* @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)
|
|
1276
1239
|
*/
|
|
1277
1240
|
async diluteBatch(postageBatchId, depth, options) {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1241
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1242
|
+
depth = Types.asNumber(depth, {
|
|
1243
|
+
name: 'depth',
|
|
1244
|
+
min: 18,
|
|
1245
|
+
max: 255
|
|
1246
|
+
});
|
|
1247
|
+
return stamps.diluteBatch(this.getRequestOptionsForCall(options), postageBatchId, depth);
|
|
1282
1248
|
}
|
|
1283
1249
|
/**
|
|
1284
1250
|
* Return details for specific postage batch.
|
|
@@ -1286,11 +1252,10 @@ export class Bee {
|
|
|
1286
1252
|
* @param postageBatchId Batch ID
|
|
1287
1253
|
*
|
|
1288
1254
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1289
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/
|
|
1255
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
|
|
1290
1256
|
*/
|
|
1291
1257
|
async getPostageBatch(postageBatchId, options) {
|
|
1292
|
-
|
|
1293
|
-
assertBatchId(postageBatchId);
|
|
1258
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1294
1259
|
return stamps.getPostageBatch(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1295
1260
|
}
|
|
1296
1261
|
/**
|
|
@@ -1299,35 +1264,31 @@ export class Bee {
|
|
|
1299
1264
|
* @param postageBatchId Batch ID
|
|
1300
1265
|
*
|
|
1301
1266
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1302
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/
|
|
1267
|
+
* @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)
|
|
1303
1268
|
*/
|
|
1304
1269
|
async getPostageBatchBuckets(postageBatchId, options) {
|
|
1305
|
-
|
|
1306
|
-
assertBatchId(postageBatchId);
|
|
1270
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1307
1271
|
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(options), postageBatchId);
|
|
1308
1272
|
}
|
|
1309
1273
|
/**
|
|
1310
1274
|
* Return all postage batches that has the node available.
|
|
1311
1275
|
*
|
|
1312
1276
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1313
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/
|
|
1277
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1314
1278
|
*/
|
|
1315
1279
|
async getAllPostageBatch(options) {
|
|
1316
|
-
assertRequestOptions(options);
|
|
1317
1280
|
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1318
1281
|
}
|
|
1319
1282
|
/**
|
|
1320
1283
|
* Return all globally available postage batches.
|
|
1321
1284
|
*/
|
|
1322
1285
|
async getAllGlobalPostageBatch(options) {
|
|
1323
|
-
assertRequestOptions(options);
|
|
1324
1286
|
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1325
1287
|
}
|
|
1326
1288
|
/**
|
|
1327
1289
|
* Return lists of all current pending transactions that the Bee made
|
|
1328
1290
|
*/
|
|
1329
1291
|
async getAllPendingTransactions(options) {
|
|
1330
|
-
assertRequestOptions(options);
|
|
1331
1292
|
return transactions.getAllTransactions(this.getRequestOptionsForCall(options));
|
|
1332
1293
|
}
|
|
1333
1294
|
/**
|
|
@@ -1335,8 +1296,7 @@ export class Bee {
|
|
|
1335
1296
|
* @param transactionHash
|
|
1336
1297
|
*/
|
|
1337
1298
|
async getPendingTransaction(transactionHash, options) {
|
|
1338
|
-
|
|
1339
|
-
assertTransactionHash(transactionHash);
|
|
1299
|
+
transactionHash = new TransactionId(transactionHash);
|
|
1340
1300
|
return transactions.getTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1341
1301
|
}
|
|
1342
1302
|
/**
|
|
@@ -1346,8 +1306,7 @@ export class Bee {
|
|
|
1346
1306
|
* @param transactionHash
|
|
1347
1307
|
*/
|
|
1348
1308
|
async rebroadcastPendingTransaction(transactionHash, options) {
|
|
1349
|
-
|
|
1350
|
-
assertTransactionHash(transactionHash);
|
|
1309
|
+
transactionHash = new TransactionId(transactionHash);
|
|
1351
1310
|
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
|
|
1352
1311
|
}
|
|
1353
1312
|
/**
|
|
@@ -1356,12 +1315,15 @@ export class Bee {
|
|
|
1356
1315
|
* @param gasPrice
|
|
1357
1316
|
*/
|
|
1358
1317
|
async cancelPendingTransaction(transactionHash, gasPrice, options) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1318
|
+
transactionHash = new TransactionId(transactionHash);
|
|
1319
|
+
let gasPriceString;
|
|
1361
1320
|
if (gasPrice) {
|
|
1362
|
-
|
|
1321
|
+
gasPriceString = asNumberString(gasPrice, {
|
|
1322
|
+
min: 0n,
|
|
1323
|
+
name: 'gasPrice'
|
|
1324
|
+
});
|
|
1363
1325
|
}
|
|
1364
|
-
return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash,
|
|
1326
|
+
return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPriceString);
|
|
1365
1327
|
}
|
|
1366
1328
|
/**
|
|
1367
1329
|
* Gets the staked amount of BZZ (in PLUR unit) as number string.
|
|
@@ -1369,7 +1331,6 @@ export class Bee {
|
|
|
1369
1331
|
* @param options
|
|
1370
1332
|
*/
|
|
1371
1333
|
async getStake(options) {
|
|
1372
|
-
assertRequestOptions(options);
|
|
1373
1334
|
return stake.getStake(this.getRequestOptionsForCall(options));
|
|
1374
1335
|
}
|
|
1375
1336
|
/**
|
|
@@ -1381,9 +1342,14 @@ export class Bee {
|
|
|
1381
1342
|
* @param options
|
|
1382
1343
|
*/
|
|
1383
1344
|
async depositStake(amount, options, requestOptions) {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1345
|
+
const amountString = amount instanceof BZZ ? amount.toPLURString() : asNumberString(amount, {
|
|
1346
|
+
min: 1n,
|
|
1347
|
+
name: 'amount'
|
|
1348
|
+
});
|
|
1349
|
+
if (options) {
|
|
1350
|
+
options = prepareTransactionOptions(options);
|
|
1351
|
+
}
|
|
1352
|
+
return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
|
|
1387
1353
|
}
|
|
1388
1354
|
/**
|
|
1389
1355
|
* Get current status of node in redistribution game
|
|
@@ -1391,7 +1357,6 @@ export class Bee {
|
|
|
1391
1357
|
* @param options
|
|
1392
1358
|
*/
|
|
1393
1359
|
async getRedistributionState(options) {
|
|
1394
|
-
assertRequestOptions(options);
|
|
1395
1360
|
return stake.getRedistributionState(this.getRequestOptionsForCall(options));
|
|
1396
1361
|
}
|
|
1397
1362
|
async waitForUsablePostageStamp(id, timeout = 240000) {
|
|
@@ -1402,26 +1367,17 @@ export class Bee {
|
|
|
1402
1367
|
if (stamp.usable) {
|
|
1403
1368
|
return;
|
|
1404
1369
|
}
|
|
1405
|
-
} catch (error) {
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
// ignore error
|
|
1372
|
+
}
|
|
1406
1373
|
await System.sleepMillis(TIME_STEP);
|
|
1407
1374
|
}
|
|
1408
1375
|
throw new BeeError('Timeout on waiting for postage stamp to become usable');
|
|
1409
1376
|
}
|
|
1410
|
-
/**
|
|
1411
|
-
* @param signer
|
|
1412
|
-
* @private
|
|
1413
|
-
* @throws BeeError if either no Signer was passed or no default Signer was specified for the instance
|
|
1414
|
-
*/
|
|
1415
|
-
resolveSigner(signer) {
|
|
1416
|
-
if (signer) {
|
|
1417
|
-
return makeSigner(signer);
|
|
1418
|
-
}
|
|
1419
|
-
if (this.signer) {
|
|
1420
|
-
return this.signer;
|
|
1421
|
-
}
|
|
1422
|
-
throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.');
|
|
1423
|
-
}
|
|
1424
1377
|
getRequestOptionsForCall(options) {
|
|
1378
|
+
if (options) {
|
|
1379
|
+
options = prepareBeeRequestOptions(options);
|
|
1380
|
+
}
|
|
1425
1381
|
return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
|
|
1426
1382
|
}
|
|
1427
1383
|
}
|