Skip to content

Commit 4cf0441

Browse files
authored
feat: add stake command group (#623)
* feat: add stake command group * chore: lint * test(fix): adjust messages
1 parent 2b612d5 commit 4cf0441

File tree

22 files changed

+197
-49
lines changed

22 files changed

+197
-49
lines changed

src/command/grantee/create.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import fs from 'fs'
12
import { Argument, LeafCommand, Option } from 'furious-commander'
2-
import { GranteeCommand } from './grantee-command'
33
import { stampProperties } from '../../utils/option'
44
import { createKeyValue } from '../../utils/text'
5-
import fs from 'fs'
5+
import { GranteeCommand } from './grantee-command'
66

77
export class Create extends GranteeCommand implements LeafCommand {
88
public readonly name = 'create'
@@ -25,7 +25,7 @@ export class Create extends GranteeCommand implements LeafCommand {
2525
public stamp!: string
2626

2727
public async run(): Promise<void> {
28-
await super.init()
28+
super.init()
2929
this.actReqHeaders = {
3030
'Swarm-Act': 'true',
3131
}

src/command/grantee/get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Argument, LeafCommand } from 'furious-commander'
2-
import { GranteeCommand } from './grantee-command'
32
import { createKeyValue } from '../../utils/text'
3+
import { GranteeCommand } from './grantee-command'
44

55
export class Get extends GranteeCommand implements LeafCommand {
66
public readonly name = 'get'
@@ -15,7 +15,7 @@ export class Get extends GranteeCommand implements LeafCommand {
1515
public reference!: string
1616

1717
public async run(): Promise<void> {
18-
await super.init()
18+
super.init()
1919
const response = await this.bee.getGrantees(this.reference)
2020
this.console.log(
2121
createKeyValue('Grantee public keys', response.grantees.map(grantee => grantee.toCompressedHex()).join('\n')),

src/command/grantee/patch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import fs from 'fs'
12
import { Argument, LeafCommand, Option } from 'furious-commander'
2-
import { GranteeCommand } from './grantee-command'
33
import { stampProperties } from '../../utils/option'
44
import { createKeyValue } from '../../utils/text'
5-
import fs from 'fs'
5+
import { GranteeCommand } from './grantee-command'
66

77
export class Patch extends GranteeCommand implements LeafCommand {
88
public readonly name = 'patch'
@@ -43,7 +43,7 @@ export class Patch extends GranteeCommand implements LeafCommand {
4343
public history!: string
4444

4545
public async run(): Promise<void> {
46-
await super.init()
46+
super.init()
4747
this.actReqHeaders = {
4848
'Swarm-Act': 'true',
4949
'Swarm-Act-Timestamp': Date.now().toString(),

src/command/pinning/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class List extends PinningCommand implements LeafCommand {
1010
public readonly description = 'List pinned root hashes'
1111

1212
public async run(): Promise<void> {
13-
await super.init()
13+
super.init()
1414
this.console.info('Getting pinned root hashes...')
1515

1616
const pins = await this.bee.getAllPins()

src/command/pinning/unpin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Unpin extends PinningCommand implements LeafCommand {
1212
public address!: string
1313

1414
public async run(): Promise<void> {
15-
await super.init()
15+
super.init()
1616

1717
try {
1818
await this.bee.unpin(this.address)

src/command/pss/receive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Receive extends PssCommand implements LeafCommand {
2929
public receivedMessage?: string
3030

3131
public async run(): Promise<void> {
32-
await super.init()
32+
super.init()
3333

3434
this.console.log('Waiting for one PSS message on topic ' + this.topic)
3535

src/command/pss/send.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Send extends PssCommand implements LeafCommand {
4949
sendable?: string | Uint8Array
5050

5151
public async run(): Promise<void> {
52-
await super.init()
52+
super.init()
5353

5454
if (this.path) {
5555
if (!fileExists(this.path)) {

src/command/pss/subscribe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export class Subscribe extends PssCommand implements LeafCommand {
1515
})
1616
public outFile!: string
1717

18-
public async run(): Promise<void> {
19-
await super.init()
18+
public run(): void {
19+
super.init()
2020

2121
this.console.log('Subscribing for PSS messages on topic ' + this.topic)
2222

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import { BZZ } from '@ethersphere/bee-js'
22
import { LeafCommand, Option } from 'furious-commander'
3-
import { createSpinner } from '../utils/spinner'
4-
import { createKeyValue } from '../utils/text'
5-
import { RootCommand } from './root-command'
6-
import { VerbosityLevel } from './root-command/command-log'
3+
import { createSpinner } from '../../utils/spinner'
4+
import { RootCommand } from '../root-command'
5+
import { VerbosityLevel } from '../root-command/command-log'
76

87
const MIN_DEPOSIT = BZZ.fromDecimalString('10')
98

10-
export class Stake extends RootCommand implements LeafCommand {
11-
public readonly name = 'stake'
9+
export class Deposit extends RootCommand implements LeafCommand {
10+
public readonly name = 'deposit'
1211

13-
public readonly description = `Manages nodes stake`
12+
public readonly description = 'Stake xBZZ for the storage incentives'
1413

1514
@Option({
16-
key: 'deposit',
15+
key: 'plur',
1716
description: "Amount of PLUR to add to the node's stake",
1817
type: 'bigint',
1918
minimum: BigInt(1),
19+
conflicts: 'bzz',
2020
})
2121
public amountPlur!: bigint | undefined
2222

2323
@Option({
24-
key: 'deposit-bzz',
24+
key: 'bzz',
2525
description: "Amount of BZZ to add to the node's stake",
2626
type: 'string',
27+
conflicts: 'plur',
2728
})
2829
public amountBzz!: string | undefined
2930

@@ -36,10 +37,10 @@ export class Stake extends RootCommand implements LeafCommand {
3637
await this.deposit(BZZ.fromDecimalString(this.amountBzz))
3738
}
3839

39-
const stake = await this.bee.getStake()
40-
41-
this.console.log(createKeyValue('Staked xBZZ', stake.toDecimalString()))
42-
this.console.quiet(stake.toDecimalString())
40+
this.console.log('Stake deposited successfully!')
41+
this.console.log('Run `swarm-cli stake status` to check your stake status.')
42+
this.console.log('')
43+
this.console.log('Do note it may take a few minutes for the stake to be reflected in the node status.')
4344
}
4445

4546
private async deposit(amount: BZZ): Promise<void> {
@@ -86,10 +87,6 @@ export class Stake extends RootCommand implements LeafCommand {
8687
try {
8788
await this.bee.depositStake(amount)
8889
spinner.stop()
89-
90-
this.console.log(
91-
'Successfully staked! It may take a few minutes for the stake to be reflected in the node status.',
92-
)
9390
} catch (e) {
9491
spinner.stop()
9592
throw e

src/command/stake/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { GroupCommand } from 'furious-commander'
2+
import { Deposit } from './deposit'
3+
import { Recover } from './recover'
4+
import { Status } from './status'
5+
import { Withdraw } from './withdraw'
6+
7+
export class Stake implements GroupCommand {
8+
public readonly name = 'stake'
9+
10+
public readonly description = 'Manages node stake'
11+
12+
public subCommandClasses = [Status, Deposit, Withdraw, Recover]
13+
}

0 commit comments

Comments
 (0)