Skip to content

Commit 0ac68d4

Browse files
rolandlorCafe137
andauthored
feat: add erasure code and encryption parameters to storage methods (#1057)
* feat: adds erasure code handling and encryption handling * test: add expected argument in a test --------- Co-authored-by: Cafe137 <xcafe137@gmail.com>
1 parent 879de84 commit 0ac68d4

5 files changed

Lines changed: 374 additions & 24 deletions

File tree

src/bee.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import type {
6565
PssSubscription,
6666
Readiness,
6767
RedistributionState,
68+
RedundancyLevel,
6869
RedundantUploadOptions,
6970
ReferenceInformation,
7071
RemovePeerResponse,
@@ -1718,10 +1719,12 @@ export class Bee {
17181719
duration: Duration,
17191720
options?: PostageBatchOptions,
17201721
requestOptions?: BeeRequestOptions,
1722+
encryption?: boolean,
1723+
erasureCodeLevel?: RedundancyLevel,
17211724
): Promise<BatchId> {
17221725
const chainState = await this.getChainState(requestOptions)
17231726
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
1724-
const depth = getDepthForSize(size)
1727+
const depth = getDepthForSize(size, encryption, erasureCodeLevel)
17251728

17261729
if (options) {
17271730
options = preparePostageBatchOptions(options)
@@ -1730,17 +1733,29 @@ export class Bee {
17301733
return this.createPostageBatch(amount, depth, options, requestOptions)
17311734
}
17321735

1733-
async getStorageCost(size: Size, duration: Duration, options?: BeeRequestOptions): Promise<BZZ> {
1736+
async getStorageCost(
1737+
size: Size,
1738+
duration: Duration,
1739+
options?: BeeRequestOptions,
1740+
encryption?: boolean,
1741+
erasureCodeLevel?: RedundancyLevel,
1742+
): Promise<BZZ> {
17341743
const chainState = await this.getChainState(options)
17351744
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
1736-
const depth = getDepthForSize(size)
1745+
const depth = getDepthForSize(size, encryption, erasureCodeLevel)
17371746

17381747
return getStampCost(depth, amount)
17391748
}
17401749

1741-
async extendStorageSize(postageBatchId: BatchId | Uint8Array | string, size: Size, options?: BeeRequestOptions) {
1750+
async extendStorageSize(
1751+
postageBatchId: BatchId | Uint8Array | string,
1752+
size: Size,
1753+
options?: BeeRequestOptions,
1754+
encryption?: boolean,
1755+
erasureCodeLevel?: RedundancyLevel,
1756+
) {
17421757
const batch = await this.getPostageBatch(postageBatchId, options)
1743-
const depth = getDepthForSize(size)
1758+
const depth = getDepthForSize(size, encryption, erasureCodeLevel)
17441759
const delta = depth - batch.depth
17451760

17461761
if (delta <= 0) {
@@ -1769,11 +1784,13 @@ export class Bee {
17691784
size: Size,
17701785
duration: Duration,
17711786
options?: BeeRequestOptions,
1787+
encryption?: boolean,
1788+
erasureCodeLevel?: RedundancyLevel,
17721789
): Promise<BZZ> {
17731790
const batch = await this.getPostageBatch(postageBatchId, options)
17741791
const chainState = await this.getChainState(options)
17751792
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
1776-
const depth = getDepthForSize(size)
1793+
const depth = getDepthForSize(size, encryption, erasureCodeLevel)
17771794

17781795
const currentValue = getStampCost(batch.depth, batch.amount)
17791796
const newValue = getStampCost(depth, amount)
@@ -1785,9 +1802,11 @@ export class Bee {
17851802
postageBatchId: BatchId | Uint8Array | string,
17861803
size: Size,
17871804
options?: BeeRequestOptions,
1805+
encryption?: boolean,
1806+
erasureCodeLevel?: RedundancyLevel,
17881807
): Promise<BZZ> {
17891808
const batch = await this.getPostageBatch(postageBatchId, options)
1790-
const depth = getDepthForSize(size)
1809+
const depth = getDepthForSize(size, encryption, erasureCodeLevel)
17911810
const delta = depth - batch.depth
17921811

17931812
if (delta <= 0) {

0 commit comments

Comments
 (0)