@ethersphere/bee-js 6.6.0 → 6.7.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/dist/cjs/bee-debug.js +11 -3
- package/dist/cjs/feed/index.js +1 -1
- package/dist/cjs/utils/expose.js +2 -1
- package/dist/cjs/utils/stamps.js +35 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +10 -3
- package/dist/mjs/feed/index.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/stamps.js +33 -0
- package/dist/types/feed/index.d.ts +1 -1
- package/dist/types/modules/feed.d.ts +3 -2
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +9 -0
- package/package.json +1 -1
package/dist/cjs/bee-debug.js
CHANGED
|
@@ -567,9 +567,17 @@ class BeeDebug {
|
|
|
567
567
|
async waitForUsablePostageStamp(id, timeout = 120000) {
|
|
568
568
|
const TIME_STEP = 1500;
|
|
569
569
|
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
570
|
+
try {
|
|
571
|
+
const stamp = await this.getPostageBatch(id);
|
|
572
|
+
if (stamp.usable) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
const message = error?.response?.data?.message || error?.message || '';
|
|
578
|
+
if (!message.includes('batch not usable')) {
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
573
581
|
}
|
|
574
582
|
await cafe_utility_1.System.sleepMillis(TIME_STEP);
|
|
575
583
|
}
|
package/dist/cjs/feed/index.js
CHANGED
|
@@ -89,7 +89,7 @@ function makeFeedReader(requestOptions, type, topic, owner) {
|
|
|
89
89
|
owner,
|
|
90
90
|
topic,
|
|
91
91
|
async download(options) {
|
|
92
|
-
if (!options?.index) {
|
|
92
|
+
if (!options?.index && options?.index !== 0) {
|
|
93
93
|
return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic, { ...options, type });
|
|
94
94
|
}
|
|
95
95
|
const update = await downloadFeedUpdate(requestOptions, (0, hex_1.hexToBytes)(owner), topic, options.index);
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.readableWebToNode = exports.readableNodeToWeb = exports.normalizeToReadableStream = exports.isReadableStream = exports.isReadable = exports.isNodeReadable = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
3
|
+
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.readableWebToNode = exports.readableNodeToWeb = exports.normalizeToReadableStream = exports.isReadableStream = exports.isReadable = exports.isNodeReadable = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
6
|
var collection_node_1 = require("./collection.node");
|
|
@@ -46,5 +46,6 @@ Object.defineProperty(exports, "getDepthForCapacity", { enumerable: true, get: f
|
|
|
46
46
|
Object.defineProperty(exports, "getStampCostInBzz", { enumerable: true, get: function () { return stamps_1.getStampCostInBzz; } });
|
|
47
47
|
Object.defineProperty(exports, "getStampCostInPlur", { enumerable: true, get: function () { return stamps_1.getStampCostInPlur; } });
|
|
48
48
|
Object.defineProperty(exports, "getStampMaximumCapacityBytes", { enumerable: true, get: function () { return stamps_1.getStampMaximumCapacityBytes; } });
|
|
49
|
+
Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytes; } });
|
|
49
50
|
Object.defineProperty(exports, "getStampTtlSeconds", { enumerable: true, get: function () { return stamps_1.getStampTtlSeconds; } });
|
|
50
51
|
Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } });
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
|
|
3
|
+
exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
6
6
|
*
|
|
@@ -23,6 +23,40 @@ function getStampMaximumCapacityBytes(depth) {
|
|
|
23
23
|
return 2 ** depth * 4096;
|
|
24
24
|
}
|
|
25
25
|
exports.getStampMaximumCapacityBytes = getStampMaximumCapacityBytes;
|
|
26
|
+
/**
|
|
27
|
+
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
28
|
+
*/
|
|
29
|
+
const utilisationRateMap = {
|
|
30
|
+
22: 0.2867,
|
|
31
|
+
23: 0.4956,
|
|
32
|
+
24: 0.6433,
|
|
33
|
+
25: 0.7478,
|
|
34
|
+
26: 0.8217,
|
|
35
|
+
27: 0.8739,
|
|
36
|
+
28: 0.9108,
|
|
37
|
+
29: 0.9369,
|
|
38
|
+
30: 0.9554,
|
|
39
|
+
31: 0.9685,
|
|
40
|
+
32: 0.9777,
|
|
41
|
+
33: 0.9842,
|
|
42
|
+
34: 0.9889,
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Utility function that calculates the effective volume of a postage batch based on its depth.
|
|
46
|
+
*
|
|
47
|
+
* Below 22 depth the effective volume is 0
|
|
48
|
+
* Above 34 it's always > 99%
|
|
49
|
+
*
|
|
50
|
+
* @returns {number} The effective volume of the postage batch in bytes.
|
|
51
|
+
*/
|
|
52
|
+
function getStampEffectiveBytes(depth) {
|
|
53
|
+
if (depth < 22) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
const utilRate = utilisationRateMap[depth] ?? 0.99;
|
|
57
|
+
return getStampMaximumCapacityBytes(depth) * utilRate;
|
|
58
|
+
}
|
|
59
|
+
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
26
60
|
/**
|
|
27
61
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
28
62
|
*
|