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