Skip to content

Commit 1b3eace

Browse files
authored
feat: add network option, require explicit block time (#998)
1 parent e327b50 commit 1b3eace

File tree

23 files changed

+58
-26
lines changed

23 files changed

+58
-26
lines changed

.github/workflows/check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ jobs:
3232
uses: wagoid/commitlint-github-action@v2
3333

3434
- name: Code linting
35-
run: npm run lint:check
35+
run: npm run lint
3636
env:
3737
CI: true
3838

3939
- name: Dependency check
4040
run: npm run depcheck
4141

4242
- name: Check typings
43-
run: npm run check:types
43+
run: npm run check
4444

4545
- name: Check build
4646
run: npm run build

jest.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default async (): Promise<Config.InitialOptions> => {
1010
Types.asString(process.env.JEST_BEE_FULL_URL, { name: 'JEST_BEE_FULL_URL' })
1111
Types.asString(process.env.JEST_BEE_LIGHT_URL, { name: 'JEST_BEE_LIGHT_URL' })
1212
Types.asString(process.env.JEST_BEE_ULTRA_LIGHT_URL, { name: 'JEST_BEE_ULTRA_LIGHT_URL' })
13-
Types.asString(process.env.JEST_BEE_SECRET, { name: 'JEST_BEE_SECRET' })
1413
Types.asHexString(process.env.JEST_FULL_BATCH_ID, { name: 'JEST_FULL_BATCH_ID', byteLength: 32 })
1514
Types.asHexString(process.env.JEST_LIGHT_BATCH_ID, { name: 'JEST_LIGHT_BATCH_ID', byteLength: 32 })
1615

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@
5656
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
5757
"build:browser": "webpack --progress",
5858
"test": "jest --config=jest.config.ts --runInBand --verbose",
59-
"check:types": "tsc --project tsconfig.test.json",
60-
"lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
61-
"lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
59+
"check": "tsc --project tsconfig.test.json",
60+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
6261
"depcheck": "depcheck ."
6362
},
6463
"dependencies": {

src/bee.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export class Bee {
149149
*/
150150
public readonly signer?: PrivateKey
151151

152+
/**
153+
* Network on which the Bee node is running
154+
*/
155+
public readonly network: 'gnosis' | 'sepolia'
156+
152157
/**
153158
* Options for making requests
154159
* @private
@@ -171,6 +176,8 @@ export class Bee {
171176
this.signer = new PrivateKey(options.signer)
172177
}
173178

179+
this.network = options?.network ?? 'gnosis'
180+
174181
this.requestOptions = {
175182
baseURL: this.url,
176183
timeout: options?.timeout ?? 0,
@@ -1035,6 +1042,7 @@ export class Bee {
10351042
const signer = new PrivateKey(Binary.numberToUint256(start + i, 'BE'))
10361043
const socAddress = makeSOCAddress(identifier, signer.publicKey().address())
10371044
const actualProximity = 256 - Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256)
1045+
10381046
if (actualProximity <= 256 - proximity) {
10391047
return signer
10401048
}
@@ -1637,7 +1645,7 @@ export class Bee {
16371645
requestOptions?: BeeRequestOptions,
16381646
): Promise<BatchId> {
16391647
const chainState = await this.getChainState(requestOptions)
1640-
const amount = getAmountForDuration(duration, chainState.currentPrice)
1648+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
16411649
const depth = getDepthForSize(size)
16421650

16431651
if (options) {
@@ -1649,7 +1657,7 @@ export class Bee {
16491657

16501658
async getStorageCost(size: Size, duration: Duration, options?: BeeRequestOptions): Promise<BZZ> {
16511659
const chainState = await this.getChainState(options)
1652-
const amount = getAmountForDuration(duration, chainState.currentPrice)
1660+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
16531661
const depth = getDepthForSize(size)
16541662

16551663
return getStampCost(depth, amount)
@@ -1676,7 +1684,7 @@ export class Bee {
16761684
) {
16771685
const batch = await this.getPostageBatch(postageBatchId, options)
16781686
const chainState = await this.getChainState(options)
1679-
const amount = getAmountForDuration(duration, chainState.currentPrice)
1687+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
16801688

16811689
return this.topUpBatch(batch.batchID, amount, options)
16821690
}
@@ -1689,7 +1697,7 @@ export class Bee {
16891697
): Promise<BZZ> {
16901698
const batch = await this.getPostageBatch(postageBatchId, options)
16911699
const chainState = await this.getChainState(options)
1692-
const amount = getAmountForDuration(duration, chainState.currentPrice)
1700+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
16931701
const depth = getDepthForSize(size)
16941702

16951703
const currentValue = getStampCost(batch.depth, batch.amount)
@@ -1713,6 +1721,7 @@ export class Bee {
17131721

17141722
const currentPaid = getStampCost(batch.depth, batch.amount)
17151723
const newPaid = getStampCost(depth, batch.amount)
1724+
17161725
return newPaid.minus(currentPaid)
17171726
}
17181727

@@ -1723,7 +1732,7 @@ export class Bee {
17231732
): Promise<BZZ> {
17241733
const batch = await this.getPostageBatch(postageBatchId, options)
17251734
const chainState = await this.getChainState(options)
1726-
const amount = getAmountForDuration(duration, chainState.currentPrice)
1735+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)
17271736

17281737
return getStampCost(batch.depth, amount)
17291738
}

src/feed/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export async function updateFeedWithPayload(
101101
if (data.length > 4096) {
102102
const uploadResult = await bytes.upload(requestOptions, data, postageBatchId, options)
103103
const rootChunk = await chunkAPI.download(requestOptions, uploadResult.reference)
104+
104105
return uploadSingleOwnerChunkWithWrappedChunk(
105106
requestOptions,
106107
signer,

src/manifest/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ export class MantarayNode {
248248
requestOptions?: BeeRequestOptions,
249249
): Promise<MantarayNode> {
250250
const data = (await bee.downloadData(reference, options, requestOptions)).toUint8Array()
251+
251252
return this.unmarshalFromData(data)
252253
}
253254

src/stamper/stamper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class Stamper {
3939
const address = chunk.hash()
4040
const bucket = Binary.uint16ToNumber(address, 'BE')
4141
const height = this.buckets[bucket]
42+
4243
if (height >= this.maxSlot) {
4344
throw Error('Bucket is full')
4445
}

src/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export interface BeeOptions extends BeeRequestOptions {
5555
* Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
5656
*/
5757
signer?: PrivateKey | Uint8Array | string
58+
/**
59+
* Default gnosis when unspecified.
60+
*/
61+
network?: 'gnosis' | 'sepolia'
5862
}
5963

6064
export interface GranteesResult {

src/utils/duration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export class Duration {
33

44
private constructor(seconds: number) {
55
this.seconds = Math.ceil(seconds)
6+
67
if (seconds <= 0) {
78
throw Error('Duration must be greater than 0')
89
}

src/utils/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export async function http<T>(options: BeeRequestOptions, config: AxiosRequestCo
2929
const keys = Object.keys(requestConfig.params)
3030
for (const key of keys) {
3131
const value = requestConfig.params[key]
32+
3233
if (value === undefined) {
3334
delete requestConfig.params[key]
3435
}

0 commit comments

Comments
 (0)