Skip to content

Commit

Permalink
fix: handle missing chequebook in addresses command (#534)
Browse files Browse the repository at this point in the history
* fix: handle missing chequebook in addresses command

* style: add newline
  • Loading branch information
Cafe137 authored Sep 16, 2024
1 parent e8b1842 commit 05cb0ed
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/command/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NodeAddresses } from '@ethersphere/bee-js'
import { ChequebookAddressResponse, NodeAddresses } from '@ethersphere/bee-js'
import { Optional } from 'cafe-utility'
import chalk from 'chalk'
import { LeafCommand } from 'furious-commander'
import { createKeyValue } from '../utils/text'
Expand All @@ -11,13 +12,23 @@ export class Addresses extends RootCommand implements LeafCommand {

public nodeAddresses!: NodeAddresses

public chequebookAddress!: string

public async run(): Promise<void> {
await super.init()

this.nodeAddresses = await this.bee.getNodeAddresses()
this.chequebookAddress = (await this.bee.getChequebookAddress()).chequebookAddress
const wrappedChequebookAddress = await this.bee
.getChequebookAddress()
.then(x => {
return Optional.of(x)
})
.catch(() => {
this.console.error('Could not fetch chequebook address')
this.console.error('This is expected if chequebook-enable: false is set in the configuration')
this.console.error('or when the Bee node is still syncing with the blockchain')
this.console.log('')

return Optional.empty<ChequebookAddressResponse>()
})

const longest = 'PSS Public Key'.length
this.console.log(chalk.bold('Node Addresses'))
Expand All @@ -27,16 +38,21 @@ export class Addresses extends RootCommand implements LeafCommand {
this.console.log(createKeyValue('PSS Public Key', this.nodeAddresses.pssPublicKey, longest))
this.console.log(createKeyValue('Public Key', this.nodeAddresses.publicKey, longest))
this.console.log(createKeyValue('Underlay', this.nodeAddresses.underlay.join(' '), longest))
this.console.log('')
this.console.log(chalk.bold('Chequebook Address'))
this.console.divider()
this.console.log(this.chequebookAddress)

wrappedChequebookAddress.ifPresent(chequebookAddress => {
this.console.log('')
this.console.log(chalk.bold('Chequebook Address'))
this.console.divider()
this.console.log(chequebookAddress.chequebookAddress)
})

this.console.quiet('Ethereum ' + this.nodeAddresses.ethereum)
this.console.quiet('Overlay ' + this.nodeAddresses.overlay)
this.console.quiet('PSS_Public_Key ' + this.nodeAddresses.pssPublicKey)
this.console.quiet('Public_Key ' + this.nodeAddresses.publicKey)
this.console.quiet('Underlay ' + this.nodeAddresses.underlay)
this.console.quiet('Chequebook ' + this.chequebookAddress)
wrappedChequebookAddress.ifPresent(chequebookAddress => {
this.console.quiet('Chequebook ' + chequebookAddress.chequebookAddress)
})
}
}

0 comments on commit 05cb0ed

Please sign in to comment.