@upcoming/bee-js 11.1.0 → 12.0.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 +16 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +20 -1
- package/dist/types/bee.d.ts +12 -0
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/package.json +2 -2
package/dist/cjs/bee.js
CHANGED
|
@@ -1757,6 +1757,22 @@ class Bee {
|
|
|
1757
1757
|
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1758
1758
|
return (0, stamps_1.getStampCost)(batch.depth, amount);
|
|
1759
1759
|
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1762
|
+
*
|
|
1763
|
+
* @param postageBatchId
|
|
1764
|
+
* @param bzz The amount of BZZ to spend on the top-up.
|
|
1765
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1766
|
+
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
|
|
1767
|
+
*/
|
|
1768
|
+
async calculateTopUpForBzz(postageBatchId, bzz, requestOptions) {
|
|
1769
|
+
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1770
|
+
const chainState = await this.getChainState(requestOptions);
|
|
1771
|
+
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1772
|
+
const amount = bzz.toPLURBigInt() / 2n ** BigInt(batch.depth);
|
|
1773
|
+
const duration = (0, stamps_1.getStampDuration)(amount, chainState.currentPrice, blockTime);
|
|
1774
|
+
return { amount, duration };
|
|
1775
|
+
}
|
|
1760
1776
|
/**
|
|
1761
1777
|
* Increases the duration of a postage batch by increasing its amount.
|
|
1762
1778
|
*
|