@ethersphere/bee-js 9.0.2 → 9.1.0

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
@@ -84,6 +84,7 @@ class Bee {
84
84
  if (options?.signer) {
85
85
  this.signer = new typed_bytes_1.PrivateKey(options.signer);
86
86
  }
87
+ this.network = options?.network ?? 'gnosis';
87
88
  this.requestOptions = {
88
89
  baseURL: this.url,
89
90
  timeout: options?.timeout ?? 0,
@@ -1161,7 +1162,7 @@ class Bee {
1161
1162
  }
1162
1163
  async buyStorage(size, duration, options, requestOptions) {
1163
1164
  const chainState = await this.getChainState(requestOptions);
1164
- const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1165
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1165
1166
  const depth = (0, stamps_1.getDepthForSize)(size);
1166
1167
  if (options) {
1167
1168
  options = (0, type_1.preparePostageBatchOptions)(options);
@@ -1170,7 +1171,7 @@ class Bee {
1170
1171
  }
1171
1172
  async getStorageCost(size, duration, options) {
1172
1173
  const chainState = await this.getChainState(options);
1173
- const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1174
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1174
1175
  const depth = (0, stamps_1.getDepthForSize)(size);
1175
1176
  return (0, stamps_1.getStampCost)(depth, amount);
1176
1177
  }
@@ -1187,13 +1188,13 @@ class Bee {
1187
1188
  async extendStorageDuration(postageBatchId, duration, options) {
1188
1189
  const batch = await this.getPostageBatch(postageBatchId, options);
1189
1190
  const chainState = await this.getChainState(options);
1190
- const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1191
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1191
1192
  return this.topUpBatch(batch.batchID, amount, options);
1192
1193
  }
1193
1194
  async getExtensionCost(postageBatchId, size, duration, options) {
1194
1195
  const batch = await this.getPostageBatch(postageBatchId, options);
1195
1196
  const chainState = await this.getChainState(options);
1196
- const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1197
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1197
1198
  const depth = (0, stamps_1.getDepthForSize)(size);
1198
1199
  const currentValue = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
1199
1200
  const newValue = (0, stamps_1.getStampCost)(depth, amount);
@@ -1213,7 +1214,7 @@ class Bee {
1213
1214
  async getDurationExtensionCost(postageBatchId, duration, options) {
1214
1215
  const batch = await this.getPostageBatch(postageBatchId, options);
1215
1216
  const chainState = await this.getChainState(options);
1216
- const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
1217
+ const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1217
1218
  return (0, stamps_1.getStampCost)(batch.depth, amount);
1218
1219
  }
1219
1220
  /**
@@ -114,6 +114,7 @@ function makeFeedReader(requestOptions, topic, owner) {
114
114
  return {
115
115
  payload: update.payload,
116
116
  feedIndex,
117
+ feedIndexNext: feedIndex.next(),
117
118
  };
118
119
  };
119
120
  const downloadPayload = async (options) => {
@@ -128,6 +129,7 @@ function makeFeedReader(requestOptions, topic, owner) {
128
129
  return {
129
130
  payload,
130
131
  feedIndex,
132
+ feedIndexNext: feedIndex.next(),
131
133
  };
132
134
  };
133
135
  const downloadReference = async (options) => {
@@ -139,6 +141,7 @@ function makeFeedReader(requestOptions, topic, owner) {
139
141
  return {
140
142
  reference: new typed_bytes_1.Reference(payload.payload.toUint8Array()),
141
143
  feedIndex: payload.feedIndex,
144
+ feedIndexNext: payload.feedIndexNext ?? payload.feedIndex.next(),
142
145
  };
143
146
  };
144
147
  return {
@@ -98,7 +98,7 @@ exports.getStampCost = getStampCost;
98
98
  *
99
99
  * @returns {number} The TTL of the postage batch.
100
100
  */
101
- function getStampDuration(amount, pricePerBlock, blockTime = 5) {
101
+ function getStampDuration(amount, pricePerBlock, blockTime) {
102
102
  const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
103
103
  return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
104
104
  }
@@ -110,7 +110,7 @@ exports.getStampDuration = getStampDuration;
110
110
  * @param pricePerBlock The price per block in PLUR.
111
111
  * @param blockTime The block time in seconds.
112
112
  */
113
- function getAmountForDuration(duration, pricePerBlock, blockTime = 5) {
113
+ function getAmountForDuration(duration, pricePerBlock, blockTime) {
114
114
  return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock);
115
115
  }
116
116
  exports.getAmountForDuration = getAmountForDuration;
@@ -163,6 +163,7 @@ class Topic extends bytes_1.Bytes {
163
163
  }
164
164
  exports.Topic = Topic;
165
165
  Topic.LENGTH = 32;
166
+ const MAX_UINT64 = new Uint8Array(8).fill(0xff, 0, 8);
166
167
  class FeedIndex extends bytes_1.Bytes {
167
168
  constructor(bytes) {
168
169
  super(bytes, 8);
@@ -173,7 +174,13 @@ class FeedIndex extends bytes_1.Bytes {
173
174
  toBigInt() {
174
175
  return cafe_utility_1.Binary.uint64ToNumber(this.bytes, 'BE');
175
176
  }
177
+ next() {
178
+ if (cafe_utility_1.Binary.equals(this.bytes, MAX_UINT64)) {
179
+ return FeedIndex.fromBigInt(0n);
180
+ }
181
+ return FeedIndex.fromBigInt(this.toBigInt() + 1n);
182
+ }
176
183
  }
177
184
  exports.FeedIndex = FeedIndex;
178
185
  FeedIndex.LENGTH = 8;
179
- FeedIndex.MINUS_ONE = new FeedIndex(new Uint8Array(8).fill(0xff, 0, 8));
186
+ FeedIndex.MINUS_ONE = new FeedIndex(MAX_UINT64);