@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.
@@ -539,9 +539,16 @@ export class BeeDebug {
539
539
  async waitForUsablePostageStamp(id, timeout = 120000) {
540
540
  const TIME_STEP = 1500;
541
541
  for (let time = 0; time < timeout; time += TIME_STEP) {
542
- const stamp = await this.getPostageBatch(id);
543
- if (stamp.usable) {
544
- return;
542
+ try {
543
+ const stamp = await this.getPostageBatch(id);
544
+ if (stamp.usable) {
545
+ return;
546
+ }
547
+ } catch (error) {
548
+ const message = error?.response?.data?.message || error?.message || '';
549
+ if (!message.includes('batch not usable')) {
550
+ throw error;
551
+ }
545
552
  }
546
553
  await System.sleepMillis(TIME_STEP);
547
554
  }
@@ -58,7 +58,7 @@ export function makeFeedReader(requestOptions, type, topic, owner) {
58
58
  owner,
59
59
  topic,
60
60
  async download(options) {
61
- if (!options?.index) {
61
+ if (!options?.index && options?.index !== 0) {
62
62
  return fetchLatestFeedUpdate(requestOptions, owner, topic, {
63
63
  ...options,
64
64
  type
@@ -6,4 +6,4 @@ export { ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, m
6
6
  export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode } from "./stream.js";
7
7
  export { keccak256Hash } from "./hash.js";
8
8
  export { makeMaxTarget } from "./pss.js";
9
- export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
9
+ export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
@@ -18,6 +18,39 @@ export function getStampUsage(utilization, depth, bucketDepth) {
18
18
  export function getStampMaximumCapacityBytes(depth) {
19
19
  return 2 ** depth * 4096;
20
20
  }
21
+ /**
22
+ * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
23
+ */
24
+ const utilisationRateMap = {
25
+ 22: 0.2867,
26
+ 23: 0.4956,
27
+ 24: 0.6433,
28
+ 25: 0.7478,
29
+ 26: 0.8217,
30
+ 27: 0.8739,
31
+ 28: 0.9108,
32
+ 29: 0.9369,
33
+ 30: 0.9554,
34
+ 31: 0.9685,
35
+ 32: 0.9777,
36
+ 33: 0.9842,
37
+ 34: 0.9889
38
+ };
39
+ /**
40
+ * Utility function that calculates the effective volume of a postage batch based on its depth.
41
+ *
42
+ * Below 22 depth the effective volume is 0
43
+ * Above 34 it's always > 99%
44
+ *
45
+ * @returns {number} The effective volume of the postage batch in bytes.
46
+ */
47
+ export function getStampEffectiveBytes(depth) {
48
+ if (depth < 22) {
49
+ return 0;
50
+ }
51
+ const utilRate = utilisationRateMap[depth] ?? 0.99;
52
+ return getStampMaximumCapacityBytes(depth) * utilRate;
53
+ }
21
54
  /**
22
55
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
23
56
  *
@@ -1,5 +1,5 @@
1
1
  import { FeedUpdateOptions } from '../modules/feed';
2
- import { BatchId, BeeRequestOptions, BytesReference, FeedReader, FeedWriter, FEED_INDEX_HEX_LENGTH, PlainBytesReference, Reference, Signer, Topic, UploadOptions } from '../types';
2
+ import { BatchId, BeeRequestOptions, BytesReference, FEED_INDEX_HEX_LENGTH, FeedReader, FeedWriter, PlainBytesReference, Reference, Signer, Topic, UploadOptions } from '../types';
3
3
  import { Bytes } from '../utils/bytes';
4
4
  import { EthAddress, HexEthAddress } from '../utils/eth';
5
5
  import { HexString } from '../utils/hex';
@@ -1,3 +1,4 @@
1
+ import { Index } from '../feed';
1
2
  import { FeedType } from '../feed/type';
2
3
  import { BatchId, BeeRequestOptions, Reference, ReferenceResponse, Topic } from '../types';
3
4
  import { HexEthAddress } from '../utils/eth';
@@ -16,13 +17,13 @@ export interface FeedUpdateOptions {
16
17
  /**
17
18
  * Fetch specific previous Feed's update (default fetches latest update)
18
19
  */
19
- index?: string;
20
+ index?: Index;
20
21
  }
21
22
  interface FeedUpdateHeaders {
22
23
  /**
23
24
  * The current feed's index
24
25
  */
25
- feedIndex: string;
26
+ feedIndex: Index;
26
27
  /**
27
28
  * The feed's index for next update.
28
29
  * Only set for the latest update. If update is fetched using previous index, then this is an empty string.
@@ -6,4 +6,4 @@ export { EthAddress, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeE
6
6
  export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode, } from './stream';
7
7
  export { keccak256Hash } from './hash';
8
8
  export { makeMaxTarget } from './pss';
9
- export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
9
+ export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
@@ -15,6 +15,15 @@ export declare function getStampUsage(utilization: number, depth: number, bucket
15
15
  * @returns {number} The maximum capacity of the postage batch in bytes.
16
16
  */
17
17
  export declare function getStampMaximumCapacityBytes(depth: number): number;
18
+ /**
19
+ * Utility function that calculates the effective volume of a postage batch based on its depth.
20
+ *
21
+ * Below 22 depth the effective volume is 0
22
+ * Above 34 it's always > 99%
23
+ *
24
+ * @returns {number} The effective volume of the postage batch in bytes.
25
+ */
26
+ export declare function getStampEffectiveBytes(depth: number): number;
18
27
  /**
19
28
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
20
29
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "6.6.0",
3
+ "version": "6.7.2",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",