File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { BatchId, Utils } from '@ethersphere/bee-js'
22import { Dates , Numbers } from 'cafe-utility'
33import { BigNumber } from 'ethers'
44import { LeafCommand , Option } from 'furious-commander'
5+ import { isChainStateReady } from '../../utils/chainsync'
56import { createSpinner } from '../../utils/spinner'
67import { createKeyValue } from '../../utils/text'
78import { VerbosityLevel } from '../root-command/command-log'
@@ -59,6 +60,14 @@ export class Buy extends StampCommand implements LeafCommand {
5960 public async run ( ) : Promise < void > {
6061 super . init ( )
6162
63+ if ( ! ( await isChainStateReady ( this . bee ) ) ) {
64+ this . console . error ( 'Synchronization with the blockchain is not yet complete.' )
65+ this . console . error ( 'Please wait until the Bee is fully synced before buying a postage stamp.' )
66+ this . console . error ( 'You can check the synchronization status with the "status" command.' )
67+
68+ return
69+ }
70+
6271 const chainState = await this . bee . getChainState ( )
6372 const minimumAmount = BigNumber . from ( chainState . currentPrice ) . mul ( 17280 )
6473
Original file line number Diff line number Diff line change 11import { BatchId , Duration , Size } from '@ethersphere/bee-js'
22import { Dates , Numbers } from 'cafe-utility'
33import { LeafCommand , Option } from 'furious-commander'
4+ import { isChainStateReady } from '../../utils/chainsync'
45import { createSpinner } from '../../utils/spinner'
56import { createKeyValue } from '../../utils/text'
67import { VerbosityLevel } from '../root-command/command-log'
@@ -43,6 +44,14 @@ export class Create extends StampCommand implements LeafCommand {
4344 public async run ( ) : Promise < void > {
4445 super . init ( )
4546
47+ if ( ! ( await isChainStateReady ( this . bee ) ) ) {
48+ this . console . error ( 'Synchronization with the blockchain is not yet complete.' )
49+ this . console . error ( 'Please wait until the Bee is fully synced before buying a postage stamp.' )
50+ this . console . error ( 'You can check the synchronization status with the "status" command.' )
51+
52+ return
53+ }
54+
4655 if ( ! this . capacity ) {
4756 this . console . log ( 'Please provide the total capacity of the postage stamp batch' )
4857 this . console . log ( 'This represents the total size of data that can be uploaded' )
Original file line number Diff line number Diff line change 1+ import { Bee } from '@ethersphere/bee-js'
2+
3+ const THRESHOLD = 10_000
4+
5+ export async function isChainStateReady ( bee : Bee ) : Promise < boolean > {
6+ const chainState = await bee . getChainState ( )
7+
8+ return chainState . chainTip > chainState . block - THRESHOLD
9+ }
You can’t perform that action at this time.
0 commit comments