@ethersphere/bee-js 10.1.0 → 10.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/dist/cjs/bee.js CHANGED
@@ -1623,7 +1623,7 @@ class Bee {
1623
1623
  const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
1624
1624
  const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, blockTime);
1625
1625
  const currentCost = (0, stamps_1.getStampCost)(batch.depth, currentAmount);
1626
- const newCost = (0, stamps_1.getStampCost)(depth, currentAmount + amount);
1626
+ const newCost = (0, stamps_1.getStampCost)(Math.max(batch.depth, depth), currentAmount + amount);
1627
1627
  return newCost.minus(currentCost);
1628
1628
  }
1629
1629
  /**
@@ -1743,13 +1743,15 @@ class Bee {
1743
1743
  *
1744
1744
  * @param postageBatchId Batch ID
1745
1745
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1746
+ * @param encryption Assume that uploads with this postage batch are encrypted, which skews the capacity.
1747
+ * @param erasureCodeLevel Assume that uploads with this postage batch are erasure coded, which skews the capacity.
1746
1748
  *
1747
1749
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1748
1750
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
1749
1751
  */
1750
- async getPostageBatch(postageBatchId, requestOptions) {
1752
+ async getPostageBatch(postageBatchId, requestOptions, encryption, erasureCodeLevel) {
1751
1753
  postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
1752
- return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId);
1754
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, encryption, erasureCodeLevel);
1753
1755
  }
1754
1756
  /**
1755
1757
  * Return detailed information related to buckets for specific postage batch.
@@ -46,6 +46,7 @@ async function getAllPostageBatches(requestOptions) {
46
46
  const usage = (0, stamps_1.getStampUsage)(utilization, depth, bucketDepth);
47
47
  const batchTTL = (0, workaround_1.normalizeBatchTTL)(cafe_utility_1.Types.asNumber(x.batchTTL, { name: 'batchTTL' }));
48
48
  const duration = duration_1.Duration.fromSeconds(batchTTL);
49
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(depth);
49
50
  return {
50
51
  batchID: new typed_bytes_1.BatchId(cafe_utility_1.Types.asString(x.batchID, { name: 'batchID' })),
51
52
  utilization,
@@ -58,15 +59,23 @@ async function getAllPostageBatches(requestOptions) {
58
59
  immutableFlag: cafe_utility_1.Types.asBoolean(x.immutableFlag, { name: 'immutableFlag' }),
59
60
  usage,
60
61
  usageText: `${Math.round(usage * 100)}%`,
61
- size: size_1.Size.fromBytes((0, stamps_1.getStampEffectiveBytes)(depth)),
62
- remainingSize: size_1.Size.fromBytes(Math.ceil((0, stamps_1.getStampEffectiveBytes)(depth) * (1 - usage))),
62
+ size: size_1.Size.fromBytes(effectiveBytes),
63
+ remainingSize: size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
63
64
  theoreticalSize: size_1.Size.fromBytes((0, stamps_1.getStampTheoreticalBytes)(depth)),
64
65
  duration,
66
+ calculateSize(encryption, redundancyLevel) {
67
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(this.depth, encryption, redundancyLevel);
68
+ return size_1.Size.fromBytes(effectiveBytes);
69
+ },
70
+ calculateRemainingSize(encryption, redundancyLevel) {
71
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(this.depth, encryption, redundancyLevel);
72
+ return size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - this.usage)));
73
+ },
65
74
  };
66
75
  });
67
76
  }
68
77
  exports.getAllPostageBatches = getAllPostageBatches;
69
- async function getPostageBatch(requestOptions, postageBatchId) {
78
+ async function getPostageBatch(requestOptions, postageBatchId, encryption, erasureCodeLevel) {
70
79
  const response = await (0, http_1.http)(requestOptions, {
71
80
  method: 'get',
72
81
  url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
@@ -79,6 +88,7 @@ async function getPostageBatch(requestOptions, postageBatchId) {
79
88
  const usage = (0, stamps_1.getStampUsage)(utilization, depth, bucketDepth);
80
89
  const batchTTL = (0, workaround_1.normalizeBatchTTL)(cafe_utility_1.Types.asNumber(body.batchTTL, { name: 'batchTTL' }));
81
90
  const duration = duration_1.Duration.fromSeconds(batchTTL);
91
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(depth, encryption, erasureCodeLevel);
82
92
  return {
83
93
  batchID: new typed_bytes_1.BatchId(cafe_utility_1.Types.asString(body.batchID, { name: 'batchID' })),
84
94
  utilization,
@@ -91,10 +101,18 @@ async function getPostageBatch(requestOptions, postageBatchId) {
91
101
  immutableFlag: cafe_utility_1.Types.asBoolean(body.immutableFlag, { name: 'immutableFlag' }),
92
102
  usage,
93
103
  usageText: `${Math.round(usage * 100)}%`,
94
- size: size_1.Size.fromBytes((0, stamps_1.getStampEffectiveBytes)(depth)),
95
- remainingSize: size_1.Size.fromBytes(Math.ceil((0, stamps_1.getStampEffectiveBytes)(depth) * (1 - usage))),
104
+ size: size_1.Size.fromBytes(effectiveBytes),
105
+ remainingSize: size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
96
106
  theoreticalSize: size_1.Size.fromBytes((0, stamps_1.getStampTheoreticalBytes)(depth)),
97
107
  duration,
108
+ calculateSize(encryption, redundancyLevel) {
109
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(depth, encryption, redundancyLevel);
110
+ return size_1.Size.fromBytes(effectiveBytes);
111
+ },
112
+ calculateRemainingSize(encryption, redundancyLevel) {
113
+ const effectiveBytes = (0, stamps_1.getStampEffectiveBytes)(depth, encryption, redundancyLevel);
114
+ return size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage)));
115
+ },
98
116
  };
99
117
  }
100
118
  exports.getPostageBatch = getPostageBatch;