@upcoming/bee-js 9.9.0 → 9.9.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/bee.js +19 -15
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +19 -11
- package/package.json +1 -1
package/dist/mjs/bee.js
CHANGED
|
@@ -1217,24 +1217,28 @@ export class Bee {
|
|
|
1217
1217
|
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1218
1218
|
const chainState = await this.getChainState(options);
|
|
1219
1219
|
const depthDelta = depth - batch.depth;
|
|
1220
|
-
const multiplier = depthDelta
|
|
1221
|
-
const
|
|
1222
|
-
const
|
|
1223
|
-
const
|
|
1220
|
+
const multiplier = depthDelta <= 0 ? 1n : 2n ** BigInt(depthDelta);
|
|
1221
|
+
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1222
|
+
const additionalAmount = getAmountForDuration(duration, chainState.currentPrice, blockTime);
|
|
1223
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
|
|
1224
|
+
const targetAmount = duration.isZero() ? currentAmount * multiplier : currentAmount + additionalAmount * multiplier;
|
|
1225
|
+
const amountDelta = targetAmount - currentAmount;
|
|
1224
1226
|
const transactionId = await this.topUpBatch(batch.batchID, amountDelta, options);
|
|
1225
|
-
if (depthDelta) {
|
|
1227
|
+
if (depthDelta > 0) {
|
|
1226
1228
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1227
1229
|
}
|
|
1228
1230
|
return transactionId;
|
|
1229
1231
|
}
|
|
1230
1232
|
async extendStorageSize(postageBatchId, size, options, encryption, erasureCodeLevel) {
|
|
1233
|
+
const chainState = await this.getChainState(options);
|
|
1231
1234
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1232
1235
|
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1233
1236
|
const delta = depth - batch.depth;
|
|
1234
1237
|
if (delta <= 0) {
|
|
1235
1238
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1236
1239
|
}
|
|
1237
|
-
|
|
1240
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1241
|
+
await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, options);
|
|
1238
1242
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1239
1243
|
}
|
|
1240
1244
|
async extendStorageDuration(postageBatchId, duration, options) {
|
|
@@ -1246,21 +1250,25 @@ export class Bee {
|
|
|
1246
1250
|
async getExtensionCost(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
|
|
1247
1251
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1248
1252
|
const chainState = await this.getChainState(options);
|
|
1249
|
-
const
|
|
1253
|
+
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1254
|
+
const amount = duration.isZero() ? 0n : getAmountForDuration(duration, chainState.currentPrice, blockTime);
|
|
1250
1255
|
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1251
|
-
const
|
|
1252
|
-
const
|
|
1256
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
|
|
1257
|
+
const currentCost = getStampCost(batch.depth, currentAmount);
|
|
1258
|
+
const newCost = getStampCost(depth, currentAmount + amount);
|
|
1253
1259
|
return newCost.minus(currentCost);
|
|
1254
1260
|
}
|
|
1255
1261
|
async getSizeExtensionCost(postageBatchId, size, options, encryption, erasureCodeLevel) {
|
|
1256
1262
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1263
|
+
const chainState = await this.getChainState(options);
|
|
1257
1264
|
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1258
1265
|
const delta = depth - batch.depth;
|
|
1259
1266
|
if (delta <= 0) {
|
|
1260
1267
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1261
1268
|
}
|
|
1262
|
-
const
|
|
1263
|
-
const
|
|
1269
|
+
const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1270
|
+
const currentCost = getStampCost(batch.depth, currentAmount);
|
|
1271
|
+
const newCost = getStampCost(depth, currentAmount);
|
|
1264
1272
|
return newCost.minus(currentCost);
|
|
1265
1273
|
}
|
|
1266
1274
|
async getDurationExtensionCost(postageBatchId, duration, options) {
|