@ethersphere/bee-js 9.1.0 → 9.1.2
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 +2 -0
- package/dist/cjs/bee.js +2 -2
- package/dist/cjs/manifest/manifest.js +26 -6
- package/dist/cjs/utils/stamps.js +1 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +2 -2
- package/dist/mjs/manifest/manifest.js +26 -5
- package/dist/mjs/utils/stamps.js +1 -1
- package/dist/types/manifest/manifest.d.ts +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -374,6 +374,8 @@ After making changes, link the package to your project by running `npm link` in
|
|
|
374
374
|
|
|
375
375
|
### Test
|
|
376
376
|
|
|
377
|
+
[Code coverage](https://bah5acgza26tlmya36bdiu5cdfs3hh22hqthkhfv6cvq2ugxqrv5aw267ydlq.bzz.limo/)
|
|
378
|
+
|
|
377
379
|
Tests are currently run against a mainnet Bee nodes. This is temporary and this section will be revised in the future.
|
|
378
380
|
|
|
379
381
|
## License
|
package/dist/cjs/bee.js
CHANGED
|
@@ -1150,7 +1150,7 @@ class Bee {
|
|
|
1150
1150
|
throw new error_1.BeeArgumentError(`Depth has to be between ${types_1.STAMPS_DEPTH_MIN}..${types_1.STAMPS_DEPTH_MAX}`, depth);
|
|
1151
1151
|
}
|
|
1152
1152
|
const chainState = await this.getChainState();
|
|
1153
|
-
const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
|
|
1153
|
+
const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n;
|
|
1154
1154
|
if (BigInt(amountString) < minimumAmount) {
|
|
1155
1155
|
throw new error_1.BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
|
|
1156
1156
|
}
|
|
@@ -1182,7 +1182,7 @@ class Bee {
|
|
|
1182
1182
|
if (delta <= 0) {
|
|
1183
1183
|
throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1184
1184
|
}
|
|
1185
|
-
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
|
|
1185
|
+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1) + 1n, options);
|
|
1186
1186
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1187
1187
|
}
|
|
1188
1188
|
async extendStorageDuration(postageBatchId, duration, options) {
|
|
@@ -20,6 +20,22 @@ class Fork {
|
|
|
20
20
|
}
|
|
21
21
|
static split(a, b) {
|
|
22
22
|
const commonPart = cafe_utility_1.Binary.commonPrefix(a.prefix, b.prefix);
|
|
23
|
+
if (commonPart.length === a.prefix.length) {
|
|
24
|
+
const remainingB = b.prefix.slice(commonPart.length);
|
|
25
|
+
b.node.path = b.prefix.slice(commonPart.length);
|
|
26
|
+
b.prefix = b.prefix.slice(commonPart.length);
|
|
27
|
+
b.node.parent = a.node;
|
|
28
|
+
a.node.forks.set(remainingB[0], b);
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
if (commonPart.length === b.prefix.length) {
|
|
32
|
+
const remainingA = a.prefix.slice(commonPart.length);
|
|
33
|
+
a.node.path = a.prefix.slice(commonPart.length);
|
|
34
|
+
a.prefix = a.prefix.slice(commonPart.length);
|
|
35
|
+
a.node.parent = b.node;
|
|
36
|
+
b.node.forks.set(remainingA[0], a);
|
|
37
|
+
return b;
|
|
38
|
+
}
|
|
23
39
|
const node = new MantarayNode({ path: commonPart });
|
|
24
40
|
const newAFork = new Fork(a.prefix.slice(commonPart.length), a.node);
|
|
25
41
|
const newBFork = new Fork(b.prefix.slice(commonPart.length), b.node);
|
|
@@ -58,13 +74,13 @@ class Fork {
|
|
|
58
74
|
const prefixLength = cafe_utility_1.Binary.uint8ToNumber(reader.read(1));
|
|
59
75
|
const prefix = reader.read(prefixLength);
|
|
60
76
|
reader.read(30 - prefixLength);
|
|
61
|
-
const
|
|
77
|
+
const selfAddress = reader.read(32);
|
|
62
78
|
let metadata = undefined;
|
|
63
79
|
if (isType(type, TYPE_WITH_METADATA)) {
|
|
64
80
|
const metadataLength = cafe_utility_1.Binary.uint16ToNumber(reader.read(2), 'BE');
|
|
65
81
|
metadata = JSON.parse(DECODER.decode(reader.read(metadataLength)));
|
|
66
82
|
}
|
|
67
|
-
return new Fork(prefix, new MantarayNode({
|
|
83
|
+
return new Fork(prefix, new MantarayNode({ selfAddress, metadata, path: prefix }));
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
86
|
exports.Fork = Fork;
|
|
@@ -175,15 +191,16 @@ class MantarayNode {
|
|
|
175
191
|
* Do not forget calling `loadRecursively` on the returned node to load the entire tree.
|
|
176
192
|
*/
|
|
177
193
|
static async unmarshal(bee, reference, options, requestOptions) {
|
|
194
|
+
reference = new typed_bytes_1.Reference(reference);
|
|
178
195
|
const data = (await bee.downloadData(reference, options, requestOptions)).toUint8Array();
|
|
179
|
-
return this.unmarshalFromData(data);
|
|
196
|
+
return this.unmarshalFromData(data, reference.toUint8Array());
|
|
180
197
|
}
|
|
181
198
|
/**
|
|
182
199
|
* Unmarshals a MantarayNode from the given data.
|
|
183
200
|
*
|
|
184
201
|
* Do not forget calling `loadRecursively` on the returned node to load the entire tree.
|
|
185
202
|
*/
|
|
186
|
-
static unmarshalFromData(data) {
|
|
203
|
+
static unmarshalFromData(data, selfAddress) {
|
|
187
204
|
const obfuscationKey = data.subarray(0, 32);
|
|
188
205
|
const decrypted = cafe_utility_1.Binary.xorCypher(data.subarray(32), obfuscationKey);
|
|
189
206
|
const reader = new cafe_utility_1.Uint8ArrayReader(decrypted);
|
|
@@ -193,7 +210,7 @@ class MantarayNode {
|
|
|
193
210
|
}
|
|
194
211
|
const targetAddressLength = cafe_utility_1.Binary.uint8ToNumber(reader.read(1));
|
|
195
212
|
const targetAddress = targetAddressLength === 0 ? __1.NULL_ADDRESS : reader.read(targetAddressLength);
|
|
196
|
-
const node = new MantarayNode({ targetAddress, obfuscationKey });
|
|
213
|
+
const node = new MantarayNode({ selfAddress, targetAddress, obfuscationKey });
|
|
197
214
|
const forkBitmap = reader.read(32);
|
|
198
215
|
for (let i = 0; i < 256; i++) {
|
|
199
216
|
if (cafe_utility_1.Binary.getBit(forkBitmap, i, 'LE')) {
|
|
@@ -290,7 +307,10 @@ class MantarayNode {
|
|
|
290
307
|
*/
|
|
291
308
|
async loadRecursively(bee, options, requestOptions) {
|
|
292
309
|
for (const fork of this.forks.values()) {
|
|
293
|
-
|
|
310
|
+
if (!fork.node.selfAddress) {
|
|
311
|
+
throw Error('MantarayNode#loadRecursively fork.node.selfAddress is not set');
|
|
312
|
+
}
|
|
313
|
+
const node = await MantarayNode.unmarshal(bee, fork.node.selfAddress, options, requestOptions);
|
|
294
314
|
fork.node.targetAddress = node.targetAddress;
|
|
295
315
|
fork.node.forks = node.forks;
|
|
296
316
|
fork.node.path = fork.prefix;
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -111,7 +111,7 @@ exports.getStampDuration = getStampDuration;
|
|
|
111
111
|
* @param blockTime The block time in seconds.
|
|
112
112
|
*/
|
|
113
113
|
function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
114
|
-
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock);
|
|
114
|
+
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n;
|
|
115
115
|
}
|
|
116
116
|
exports.getAmountForDuration = getAmountForDuration;
|
|
117
117
|
/**
|