diff --git a/CHANGELOG.md b/CHANGELOG.md index f714b39a..a9edf0ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.8.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.7.0...v2.8.0) (2024-02-08) + + +### Features + +* speed up manifest sync ([#490](https://www.github.com/ethersphere/swarm-cli/issues/490)) ([90fc2d0](https://www.github.com/ethersphere/swarm-cli/commit/90fc2d081e6152decb7b42676933154ff3c05de0)) +* upgrade to bee-js 6.7.2 ([#493](https://www.github.com/ethersphere/swarm-cli/issues/493)) ([ab3e13e](https://www.github.com/ethersphere/swarm-cli/commit/ab3e13e6442a503d38cf6980a3c6257c7accd066)) + ## [2.7.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.6.0...v2.7.0) (2023-11-29) diff --git a/package-lock.json b/package-lock.json index 96bef768..bb901359 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.7.0", + "version": "2.8.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.7.0", + "version": "2.8.0", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^6.7.0", + "@ethersphere/bee-js": "^6.7.3", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", @@ -1227,9 +1227,9 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.0.tgz", - "integrity": "sha512-t1bsUj9BmICuRL6XENTVyZZCfkFuCjc6pQxOekuVFLBd0Qpmyf87iRpVizvZN5IKhVqqw9xCzkg8otJKQdAKNA==", + "version": "6.7.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", + "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", @@ -10667,9 +10667,9 @@ } }, "@ethersphere/bee-js": { - "version": "6.7.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.0.tgz", - "integrity": "sha512-t1bsUj9BmICuRL6XENTVyZZCfkFuCjc6pQxOekuVFLBd0Qpmyf87iRpVizvZN5IKhVqqw9xCzkg8otJKQdAKNA==", + "version": "6.7.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", + "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", diff --git a/package.json b/package.json index ef49a806..a1d9591a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.7.0", + "version": "2.8.0", "description": "CLI tool for Bee", "keywords": [ "Bee", @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^6.7.0", + "@ethersphere/bee-js": "^6.7.3", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index 4c305aca..15bda9d3 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -46,14 +46,14 @@ export class Print extends FeedCommand implements LeafCommand { spinner.stop() this.console.verbose(createKeyValue('Chunk Reference', reference)) this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`)) - this.console.verbose(createKeyValue('Feed Index', feedIndex)) + this.console.verbose(createKeyValue('Feed Index', feedIndex as string)) this.console.verbose(createKeyValue('Next Index', feedIndexNext)) this.console.verbose(createKeyValue('Feed Manifest', manifest)) this.console.quiet(manifest) this.console.log(createKeyValue('Topic', `${topic}`)) this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`)) - this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex, 16) + 1)) + this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex as string, 16) + 1)) } catch (error) { spinner.stop() const message = getFieldOrNull(error, 'message') diff --git a/src/command/manifest/sync.ts b/src/command/manifest/sync.ts index 43f5e213..ce8241f4 100644 --- a/src/command/manifest/sync.ts +++ b/src/command/manifest/sync.ts @@ -1,3 +1,5 @@ +import { makeChunkedFile } from '@fairdatasociety/bmt-js' +import chalk from 'chalk' import { readFileSync } from 'fs' import { Argument, LeafCommand, Option } from 'furious-commander' import { Reference } from 'mantaray-js' @@ -5,6 +7,7 @@ import { join } from 'path' import { pickStamp } from '../../service/stamp' import { readdirDeepAsync } from '../../utils' import { BzzAddress } from '../../utils/bzz-address' +import { bytesToHex } from '../../utils/hex' import { stampProperties } from '../../utils/option' import { ManifestCommand } from './manifest-command' @@ -48,28 +51,30 @@ export class Sync extends ManifestCommand implements LeafCommand { continue } - const remoteData = await this.bee.downloadData(Buffer.from(fork.node.getEntry).toString('hex')) + const remoteAddress = Buffer.from(fork.node.getEntry).toString('hex') + const localData = readFileSync(join(this.folder, file)) + const rootChunk = makeChunkedFile(localData).rootChunk() + const localAddress = bytesToHex(rootChunk.address()) - // TODO make this more efficient once the chunker is available - if (localData.equals(remoteData)) { - this.console.log('ok -> ' + file) + if (localAddress === remoteAddress) { + this.console.log(chalk.gray(file) + ' ' + chalk.blue('UNCHANGED')) } else { - const { reference } = await this.bee.uploadData(this.stamp, readFileSync(join(this.folder, file))) + const { reference } = await this.bee.uploadData(this.stamp, localData) node.addFork(this.encodePath(file), Buffer.from(reference, 'hex') as Reference) - this.console.log('updated -> ' + file) + this.console.log(chalk.gray(file) + ' ' + chalk.yellow('CHANGED')) } } else { const { reference } = await this.bee.uploadData(this.stamp, readFileSync(join(this.folder, file))) node.addFork(this.encodePath(file), Buffer.from(reference, 'hex') as Reference) - this.console.log('new -> ' + file) + this.console.log(chalk.gray(file) + ' ' + chalk.green('NEW')) } } if (this.remove) { for (const fork of Object.values(forks).filter(x => !x.found)) { node.removePath(this.encodePath(fork.path)) - this.console.log('removed -> ' + fork.path) + this.console.log(chalk.gray(fork.path) + ' ' + chalk.red('REMOVED')) } } await this.saveAndPrintNode(node, this.stamp) diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index 35a3d6d7..5431ba9d 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -1,10 +1,9 @@ import { Utils } from '@ethersphere/bee-js' import { LeafCommand, Option } from 'furious-commander' -import { printStamp } from '../../service/stamp' -import { secondsToDhms, sleep } from '../../utils' +import { secondsToDhms } from '../../utils' import { createSpinner } from '../../utils/spinner' import { Storage } from '../../utils/storage' -import { createKeyValue, deletePreviousLine } from '../../utils/text' +import { createKeyValue } from '../../utils/text' import { VerbosityLevel } from '../root-command/command-log' import { StampCommand } from './stamp-command' @@ -96,7 +95,7 @@ export class Buy extends StampCommand implements LeafCommand { return } - const spinner = createSpinner('Buying postage stamp. This may take a few minutes.') + const spinner = createSpinner('Creating postage batch. This may take up to 5 minutes.') if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { spinner.start() @@ -107,6 +106,7 @@ export class Buy extends StampCommand implements LeafCommand { label: this.label, gasPrice: this.gasPrice?.toString(), immutableFlag: this.immutable, + waitForUsable: this.waitUsable === false ? false : true, }) spinner.stop() this.console.quiet(batchId) @@ -115,42 +115,5 @@ export class Buy extends StampCommand implements LeafCommand { } finally { spinner.stop() } - - if (this.waitUsable) { - await this.waitToBecomeUsable() - } - } - - private async waitToBecomeUsable(): Promise { - const spinner = createSpinner('Waiting for postage stamp to become usable...') - - if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { - spinner.start() - } - let running = true - - while (running) { - try { - const stamp = await this.beeDebug.getPostageBatch(this.postageBatchId) - - if (!stamp.usable) { - await sleep(1000) - continue - } - - spinner.stop() - - if (this.verbosity === VerbosityLevel.Verbose) { - if (!this.curl) { - deletePreviousLine() - } - printStamp(stamp, this.console, { showTtl: true }) - } - running = false - } catch { - await sleep(1000) - } - } - spinner.stop() } }