@ethersphere/bee-js 9.1.2 → 9.2.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/README.md +3 -0
- package/dist/cjs/bee.js +18 -1
- package/dist/cjs/utils/size.js +6 -0
- package/dist/cjs/utils/stamps.js +33 -33
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +18 -1
- package/dist/mjs/utils/size.js +6 -0
- package/dist/mjs/utils/stamps.js +16 -22
- package/dist/types/bee.d.ts +13 -0
- package/dist/types/utils/size.d.ts +2 -0
- package/package.json +1 -1
package/dist/mjs/bee.js
CHANGED
|
@@ -1276,14 +1276,31 @@ export class Bee {
|
|
|
1276
1276
|
*
|
|
1277
1277
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1278
1278
|
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1279
|
+
* @deprecated Use `getPostageBatches` instead
|
|
1279
1280
|
*/
|
|
1280
1281
|
async getAllPostageBatch(options) {
|
|
1281
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1282
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1282
1283
|
}
|
|
1283
1284
|
/**
|
|
1284
1285
|
* Return all globally available postage batches.
|
|
1286
|
+
* @deprecated Use `getGlobalPostageBatches` instead
|
|
1285
1287
|
*/
|
|
1286
1288
|
async getAllGlobalPostageBatch(options) {
|
|
1289
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1290
|
+
}
|
|
1291
|
+
/**
|
|
1292
|
+
* Return all postage batches that belong to the node.
|
|
1293
|
+
*
|
|
1294
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1295
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1296
|
+
*/
|
|
1297
|
+
async getPostageBatches(options) {
|
|
1298
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Return all globally available postage batches.
|
|
1302
|
+
*/
|
|
1303
|
+
async getGlobalPostageBatches(options) {
|
|
1287
1304
|
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1288
1305
|
}
|
|
1289
1306
|
/**
|
package/dist/mjs/utils/size.js
CHANGED
|
@@ -16,6 +16,12 @@ export class Size {
|
|
|
16
16
|
static fromBytes(bytes) {
|
|
17
17
|
return new Size(bytes);
|
|
18
18
|
}
|
|
19
|
+
static fromKilobytes(kilobytes) {
|
|
20
|
+
return new Size(kilobytes * 1000);
|
|
21
|
+
}
|
|
22
|
+
static fromMegabytes(megabytes) {
|
|
23
|
+
return new Size(megabytes * 1000 * 1000);
|
|
24
|
+
}
|
|
19
25
|
static fromGigabytes(gigabytes) {
|
|
20
26
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
21
27
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Bytes } from "./bytes.js";
|
|
|
3
3
|
import { Duration } from "./duration.js";
|
|
4
4
|
import { BZZ } from "./tokens.js";
|
|
5
5
|
import { asNumberString } from "./type.js";
|
|
6
|
+
const MAX_UTILIZATION = 0.9;
|
|
6
7
|
/**
|
|
7
8
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
8
9
|
*
|
|
@@ -25,23 +26,9 @@ export function getStampTheoreticalBytes(depth) {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
29
|
+
* Optimised for encrypted, medium erasure coding
|
|
28
30
|
*/
|
|
29
|
-
const
|
|
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
|
-
const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102.78], [26, 225.87], [27, 480.44], [28, 1001.44], [29, 2060.27], [30, 4201.9], [31, 8519.02], [32, 17199.89], [33, 34628.46]];
|
|
31
|
+
const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
|
|
45
32
|
/**
|
|
46
33
|
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
47
34
|
*
|
|
@@ -51,15 +38,22 @@ const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102
|
|
|
51
38
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
52
39
|
*/
|
|
53
40
|
export function getStampEffectiveBytes(depth) {
|
|
54
|
-
if (depth <
|
|
41
|
+
if (depth < 17) {
|
|
55
42
|
return 0;
|
|
56
43
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
44
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
45
|
+
if (depth === d) {
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (breakpoint) {
|
|
50
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
51
|
+
}
|
|
52
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
59
53
|
}
|
|
60
54
|
export function getStampEffectiveBytesBreakpoints() {
|
|
61
55
|
const map = new Map();
|
|
62
|
-
for (let i =
|
|
56
|
+
for (let i = 17; i < 35; i++) {
|
|
63
57
|
map.set(i, getStampEffectiveBytes(i));
|
|
64
58
|
}
|
|
65
59
|
return map;
|
|
@@ -99,11 +93,11 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
|
99
93
|
*/
|
|
100
94
|
export function getDepthForSize(size) {
|
|
101
95
|
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
102
|
-
if (size.
|
|
96
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
103
97
|
return depth;
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
|
-
return
|
|
100
|
+
return 35;
|
|
107
101
|
}
|
|
108
102
|
export function convertEnvelopeToMarshaledStamp(envelope) {
|
|
109
103
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -713,12 +713,25 @@ export declare class Bee {
|
|
|
713
713
|
*
|
|
714
714
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
715
715
|
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
716
|
+
* @deprecated Use `getPostageBatches` instead
|
|
716
717
|
*/
|
|
717
718
|
getAllPostageBatch(options?: BeeRequestOptions): Promise<PostageBatch[]>;
|
|
718
719
|
/**
|
|
719
720
|
* Return all globally available postage batches.
|
|
721
|
+
* @deprecated Use `getGlobalPostageBatches` instead
|
|
720
722
|
*/
|
|
721
723
|
getAllGlobalPostageBatch(options?: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
|
|
724
|
+
/**
|
|
725
|
+
* Return all postage batches that belong to the node.
|
|
726
|
+
*
|
|
727
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
728
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
729
|
+
*/
|
|
730
|
+
getPostageBatches(options?: BeeRequestOptions): Promise<PostageBatch[]>;
|
|
731
|
+
/**
|
|
732
|
+
* Return all globally available postage batches.
|
|
733
|
+
*/
|
|
734
|
+
getGlobalPostageBatches(options?: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
|
|
722
735
|
/**
|
|
723
736
|
* Return lists of all current pending transactions that the Bee made
|
|
724
737
|
*/
|
|
@@ -9,6 +9,8 @@ export declare class Size {
|
|
|
9
9
|
private bytes;
|
|
10
10
|
private constructor();
|
|
11
11
|
static fromBytes(bytes: number): Size;
|
|
12
|
+
static fromKilobytes(kilobytes: number): Size;
|
|
13
|
+
static fromMegabytes(megabytes: number): Size;
|
|
12
14
|
static fromGigabytes(gigabytes: number): Size;
|
|
13
15
|
toBytes(): number;
|
|
14
16
|
toGigabytes(): number;
|