Skip to content

Commit 07b7b7e

Browse files
authored
feat: add rchash command (#613)
1 parent 429fa8c commit 07b7b7e

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

package-lock.json

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@ethereumjs/wallet": "^2.0.4",
66-
"@ethersphere/bee-js": "^9.2.0",
66+
"@ethersphere/bee-js": "^9.4.0",
6767
"cafe-utility": "^27.14.0",
6868
"chalk": "^2.4.2",
6969
"cli-progress": "^3.11.2",

src/command/utility/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Cid } from './cid'
77
import { CreateBatch } from './create-batch'
88
import { GetBee } from './get-bee'
99
import { Lock } from './lock'
10+
import { Rchash } from './rchash'
1011
import { Redeem } from './redeem'
1112
import { Unlock } from './unlock'
1213

@@ -15,7 +16,7 @@ export class Utility implements GroupCommand {
1516

1617
public readonly description = 'Utility commands related to Swarm and wallets'
1718

18-
public subCommandClasses = [Cid, Lock, Unlock, GetBee, Redeem, CreateBatch]
19+
public subCommandClasses = [Cid, Lock, Unlock, GetBee, Redeem, CreateBatch, Rchash]
1920
}
2021

2122
export async function createWallet(pathOrPrivateKey: string, console: CommandLog): Promise<Wallet> {

src/command/utility/rchash.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { System } from 'cafe-utility'
2+
import { LeafCommand } from 'furious-commander'
3+
import { createSpinner } from '../../utils/spinner'
4+
import { createKeyValue } from '../../utils/text'
5+
import { RootCommand } from '../root-command'
6+
7+
export class Rchash extends RootCommand implements LeafCommand {
8+
public readonly name = 'rchash'
9+
10+
public readonly description = 'Check reserve sampling duration'
11+
12+
public async run(): Promise<void> {
13+
super.init()
14+
const addresses = await this.bee.getNodeAddresses()
15+
const topology = await this.bee.getTopology()
16+
let stillRunning = true
17+
const promise = this.bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex())
18+
promise.finally(() => {
19+
stillRunning = false
20+
})
21+
const startedAt = Date.now()
22+
const spinner = createSpinner('Running rchash...').start()
23+
while (stillRunning) {
24+
await System.sleepMillis(1000)
25+
const duration = (Date.now() - startedAt) / 1000
26+
spinner.text = `Running rchash ${duration.toFixed()}s`
27+
}
28+
spinner.stop()
29+
const result = await promise
30+
this.console.log(createKeyValue('Reserve sampling duration', result + ' seconds'))
31+
}
32+
}

0 commit comments

Comments
 (0)