@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
|
@@ -4,6 +4,7 @@ import { http } from "../../utils/http.js";
|
|
|
4
4
|
import { getStampEffectiveBytes, getStampTheoreticalBytes, getStampUsage } from "../../utils/stamps.js";
|
|
5
5
|
import { asNumberString } from "../../utils/type.js";
|
|
6
6
|
import { BatchId, EthAddress } from "../../utils/typed-bytes.js";
|
|
7
|
+
import { normalizeBatchTTL } from "../../utils/workaround.js";
|
|
7
8
|
const STAMPS_ENDPOINT = 'stamps';
|
|
8
9
|
const BATCHES_ENDPOINT = 'batches';
|
|
9
10
|
export async function getGlobalPostageBatches(requestOptions) {
|
|
@@ -72,9 +73,9 @@ export async function getAllPostageBatches(requestOptions) {
|
|
|
72
73
|
name: 'bucketDepth'
|
|
73
74
|
});
|
|
74
75
|
const usage = getStampUsage(utilization, depth, bucketDepth);
|
|
75
|
-
const batchTTL = Types.asNumber(x.batchTTL, {
|
|
76
|
+
const batchTTL = normalizeBatchTTL(Types.asNumber(x.batchTTL, {
|
|
76
77
|
name: 'batchTTL'
|
|
77
|
-
});
|
|
78
|
+
}));
|
|
78
79
|
const duration = Duration.fromSeconds(batchTTL);
|
|
79
80
|
return {
|
|
80
81
|
batchID: new BatchId(Types.asString(x.batchID, {
|
|
@@ -125,9 +126,9 @@ export async function getPostageBatch(requestOptions, postageBatchId) {
|
|
|
125
126
|
name: 'bucketDepth'
|
|
126
127
|
});
|
|
127
128
|
const usage = getStampUsage(utilization, depth, bucketDepth);
|
|
128
|
-
const batchTTL = Types.asNumber(body.batchTTL, {
|
|
129
|
+
const batchTTL = normalizeBatchTTL(Types.asNumber(body.batchTTL, {
|
|
129
130
|
name: 'batchTTL'
|
|
130
|
-
});
|
|
131
|
+
}));
|
|
131
132
|
const duration = Duration.fromSeconds(batchTTL);
|
|
132
133
|
return {
|
|
133
134
|
batchID: new BatchId(Types.asString(body.batchID, {
|
|
@@ -2,6 +2,7 @@ import { Types } from 'cafe-utility';
|
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
3
|
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
4
4
|
import { asNumberString } from "../../utils/type.js";
|
|
5
|
+
import { normalizeCurrentPrice } from "../../utils/workaround.js";
|
|
5
6
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
6
7
|
const WALLET_ENDPOINT = 'wallet';
|
|
7
8
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
@@ -55,9 +56,9 @@ export async function getChainState(requestOptions) {
|
|
|
55
56
|
totalAmount: asNumberString(body.totalAmount, {
|
|
56
57
|
name: 'totalAmount'
|
|
57
58
|
}),
|
|
58
|
-
currentPrice: Types.asNumber(body.currentPrice, {
|
|
59
|
+
currentPrice: normalizeCurrentPrice(Types.asNumber(body.currentPrice, {
|
|
59
60
|
name: 'currentPrice'
|
|
60
|
-
})
|
|
61
|
+
}))
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
/**
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -61,8 +61,7 @@ export function getStampEffectiveBytes(depth) {
|
|
|
61
61
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
62
62
|
*/
|
|
63
63
|
export function getStampCost(depth, amount) {
|
|
64
|
-
|
|
65
|
-
return BZZ.fromPLUR(2n ** BigInt(depth) * amountBigInt);
|
|
64
|
+
return BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
|
|
66
65
|
}
|
|
67
66
|
/**
|
|
68
67
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// TODO: Remove this file after the issue is fixed
|
|
2
|
+
export function normalizeBatchTTL(batchTTL) {
|
|
3
|
+
if (!Number.isInteger(batchTTL)) {
|
|
4
|
+
return 1;
|
|
5
|
+
}
|
|
6
|
+
if (batchTTL < 1) {
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
if (batchTTL > 315569260) {
|
|
10
|
+
return 315569260;
|
|
11
|
+
}
|
|
12
|
+
return batchTTL;
|
|
13
|
+
}
|
|
14
|
+
export function normalizeCurrentPrice(currentPrice) {
|
|
15
|
+
if (!Number.isInteger(currentPrice)) {
|
|
16
|
+
return 24000;
|
|
17
|
+
}
|
|
18
|
+
if (currentPrice < 24000) {
|
|
19
|
+
return 24000;
|
|
20
|
+
}
|
|
21
|
+
return currentPrice;
|
|
22
|
+
}
|