@upcoming/bee-js 0.10.0 → 0.10.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/dist/cjs/modules/debug/stamps.js +3 -2
- package/dist/cjs/modules/debug/states.js +2 -1
- package/dist/cjs/utils/stamps.js +1 -2
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/modules/debug/stamps.js +5 -4
- package/dist/mjs/modules/debug/states.js +3 -2
- package/dist/mjs/utils/stamps.js +1 -2
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ const http_1 = require("../../utils/http");
|
|
|
7
7
|
const stamps_1 = require("../../utils/stamps");
|
|
8
8
|
const type_1 = require("../../utils/type");
|
|
9
9
|
const typed_bytes_1 = require("../../utils/typed-bytes");
|
|
10
|
+
const workaround_1 = require("../../utils/workaround");
|
|
10
11
|
const STAMPS_ENDPOINT = 'stamps';
|
|
11
12
|
const BATCHES_ENDPOINT = 'batches';
|
|
12
13
|
async function getGlobalPostageBatches(requestOptions) {
|
|
@@ -42,7 +43,7 @@ async function getAllPostageBatches(requestOptions) {
|
|
|
42
43
|
const depth = cafe_utility_1.Types.asNumber(x.depth, { name: 'depth' });
|
|
43
44
|
const bucketDepth = cafe_utility_1.Types.asNumber(x.bucketDepth, { name: 'bucketDepth' });
|
|
44
45
|
const usage = (0, stamps_1.getStampUsage)(utilization, depth, bucketDepth);
|
|
45
|
-
const batchTTL = cafe_utility_1.Types.asNumber(x.batchTTL, { name: 'batchTTL' });
|
|
46
|
+
const batchTTL = (0, workaround_1.normalizeBatchTTL)(cafe_utility_1.Types.asNumber(x.batchTTL, { name: 'batchTTL' }));
|
|
46
47
|
const duration = duration_1.Duration.fromSeconds(batchTTL);
|
|
47
48
|
return {
|
|
48
49
|
batchID: new typed_bytes_1.BatchId(cafe_utility_1.Types.asString(x.batchID, { name: 'batchID' })),
|
|
@@ -74,7 +75,7 @@ async function getPostageBatch(requestOptions, postageBatchId) {
|
|
|
74
75
|
const depth = cafe_utility_1.Types.asNumber(body.depth, { name: 'depth' });
|
|
75
76
|
const bucketDepth = cafe_utility_1.Types.asNumber(body.bucketDepth, { name: 'bucketDepth' });
|
|
76
77
|
const usage = (0, stamps_1.getStampUsage)(utilization, depth, bucketDepth);
|
|
77
|
-
const batchTTL = cafe_utility_1.Types.asNumber(body.batchTTL, { name: 'batchTTL' });
|
|
78
|
+
const batchTTL = (0, workaround_1.normalizeBatchTTL)(cafe_utility_1.Types.asNumber(body.batchTTL, { name: 'batchTTL' }));
|
|
78
79
|
const duration = duration_1.Duration.fromSeconds(batchTTL);
|
|
79
80
|
return {
|
|
80
81
|
batchID: new typed_bytes_1.BatchId(cafe_utility_1.Types.asString(body.batchID, { name: 'batchID' })),
|
|
@@ -5,6 +5,7 @@ const cafe_utility_1 = require("cafe-utility");
|
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
6
|
const tokens_1 = require("../../utils/tokens");
|
|
7
7
|
const type_1 = require("../../utils/type");
|
|
8
|
+
const workaround_1 = require("../../utils/workaround");
|
|
8
9
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
9
10
|
const WALLET_ENDPOINT = 'wallet';
|
|
10
11
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
@@ -43,7 +44,7 @@ async function getChainState(requestOptions) {
|
|
|
43
44
|
block: cafe_utility_1.Types.asNumber(body.block, { name: 'block' }),
|
|
44
45
|
chainTip: cafe_utility_1.Types.asNumber(body.chainTip, { name: 'chainTip' }),
|
|
45
46
|
totalAmount: (0, type_1.asNumberString)(body.totalAmount, { name: 'totalAmount' }),
|
|
46
|
-
currentPrice: cafe_utility_1.Types.asNumber(body.currentPrice, { name: 'currentPrice' }),
|
|
47
|
+
currentPrice: (0, workaround_1.normalizeCurrentPrice)(cafe_utility_1.Types.asNumber(body.currentPrice, { name: 'currentPrice' })),
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
exports.getChainState = getChainState;
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -80,8 +80,7 @@ exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
|
80
80
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
81
81
|
*/
|
|
82
82
|
function getStampCost(depth, amount) {
|
|
83
|
-
|
|
84
|
-
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * amountBigInt);
|
|
83
|
+
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
|
|
85
84
|
}
|
|
86
85
|
exports.getStampCost = getStampCost;
|
|
87
86
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: Remove this file after the issue is fixed
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.normalizeCurrentPrice = exports.normalizeBatchTTL = void 0;
|
|
5
|
+
function normalizeBatchTTL(batchTTL) {
|
|
6
|
+
if (!Number.isInteger(batchTTL)) {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
if (batchTTL < 1) {
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
if (batchTTL > 315569260) {
|
|
13
|
+
return 315569260;
|
|
14
|
+
}
|
|
15
|
+
return batchTTL;
|
|
16
|
+
}
|
|
17
|
+
exports.normalizeBatchTTL = normalizeBatchTTL;
|
|
18
|
+
function normalizeCurrentPrice(currentPrice) {
|
|
19
|
+
if (!Number.isInteger(currentPrice)) {
|
|
20
|
+
return 24000;
|
|
21
|
+
}
|
|
22
|
+
if (currentPrice < 24000) {
|
|
23
|
+
return 24000;
|
|
24
|
+
}
|
|
25
|
+
return currentPrice;
|
|
26
|
+
}
|
|
27
|
+
exports.normalizeCurrentPrice = normalizeCurrentPrice;
|