From 045275982ecba9caa07c9d3e2ac8d231a0711420 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:26:42 -0700 Subject: [PATCH 01/26] feat: add redundancy options (#487) * feat: add redundancy options * chore: bump bee-js version --- package-lock.json | 84 +++++++++++++++++++++++++++---------------- package.json | 2 +- src/command/upload.ts | 61 ++++++++++++++++++++++++++++++- 3 files changed, 115 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index bb901359..6076e255 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.8.0", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^6.7.3", + "@ethersphere/bee-js": "^6.9.0", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", @@ -1227,14 +1227,14 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", - "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.9.0.tgz", + "integrity": "sha512-TW7F8V6/Ha0oW1mh5ChFN0DDJHEHYTewCj/phg+CwjKIxagnrGVs52B2DLJKQLf4RnqNHY1MXSBXqAc5FnMwKQ==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", - "axios": "^0.27.2", - "cafe-utility": "^10.8.1", + "axios": "^0.28.0", + "cafe-utility": "^15.0.2", "elliptic": "^6.5.4", "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", @@ -1245,13 +1245,18 @@ "ws": "^8.7.0" }, "engines": { - "bee": "1.13.0-f1067884", + "bee": "1.18.2-759f56f", "beeApiVersion": "4.0.0", "beeDebugApiVersion": "4.0.0", "node": ">=14.0.0", "npm": ">=6.0.0" } }, + "node_modules/@ethersphere/bee-js/node_modules/cafe-utility": { + "version": "15.0.2", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-15.0.2.tgz", + "integrity": "sha512-TNKSfA/q/XRd86NwYtF5QImQB8U5n/hKZuWblYFgYW4aveHcSg2RGOfR3+xquXRXF7BCeNoAXe2/snWFKviPzw==" + }, "node_modules/@ethersphere/bee-js/node_modules/web-streams-polyfill": { "version": "4.0.0-beta.3", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", @@ -2747,12 +2752,13 @@ } }, "node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.0.tgz", + "integrity": "sha512-Tu7NYoGY4Yoc7I+Npf9HhUMtEEpV7ZiLH9yndTCoNhcpBH0kwcvFbzYN9/u5QKI5A6uefjsNNWaz5olJVYS62Q==", "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/babel-jest": { @@ -3153,7 +3159,8 @@ "node_modules/cafe-utility": { "version": "10.8.1", "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-10.8.1.tgz", - "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==" + "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==", + "dev": true }, "node_modules/callsites": { "version": "3.1.0", @@ -4498,9 +4505,9 @@ "dev": true }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", @@ -8314,6 +8321,11 @@ "node": ">= 6" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", @@ -10667,14 +10679,14 @@ } }, "@ethersphere/bee-js": { - "version": "6.7.3", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.7.3.tgz", - "integrity": "sha512-04AXGXP148DousgjVInyGUlHZnWwTGIgiH5leCACJ6daAUnnJQm7CjQgXIH5y72gGPX1XyzXDlqBlB8zLkihkQ==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.9.0.tgz", + "integrity": "sha512-TW7F8V6/Ha0oW1mh5ChFN0DDJHEHYTewCj/phg+CwjKIxagnrGVs52B2DLJKQLf4RnqNHY1MXSBXqAc5FnMwKQ==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "@types/readable-stream": "^2.3.13", - "axios": "^0.27.2", - "cafe-utility": "^10.8.1", + "axios": "^0.28.0", + "cafe-utility": "^15.0.2", "elliptic": "^6.5.4", "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", @@ -10685,6 +10697,11 @@ "ws": "^8.7.0" }, "dependencies": { + "cafe-utility": { + "version": "15.0.2", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-15.0.2.tgz", + "integrity": "sha512-TNKSfA/q/XRd86NwYtF5QImQB8U5n/hKZuWblYFgYW4aveHcSg2RGOfR3+xquXRXF7BCeNoAXe2/snWFKviPzw==" + }, "web-streams-polyfill": { "version": "4.0.0-beta.3", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", @@ -11837,12 +11854,13 @@ "dev": true }, "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.0.tgz", + "integrity": "sha512-Tu7NYoGY4Yoc7I+Npf9HhUMtEEpV7ZiLH9yndTCoNhcpBH0kwcvFbzYN9/u5QKI5A6uefjsNNWaz5olJVYS62Q==", "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "babel-jest": { @@ -12143,7 +12161,8 @@ "cafe-utility": { "version": "10.8.1", "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-10.8.1.tgz", - "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==" + "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==", + "dev": true }, "callsites": { "version": "3.1.0", @@ -13154,9 +13173,9 @@ "dev": true }, "follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==" + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==" }, "form-data": { "version": "4.0.0", @@ -15919,6 +15938,11 @@ "sisteransi": "^1.0.5" } }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", diff --git a/package.json b/package.json index a1d9591a..4ad3420f 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^6.7.3", + "@ethersphere/bee-js": "^6.9.0", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", diff --git a/src/command/upload.ts b/src/command/upload.ts index b106eb66..4805213d 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -1,4 +1,4 @@ -import { Tag, Utils } from '@ethersphere/bee-js' +import { RedundancyLevel, Tag, Utils } from '@ethersphere/bee-js' import { Presets, SingleBar } from 'cli-progress' import * as FS from 'fs' import { Argument, LeafCommand, Option } from 'furious-commander' @@ -104,6 +104,12 @@ export class Upload extends RootCommand implements LeafCommand { }) public contentType!: string + @Option({ + key: 'redundancy', + description: 'Redundancy of the upload (MEDIUM, STRONG, INSANE, PARANOID)', + }) + public redundancy!: string + // CLASS FIELDS public hash!: string @@ -140,6 +146,7 @@ export class Upload extends RootCommand implements LeafCommand { } await this.maybeRunSizeChecks() + await this.maybePrintRedundancyStats() const tag = this.sync ? await this.bee.createTag() : undefined @@ -211,6 +218,7 @@ export class Upload extends RootCommand implements LeafCommand { encrypt: this.encrypt, contentType, deferred: this.deferred, + redundancyLevel: this.determineRedundancyLevel(), }) this.hash = reference @@ -219,6 +227,8 @@ export class Upload extends RootCommand implements LeafCommand { const { reference } = await this.bee.uploadData(this.stamp, this.stdinData, { tag: tag?.uid, deferred: this.deferred, + encrypt: this.encrypt, + redundancyLevel: this.determineRedundancyLevel(), }) this.hash = reference @@ -239,6 +249,7 @@ export class Upload extends RootCommand implements LeafCommand { pin: this.pin, encrypt: this.encrypt, deferred: this.deferred, + redundancyLevel: this.determineRedundancyLevel(), }) this.hash = reference @@ -260,6 +271,7 @@ export class Upload extends RootCommand implements LeafCommand { encrypt: this.encrypt, contentType, deferred: this.deferred, + redundancyLevel: this.determineRedundancyLevel(), }) this.hash = reference @@ -340,6 +352,35 @@ export class Upload extends RootCommand implements LeafCommand { } } + private async maybePrintRedundancyStats(): Promise { + if (!this.redundancy || this.quiet) { + return + } + + const currentSetting = Utils.getRedundancyStat(this.redundancy) + const originalSize = await this.getUploadSize() + const originalChunks = Math.ceil(originalSize.getBytes() / 4e3) + const sizeMultiplier = Utils.approximateOverheadForRedundancyLevel( + originalChunks, + currentSetting.value, + this.encrypt, + ) + const newSize = new Storage(originalChunks * 4e3 * (1 + sizeMultiplier)) + const extraSize = new Storage(newSize.getBytes() - originalSize.getBytes()) + + this.console.log(createKeyValue('Redundancy setting', currentSetting.label)) + this.console.log(`This setting will provide ${Math.round(currentSetting.errorTolerance * 100)}% error tolerance.`) + this.console.log(`An additional ${extraSize.toString()} of data will be uploaded approximately.`) + this.console.log(`${originalSize.toString()} → ${newSize.toString()} (+${extraSize.toString()})`) + if (!this.yes && !this.quiet) { + const confirmation = await this.console.confirm('Do you want to proceed?') + + if (!confirmation) { + exit(0) + } + } + } + private async getUploadSize(): Promise { let size = -1 @@ -424,4 +465,22 @@ export class Upload extends RootCommand implements LeafCommand { return defaultName } + + private determineRedundancyLevel(): RedundancyLevel | undefined { + if (!this.redundancy) { + return undefined + } + switch (this.redundancy.toUpperCase()) { + case 'MEDIUM': + return RedundancyLevel.MEDIUM + case 'STRONG': + return RedundancyLevel.STRONG + case 'INSANE': + return RedundancyLevel.INSANE + case 'PARANOID': + return RedundancyLevel.PARANOID + default: + throw new CommandLineError(`Invalid redundancy level: ${this.redundancy}`) + } + } } From ca86f010be9f4a6eb9cacd86b1aa4eac76a6bafb Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:34:16 +0200 Subject: [PATCH 02/26] chore: release 2.9.0 (#496) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9edf0ab..dd482b31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.9.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.8.0...v2.9.0) (2024-04-15) + + +### Features + +* add redundancy options ([#487](https://www.github.com/ethersphere/swarm-cli/issues/487)) ([0452759](https://www.github.com/ethersphere/swarm-cli/commit/045275982ecba9caa07c9d3e2ac8d231a0711420)) + ## [2.8.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.7.0...v2.8.0) (2024-02-08) diff --git a/package-lock.json b/package-lock.json index 6076e255..38376b7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.8.0", + "version": "2.9.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.8.0", + "version": "2.9.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^6.9.0", diff --git a/package.json b/package.json index 4ad3420f..f5fb2cae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.8.0", + "version": "2.9.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From 0106e4de697dfe97dfcae42eff8d2c74755df410 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:40:24 -0700 Subject: [PATCH 03/26] feat: merge api (#503) --- .github/workflows/ci.yaml | 2 - README.md | 171 +++++++++++++-------- jest.config.ts | 2 +- package-lock.json | 84 ++++------ package.json | 2 +- src/command/addresses.ts | 4 +- src/command/cheque/cashout.ts | 2 +- src/command/cheque/cheque-command.ts | 4 +- src/command/cheque/deposit.ts | 2 +- src/command/cheque/withdraw.ts | 2 +- src/command/feed/feed-command.ts | 4 +- src/command/feed/print.ts | 2 +- src/command/feed/update.ts | 2 +- src/command/feed/upload.ts | 2 +- src/command/manifest/add.ts | 2 +- src/command/manifest/create.ts | 2 +- src/command/manifest/merge.ts | 2 +- src/command/manifest/remove.ts | 2 +- src/command/manifest/sync.ts | 2 +- src/command/pss/send.ts | 2 +- src/command/root-command/command-config.ts | 10 +- src/command/root-command/index.ts | 52 +------ src/command/stake.ts | 10 +- src/command/stamp/buy.ts | 2 +- src/command/stamp/dilute.ts | 6 +- src/command/stamp/list.ts | 2 +- src/command/stamp/show.ts | 4 +- src/command/stamp/stamp-command.ts | 2 +- src/command/stamp/topup.ts | 4 +- src/command/status.ts | 21 +-- src/command/upload.ts | 11 +- src/command/utility/unlock.ts | 1 - src/config.ts | 8 - src/service/stamp/index.ts | 6 +- test/command/cheque.spec.ts | 22 +-- test/command/stamp.spec.ts | 2 +- test/command/status.spec.ts | 12 +- test/misc/config.spec.ts | 52 ------- test/misc/monetary-units.spec.ts | 6 +- test/misc/unavailable-bee-debug.spec.ts | 34 ---- test/misc/unsure-bee-debug.spec.ts | 31 ---- test/utility/address.ts | 4 +- test/utility/stamp.ts | 11 +- 43 files changed, 212 insertions(+), 398 deletions(-) delete mode 100644 test/misc/config.spec.ts delete mode 100644 test/misc/unavailable-bee-debug.spec.ts delete mode 100644 test/misc/unsure-bee-debug.spec.ts diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9398d7be..5d69e5d5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,8 +11,6 @@ on: env: BEE_API_URL: 'http://localhost:1633' BEE_PEER_API_URL: 'http://localhost:11633' - BEE_DEBUG_API_URL: 'http://localhost:1635' - BEE_PEER_DEBUG_API_URL: 'http://localhost:11635' jobs: node-tests: diff --git a/README.md b/README.md index 60b0ea59..151103a1 100644 --- a/README.md +++ b/README.md @@ -7,43 +7,44 @@ ![](https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square) ![](https://img.shields.io/badge/Node.js-%3E%3D12.0.0-orange.svg?style=flat-square) -Stay up to date with changes by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/swarm-cli/releases). +Stay up to date with changes by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on +the [releases tab](https://github.com/ethersphere/swarm-cli/releases). # Table of Contents - [Swarm-CLI](#swarm-cli) - [Table of Contents](#table-of-contents) - [Demo](#demo) - * [Purchasing a Postage Stamp](#purchasing-a-postage-stamp) - * [Uploading a File](#uploading-a-file) - * [Creating an Identity](#creating-an-identity) - * [Uploading to a Feed](#uploading-to-a-feed) + - [Purchasing a Postage Stamp](#purchasing-a-postage-stamp) + - [Uploading a File](#uploading-a-file) + - [Creating an Identity](#creating-an-identity) + - [Uploading to a Feed](#uploading-to-a-feed) - [Description](#description) - * [Installation](#installation) - + [From npm](#from-npm) - + [From source](#from-source) - * [Usage](#usage) - * [Commands](#commands) - * [Example usage](#example-usage) - * [Usability Features](#usability-features) - + [Uploading Files, Folders, Websites, and Arbitrary Data from stdin](#uploading-files--folders--websites--and-arbitrary-data-from-stdin) + - [Installation](#installation) + - [From npm](#from-npm) + - [From source](#from-source) + - [Usage](#usage) + - [Commands](#commands) + - [Example usage](#example-usage) + - [Usability Features](#usability-features) + - [Uploading Files, Folders, Websites, and Arbitrary Data from stdin](#uploading-files--folders--websites--and-arbitrary-data-from-stdin) - [Files](#files) - [Folders and Websites](#folders-and-websites) - [Standard Input](#standard-input) - + [Custom HTTP Headers](#custom-http-headers) - + [Autocomplete](#autocomplete) - + [Numerical Separator and Units](#numerical-separator-and-units) - + [Stamp Picker](#stamp-picker) - + [Identity Picker](#identity-picker) - + [Human Readable Topics](#human-readable-topics) - + [Manifest address scheme](#manifest-address-scheme) - + [Automating tasks with Swarm-CLI](#automating-tasks-with-swarm-cli) + - [Custom HTTP Headers](#custom-http-headers) + - [Autocomplete](#autocomplete) + - [Numerical Separator and Units](#numerical-separator-and-units) + - [Stamp Picker](#stamp-picker) + - [Identity Picker](#identity-picker) + - [Human Readable Topics](#human-readable-topics) + - [Manifest address scheme](#manifest-address-scheme) + - [Automating tasks with Swarm-CLI](#automating-tasks-with-swarm-cli) - [Connectivity](#connectivity) - [Postage Stamps](#postage-stamps) - [Uploading](#uploading) - * [Config](#config) - * [Assignment priority](#assignment-priority) - * [System environment](#system-environment) + - [Config](#config) + - [Assignment priority](#assignment-priority) + - [System environment](#system-environment) - [Development](#development) - [Contribute](#contribute) - [Maintainers](#maintainers) @@ -140,25 +141,40 @@ Run 'swarm-cli COMMAND --help' for more information on a command ## Example usage -Let's say we want to upload our website to Swarm and update a feed to point to the newest version. For updating a feed we would need to sign it with an Ethereum key, so first we need to create one with the `identity create` command: +Let's say we want to upload our website to Swarm and update a feed to point to the newest version. For updating a feed +we would need to sign it with an Ethereum key, so first we need to create one with the `identity create` command: ``` swarm-cli identity create ``` -This command will ask for a password. After that a new identity is created (named `main`). Now we can use this identity to sign updates. It's also possible to import and export Ethereum JSON V3 format identities that works with other apps (e.g. wallets). +This command will ask for a password. After that a new identity is created (named `main`). Now we can use this identity +to sign updates. It's also possible to import and export Ethereum JSON V3 format identities that works with other apps +(e.g. wallets). -Another requirement for uploading to the Swarm network is a valid postage batch, also called a postage stamp or simply a stamp. Stamps need to be purchased with BZZ tokens. We can use the `stamp buy` command to take care of this step. The `--amount` and `--depth` options alter the capacity of the postage stamp. For example, running `stamp buy --amount 1 --depth 20` will get back with a Stamp ID after a while. We will be using that with the `--stamp` option in commands which upload files, or write feeds. +Another requirement for uploading to the Swarm network is a valid postage batch, also called a postage stamp or simply a +stamp. Stamps need to be purchased with BZZ tokens. We can use the `stamp buy` command to take care of this step. The +`--amount` and `--depth` options alter the capacity of the postage stamp. For example, running +`stamp buy --amount 1 --depth 20` will get back with a Stamp ID after a while. We will be using that with the `--stamp` +option in commands which upload files, or write feeds. -For uploading to a feed we can use the `feed upload` command. It expects the path of the folder (or file) we want to upload and as options it expects `identity` to be provided along with the `password` that belongs to it, as well as the earlier mentioned `stamp`. +For uploading to a feed we can use the `feed upload` command. It expects the path of the folder (or file) we want to +upload and as options it expects `identity` to be provided along with the `password` that belongs to it, as well as the +earlier mentioned `stamp`. ``` swarm-cli feed upload path-to-be-uploaded --identity my-identity --password my-secret-password --stamp stamp-id ``` -In this example we are uploading the content of the `dist` folder. If the uploading was successful the last printed line will contain a `Feed Manifest URL`. This URL can be opened in the browser. If the uploaded folder contains an `index.html` file then it will be automatically displayed when visiting the URL. +In this example we are uploading the content of the `dist` folder. If the uploading was successful the last printed line +will contain a `Feed Manifest URL`. This URL can be opened in the browser. If the uploaded folder contains an +`index.html` file then it will be automatically displayed when visiting the URL. -This URL will stay the same when we upload an updated version of the website. Because of this we can also put this URL into a reverse proxy configuration or use the reference (the hex string after the `/bzz/`) in an ENS record. There is more information about that in the [Bee documentation](https://docs.ethswarm.org/docs/getting-started/host-your-website-using-ens). The uploaded content can be found on the link in the line starting with `URL`. This will change every time the content is modified. +This URL will stay the same when we upload an updated version of the website. Because of this we can also put this URL +into a reverse proxy configuration or use the reference (the hex string after the `/bzz/`) in an ENS record. There is +more information about that in the +[Bee documentation](https://docs.ethswarm.org/docs/getting-started/host-your-website-using-ens). The uploaded content +can be found on the link in the line starting with `URL`. This will change every time the content is modified. ## Usability Features @@ -172,7 +188,8 @@ Use `swarm-cli` to upload a single file: swarm-cli upload README.md ``` -The command above will print a `/bzz` URL that may be opened in the browser. If the browser is able to handle the file format then the file is displayed, otherwise it will be offered to be downloaded. +The command above will print a `/bzz` URL that may be opened in the browser. If the browser is able to handle the file +format then the file is displayed, otherwise it will be offered to be downloaded. #### Folders and Websites @@ -182,7 +199,9 @@ The command above will print a `/bzz` URL that may be opened in the browser. If swarm-cli upload build/ ``` -This also yields a `/bzz` URL. If there is an `index.html` present in the root of the folder, `--index-document` will be automatically applied by `swarm-cli`. This option sets which file the browser should open for an empty path. You may also freely set `--index-document` during upload to change this. +This also yields a `/bzz` URL. If there is an `index.html` present in the root of the folder, `--index-document` will be +automatically applied by `swarm-cli`. This option sets which file the browser should open for an empty path. You may +also freely set `--index-document` during upload to change this. #### Standard Input @@ -192,7 +211,10 @@ You can pipe data from other commands to `swarm-cli` using the `--stdin` option. curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] ``` -Unlike other upload methods, this results in a `/bytes` URL, which cannot be displayed by browsers normally. You can still share your hash and others can download it. However, with the `--name` option, you can give your arbitrary data a file name, and `swarm-cli` will attempt to determine the suitable content type for your data. Given it is successful, `swarm-cli` will print a `/bzz` URL instead of the `/bytes` URL, which is good to be displayed in browsers. Example: +Unlike other upload methods, this results in a `/bytes` URL, which cannot be displayed by browsers normally. You can +still share your hash and others can download it. However, with the `--name` option, you can give your arbitrary data a +file name, and `swarm-cli` will attempt to determine the suitable content type for your data. Given it is successful, +`swarm-cli` will print a `/bzz` URL instead of the `/bytes` URL, which is good to be displayed in browsers. Example: ``` curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random.jpg @@ -204,7 +226,9 @@ There is also a `--content-type` option if you want to adjust it manually: curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp [...] --name random --content-type image/jpeg ``` -Please note that stdin is reserved for the data you are uploading, so interactive features are disabled during this time. Because of that, `--stamp` must be passed beforehand. You may create an alias for grabbing the ID of the least used postage stamp: +Please note that stdin is reserved for the data you are uploading, so interactive features are disabled during this +time. Because of that, `--stamp` must be passed beforehand. You may create an alias for grabbing the ID of the least +used postage stamp: ``` alias st='swarm-cli stamp list --least-used --limit 1 --hide-usage --quiet' @@ -216,9 +240,10 @@ Leveraging the alias above, you can use a shortcut for uploading from stdin: curl -L https://picsum.photos/200 | swarm-cli --stdin --stamp $(st) ``` -### Custom HTTP Headers +### Custom HTTP Headers -Similarly to `curl`, you may use the `--header` or `-H` option to specify as many additional headers as you want, which will be sent with all requests: +Similarly to `curl`, you may use the `--header` or `-H` option to specify as many additional headers as you want, which +will be sent with all requests: ``` swarm-cli upload README.md -H "Authorization: [...]" -H "X-Custom-Header: Your Value" @@ -226,19 +251,24 @@ swarm-cli upload README.md -H "Authorization: [...]" -H "X-Custom-Header: Your V ### Autocomplete -`swarm-cli` has support for autocomplete in `bash`, `zsh` and `fish`. This turns on `` suggestions which can complete commands, paths and options for you. +`swarm-cli` has support for autocomplete in `bash`, `zsh` and `fish`. This turns on `` suggestions which can +complete commands, paths and options for you. To enable it, you need to install it once via two options: - - Running `swarm-cli --generate-completion` and following the instructions there - - Running `swarm-cli --install-completion` which automatically appends the completion script to your configuration file -| Shell | Completion System | Configuration Path | -|---------|---------------------------------------------------|------------------------------------------| -| `bash` | `compdef` & `compadd` OR `complete` & `COMPREPLY` | `$HOME/.bashrc` & `$HOME/.bash_profile` | -| `zsh` | `compdef` & `compadd` OR `complete` & `COMPREPLY` | `$HOME/.zshrc` | -| `fish` | `complete` | `$HOME/.config/fish/config.fish` | +- Running `swarm-cli --generate-completion` and following the instructions there +- Running `swarm-cli --install-completion` which automatically appends the completion script to your configuration file -> Warning! If you start a subshell (e.g. running `bash` from `zsh`), your `SHELL` env variable would still be the old value! The generation and completion script cannot detect your shell accurately in that case, so please set `SHELL` manually. It is generally advised to run `--generate-completion` first to ensure the shell and the paths are properly detected. +| Shell | Completion System | Configuration Path | +| ------ | ------------------------------------------------- | --------------------------------------- | +| `bash` | `compdef` & `compadd` OR `complete` & `COMPREPLY` | `$HOME/.bashrc` & `$HOME/.bash_profile` | +| `zsh` | `compdef` & `compadd` OR `complete` & `COMPREPLY` | `$HOME/.zshrc` | +| `fish` | `complete` | `$HOME/.config/fish/config.fish` | + +> Warning! If you start a subshell (e.g. running `bash` from `zsh`), your `SHELL` env variable would still be the old +> value! The generation and completion script cannot detect your shell accurately in that case, so please set `SHELL` +> manually. It is generally advised to run `--generate-completion` first to ensure the shell and the paths are properly +> detected. Example: @@ -256,7 +286,8 @@ You need to source your configuration, or restart your shell, to load the change ### Numerical Separator and Units -As most of the units are specified in wei and PLUR - the smallest denominations of currencies - they are a bit difficult to write out. +As most of the units are specified in wei and PLUR - the smallest denominations of currencies - they are a bit difficult +to write out. To aid this, you may use underscores (`_`) and `K`, `M`, `B` and `T` units to make your numbers more comprehensible. @@ -280,7 +311,8 @@ Look for hints in the `--help` sections. Take the `upload` command for example: --stamp ID of the postage stamp to use [required when quiet][string] ``` -That means, you don't have to provide the postage stamp ID beforehand. Simply running `swarm-cli upload ` will prompt you with an interactive stamp picker: +That means, you don't have to provide the postage stamp ID beforehand. Simply running `swarm-cli upload ` will +prompt you with an interactive stamp picker: ``` ? Please select a stamp for this action. @@ -294,11 +326,14 @@ That means, you don't have to provide the postage stamp ID beforehand. Simply ru Similarly to Stamp Picker, when an identity is not provided, an interactive picker will be prompted. -Take the command `feed upload` for example. Albeit it takes quite a lot of options, you can run it with typing as little as `feed upload `. +Take the command `feed upload` for example. Albeit it takes quite a lot of options, you can run it with typing as little +as `feed upload `. -`swarm-cli` will take you through some prompts to interactively specify all required options, such as `identity`, `password` of the identity, and the mandatory `stamp`. +`swarm-cli` will take you through some prompts to interactively specify all required options, such as `identity`, +`password` of the identity, and the mandatory `stamp`. -Passing identities is also tolerant to errors, so if you provide one which does not exist, the output will tell you and you can correct it: +Passing identities is also tolerant to errors, so if you provide one which does not exist, the output will tell you and +you can correct it: ``` The provided identity does not exist. Please select one that exists. @@ -312,7 +347,8 @@ You may need to pass topics on multiple occasions - for example, when uploading Topics are 32-byte long identifiers, so you need 64 characters to write them out in hexadecimal string format. -You can do that with the `--topic` or `-t` option, or alternatively take a shortcut and use a human readable string which will be hashed by `swarm-cli` for your convenience. It is available via the `--topic-string` or `-T` option. +You can do that with the `--topic` or `-t` option, or alternatively take a shortcut and use a human readable string +which will be hashed by `swarm-cli` for your convenience. It is available via the `--topic-string` or `-T` option. Example: @@ -331,11 +367,15 @@ Only one is required: [topic] or [topic-string] ### Manifest address scheme -The `manifest` commands enable low-level operation on manifests. These always require a root manifest reference (hash) argument as the input. Some commands, however, work with subparts of the manifest. A few examples are: downloading only a folder from a manifest, listing files only under a specific path in a manifest, and adding files or folders not to the root of the manifest, but under some path. +The `manifest` commands enable low-level operation on manifests. These always require a root manifest reference (hash) +argument as the input. Some commands, however, work with subparts of the manifest. A few examples are: downloading only +a folder from a manifest, listing files only under a specific path in a manifest, and adding files or folders not to the +root of the manifest, but under some path. These can be achieved by using the `bzz:///` scheme in the `
` argument as follows: -List entries under the `/command/pss` prefix in manifest `1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f` +List entries under the `/command/pss` prefix in manifest +`1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f` ``` swarm-cli manifest list bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5012ee749604a7b425f/command/pss @@ -351,7 +391,9 @@ swarm-cli manifest download bzz://1512546a3f4d0fea9f35fa1177486bdfe2bc2536917ad5 ### Automating tasks with Swarm-CLI -Running `swarm-cli` with the flag `--quiet` (or `-q` for short) disables all interactive features, and makes commands print information in an easily parsable format. The exit code also indicates whether running the command was successful or not. These may be useful for automating tasks both in CI environments and in your terminal too. +Running `swarm-cli` with the flag `--quiet` (or `-q` for short) disables all interactive features, and makes commands +print information in an easily parsable format. The exit code also indicates whether running the command was successful +or not. These may be useful for automating tasks both in CI environments and in your terminal too. Below you will find a few snippets to give an idea how it can be used to compose tasks. @@ -414,7 +456,8 @@ On Windows systems: `$HOME\AppData\swarm-cli` The configuration file is saved with `600` file permission. -On first run, this configuration will be generated with default values, that you are able to change on your demand under the before mentioned path. +On first run, this configuration will be generated with default values, that you are able to change on your demand under +the before mentioned path. ## Assignment priority @@ -423,7 +466,8 @@ It is possible to set value of particular parameters in different ways. The assignment priority of how option gets its value in question is the following: 1. passed CLI option value (with e.g. `--option-example-1`) -2. env variable for that option in form of either `OPTION_EXAMPLE_1` or `SWARM_CLI_OPTION_EXAMPLE_1` (if it is available) +2. env variable for that option in form of either `OPTION_EXAMPLE_1` or `SWARM_CLI_OPTION_EXAMPLE_1` (if it is + available) 3. CLI configuration value of that option (if it is available) 4. option's default fallback value (or it is required to define by #1) @@ -431,15 +475,13 @@ The assignment priority of how option gets its value in question is the followin With specific system environment variables you can alter the behaviour of the CLI -* `BEE_API_URL` - API URL of Bee client -* `BEE_DEBUG_API_URL` - Debug API URL of Bee client -* `SWARM_CLI_CONFIG_FOLDER` - full path to a configuration folder -* `SWARM_CLI_CONFIG_FILE` - configuration file name, defaults to config.json +- `BEE_API_URL` - API URL of Bee client +- `SWARM_CLI_CONFIG_FOLDER` - full path to a configuration folder +- `SWARM_CLI_CONFIG_FILE` - configuration file name, defaults to config.json # Development -After the project has been cloned, the dependencies must be -installed. Run the following in the project folder: +After the project has been cloned, the dependencies must be installed. Run the following in the project folder: ```sh $ npm install @@ -459,9 +501,8 @@ To make the local `swarm-cli` files in the `dist/` directory available as a glob If all went well you should be able to run `swarm-cli`. -If `npm link` fails, or you don't want to install anything, then you -can use `node dist/src/index.js` to run `swarm-cli` from the checked out -directory. +If `npm link` fails, or you don't want to install anything, then you can use `node dist/src/index.js` to run `swarm-cli` +from the checked out directory. # Contribute diff --git a/jest.config.ts b/jest.config.ts index ea2d81a2..9002a43f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -15,7 +15,7 @@ export default async (): Promise => { * only consists a single queen node as well */ if (!process.env.SKIP_WORKER) { - process.env.WORKER_PSS_ADDRESS = await getPssAddress('http://localhost:11635') + process.env.WORKER_PSS_ADDRESS = await getPssAddress('http://localhost:11633') } if (!process.env.STAMP) { diff --git a/package-lock.json b/package-lock.json index 38376b7e..dd3551ac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.9.0", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^6.9.0", + "@ethersphere/bee-js": "^7.0.0", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", @@ -1227,43 +1227,24 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.9.0.tgz", - "integrity": "sha512-TW7F8V6/Ha0oW1mh5ChFN0DDJHEHYTewCj/phg+CwjKIxagnrGVs52B2DLJKQLf4RnqNHY1MXSBXqAc5FnMwKQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.0.tgz", + "integrity": "sha512-SbWsV/FBOu42SB3oBWiZluD5rLbnHlS+vfHSPiWmbFrqyRh8ZtM/NA8nxRF7IOstP7tXl6RYAQnAHrAei+54lQ==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", - "@types/readable-stream": "^2.3.13", - "axios": "^0.28.0", - "cafe-utility": "^15.0.2", + "axios": "^0.28.1", + "cafe-utility": "^21.3.1", "elliptic": "^6.5.4", - "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", "js-sha3": "^0.8.0", "semver": "^7.3.5", - "tar-js": "^0.3.0", - "web-streams-polyfill": "^4.0.0-beta.3", "ws": "^8.7.0" - }, - "engines": { - "bee": "1.18.2-759f56f", - "beeApiVersion": "4.0.0", - "beeDebugApiVersion": "4.0.0", - "node": ">=14.0.0", - "npm": ">=6.0.0" } }, "node_modules/@ethersphere/bee-js/node_modules/cafe-utility": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-15.0.2.tgz", - "integrity": "sha512-TNKSfA/q/XRd86NwYtF5QImQB8U5n/hKZuWblYFgYW4aveHcSg2RGOfR3+xquXRXF7BCeNoAXe2/snWFKviPzw==" - }, - "node_modules/@ethersphere/bee-js/node_modules/web-streams-polyfill": { - "version": "4.0.0-beta.3", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", - "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", - "engines": { - "node": ">= 14" - } + "version": "21.3.1", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.3.1.tgz", + "integrity": "sha512-6e5dovyMdaWNbWOY+gvpb8LnIwyO7D53uf5At0abjeAbp998B3hohE5aePRSPRSY8nzbNNTsUFmExKpUQaR7Bw==" }, "node_modules/@ethersphere/swarm-cid": { "version": "0.1.0", @@ -2338,6 +2319,7 @@ "version": "2.3.13", "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-2.3.13.tgz", "integrity": "sha512-4JSCx8EUzaW9Idevt+9lsRAt1lcSccoQfE+AouM1gk8sFxnnytKNIO3wTl9Dy+4m6jRJ1yXhboLHHT/LXBQiEw==", + "dev": true, "dependencies": { "@types/node": "*", "safe-buffer": "*" @@ -2752,9 +2734,9 @@ } }, "node_modules/axios": { - "version": "0.28.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.0.tgz", - "integrity": "sha512-Tu7NYoGY4Yoc7I+Npf9HhUMtEEpV7ZiLH9yndTCoNhcpBH0kwcvFbzYN9/u5QKI5A6uefjsNNWaz5olJVYS62Q==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.1.tgz", + "integrity": "sha512-iUcGA5a7p0mVb4Gm/sy+FSECNkPFT4y7wt6OM/CDpO/OnNCvSs3PoMG8ibrC9jRoGYU0gUK5pXVC4NPXq6lHRQ==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -4407,6 +4389,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-2.1.2.tgz", "integrity": "sha512-YKqtUDwqLyfyMnmbw8XD6Q8j9i/HggKtPEI+pZ1+8bvheBu78biSmNaXWusx1TauGqtUUGx/cBb1mKdq2rLYow==", + "dev": true, "engines": { "node": "^10.17.0 || >=12.3.0" }, @@ -9116,6 +9099,7 @@ "version": "0.3.0", "resolved": "https://registry.npmjs.org/tar-js/-/tar-js-0.3.0.tgz", "integrity": "sha1-aUmqv7C6GLsVYq5RpDn9DzAYOhc=", + "dev": true, "engines": { "node": "*" } @@ -10679,33 +10663,24 @@ } }, "@ethersphere/bee-js": { - "version": "6.9.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-6.9.0.tgz", - "integrity": "sha512-TW7F8V6/Ha0oW1mh5ChFN0DDJHEHYTewCj/phg+CwjKIxagnrGVs52B2DLJKQLf4RnqNHY1MXSBXqAc5FnMwKQ==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.0.tgz", + "integrity": "sha512-SbWsV/FBOu42SB3oBWiZluD5rLbnHlS+vfHSPiWmbFrqyRh8ZtM/NA8nxRF7IOstP7tXl6RYAQnAHrAei+54lQ==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", - "@types/readable-stream": "^2.3.13", - "axios": "^0.28.0", - "cafe-utility": "^15.0.2", + "axios": "^0.28.1", + "cafe-utility": "^21.3.1", "elliptic": "^6.5.4", - "fetch-blob": "2.1.2", "isomorphic-ws": "^4.0.1", "js-sha3": "^0.8.0", "semver": "^7.3.5", - "tar-js": "^0.3.0", - "web-streams-polyfill": "^4.0.0-beta.3", "ws": "^8.7.0" }, "dependencies": { "cafe-utility": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-15.0.2.tgz", - "integrity": "sha512-TNKSfA/q/XRd86NwYtF5QImQB8U5n/hKZuWblYFgYW4aveHcSg2RGOfR3+xquXRXF7BCeNoAXe2/snWFKviPzw==" - }, - "web-streams-polyfill": { - "version": "4.0.0-beta.3", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", - "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==" + "version": "21.3.1", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.3.1.tgz", + "integrity": "sha512-6e5dovyMdaWNbWOY+gvpb8LnIwyO7D53uf5At0abjeAbp998B3hohE5aePRSPRSY8nzbNNTsUFmExKpUQaR7Bw==" } } }, @@ -11572,6 +11547,7 @@ "version": "2.3.13", "resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-2.3.13.tgz", "integrity": "sha512-4JSCx8EUzaW9Idevt+9lsRAt1lcSccoQfE+AouM1gk8sFxnnytKNIO3wTl9Dy+4m6jRJ1yXhboLHHT/LXBQiEw==", + "dev": true, "requires": { "@types/node": "*", "safe-buffer": "*" @@ -11854,9 +11830,9 @@ "dev": true }, "axios": { - "version": "0.28.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.0.tgz", - "integrity": "sha512-Tu7NYoGY4Yoc7I+Npf9HhUMtEEpV7ZiLH9yndTCoNhcpBH0kwcvFbzYN9/u5QKI5A6uefjsNNWaz5olJVYS62Q==", + "version": "0.28.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.28.1.tgz", + "integrity": "sha512-iUcGA5a7p0mVb4Gm/sy+FSECNkPFT4y7wt6OM/CDpO/OnNCvSs3PoMG8ibrC9jRoGYU0gUK5pXVC4NPXq6lHRQ==", "requires": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -13109,7 +13085,8 @@ "fetch-blob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-2.1.2.tgz", - "integrity": "sha512-YKqtUDwqLyfyMnmbw8XD6Q8j9i/HggKtPEI+pZ1+8bvheBu78biSmNaXWusx1TauGqtUUGx/cBb1mKdq2rLYow==" + "integrity": "sha512-YKqtUDwqLyfyMnmbw8XD6Q8j9i/HggKtPEI+pZ1+8bvheBu78biSmNaXWusx1TauGqtUUGx/cBb1mKdq2rLYow==", + "dev": true }, "figures": { "version": "3.2.0", @@ -16538,7 +16515,8 @@ "tar-js": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/tar-js/-/tar-js-0.3.0.tgz", - "integrity": "sha1-aUmqv7C6GLsVYq5RpDn9DzAYOhc=" + "integrity": "sha1-aUmqv7C6GLsVYq5RpDn9DzAYOhc=", + "dev": true }, "tar-stream": { "version": "2.2.0", diff --git a/package.json b/package.json index f5fb2cae..bc0aa803 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^6.9.0", + "@ethersphere/bee-js": "^7.0.0", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", diff --git a/src/command/addresses.ts b/src/command/addresses.ts index da113977..a6596050 100644 --- a/src/command/addresses.ts +++ b/src/command/addresses.ts @@ -16,8 +16,8 @@ export class Addresses extends RootCommand implements LeafCommand { public async run(): Promise { await super.init() - this.nodeAddresses = await this.beeDebug.getNodeAddresses() - this.chequebookAddress = (await this.beeDebug.getChequebookAddress()).chequebookAddress + this.nodeAddresses = await this.bee.getNodeAddresses() + this.chequebookAddress = (await this.bee.getChequebookAddress()).chequebookAddress const longest = 'PSS Public Key'.length this.console.log(chalk.bold('Node Addresses')) diff --git a/src/command/cheque/cashout.ts b/src/command/cheque/cashout.ts index 5cfffb27..752e2193 100644 --- a/src/command/cheque/cashout.ts +++ b/src/command/cheque/cashout.ts @@ -73,7 +73,7 @@ export class Cashout extends ChequeCommand implements LeafCommand { try { this.console.log(chalk.green('Cashing out:')) this.printCheque({ address, amount }) - const transaction = await this.beeDebug.cashoutLastCheque(address, { + const transaction = await this.bee.cashoutLastCheque(address, { gasLimit: this.gasLimit?.toString(), gasPrice: this.gasPrice?.toString(), }) diff --git a/src/command/cheque/cheque-command.ts b/src/command/cheque/cheque-command.ts index f89cefbe..b3b8150b 100644 --- a/src/command/cheque/cheque-command.ts +++ b/src/command/cheque/cheque-command.ts @@ -15,7 +15,7 @@ export class ChequeCommand extends RootCommand { } protected async getCashableCheques(): Promise { - const { lastcheques } = await this.beeDebug.getLastCheques() + const { lastcheques } = await this.bee.getLastCheques() const results: Cashable[] = [] for (const cheque of lastcheques) { @@ -41,7 +41,7 @@ export class ChequeCommand extends RootCommand { protected async getUncashedAmount(address: string): Promise { try { - const lastCashout = await this.beeDebug.getLastCashoutAction(address) + const lastCashout = await this.bee.getLastCashoutAction(address) return BigInt(lastCashout.uncashedAmount) } catch (error) { diff --git a/src/command/cheque/deposit.ts b/src/command/cheque/deposit.ts index 7056cec9..73669a1d 100644 --- a/src/command/cheque/deposit.ts +++ b/src/command/cheque/deposit.ts @@ -21,7 +21,7 @@ export class Deposit extends ChequeCommand implements LeafCommand { public async run(): Promise { await super.init() - const response = await this.beeDebug.depositTokens(this.amount.toString()) + const response = await this.bee.depositTokens(this.amount.toString()) this.console.log(createKeyValue('Tx', response)) this.console.quiet(response) } diff --git a/src/command/cheque/withdraw.ts b/src/command/cheque/withdraw.ts index c9680ef8..b511b612 100644 --- a/src/command/cheque/withdraw.ts +++ b/src/command/cheque/withdraw.ts @@ -21,7 +21,7 @@ export class Withdraw extends ChequeCommand implements LeafCommand { public async run(): Promise { await super.init() - const response = await this.beeDebug.withdrawTokens(this.amount.toString()) + const response = await this.bee.withdrawTokens(this.amount.toString()) this.console.log(createKeyValue('Tx', response)) this.console.quiet(response) } diff --git a/src/command/feed/feed-command.ts b/src/command/feed/feed-command.ts index a3fc4d30..4bfdba40 100644 --- a/src/command/feed/feed-command.ts +++ b/src/command/feed/feed-command.ts @@ -51,8 +51,8 @@ export class FeedCommand extends RootCommand { this.console.quiet(manifest) - if (!this.quiet && this.debugApiIsUsable()) { - printStamp(await this.beeDebug.getPostageBatch(this.stamp), this.console, { shortenBatchId: true }) + if (!this.quiet) { + printStamp(await this.bee.getPostageBatch(this.stamp), this.console, { shortenBatchId: true }) } return manifest diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index 15bda9d3..d0b76b44 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -37,7 +37,7 @@ export class Print extends FeedCommand implements LeafCommand { if (!this.stamp) { spinner.stop() - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) spinner.start() } diff --git a/src/command/feed/update.ts b/src/command/feed/update.ts index 5d9af4ae..c4dbd5d4 100644 --- a/src/command/feed/update.ts +++ b/src/command/feed/update.ts @@ -14,7 +14,7 @@ export class Update extends FeedCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } await this.updateFeedAndPrint(this.reference) diff --git a/src/command/feed/upload.ts b/src/command/feed/upload.ts index c3548d22..03207637 100644 --- a/src/command/feed/upload.ts +++ b/src/command/feed/upload.ts @@ -17,7 +17,7 @@ export class Upload extends FeedCommand implements LeafCommand { await super.init() if (!this.stamp) { - const stamp = await pickStamp(this.beeDebug, this.console) + const stamp = await pickStamp(this.bee, this.console) this.stamp = stamp this.fileUpload.stamp = stamp } diff --git a/src/command/manifest/add.ts b/src/command/manifest/add.ts index 812a4c0d..7df7c903 100644 --- a/src/command/manifest/add.ts +++ b/src/command/manifest/add.ts @@ -29,7 +29,7 @@ export class Add extends ManifestCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const address = new BzzAddress(this.bzzUrl) const { node } = await this.initializeNode(address.hash) diff --git a/src/command/manifest/create.ts b/src/command/manifest/create.ts index 4399cba6..1de22ba6 100644 --- a/src/command/manifest/create.ts +++ b/src/command/manifest/create.ts @@ -15,7 +15,7 @@ export class Create extends ManifestCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const node = new MantarayNode() await this.saveAndPrintNode(node, this.stamp) diff --git a/src/command/manifest/merge.ts b/src/command/manifest/merge.ts index 42616eb4..8436d26c 100644 --- a/src/command/manifest/merge.ts +++ b/src/command/manifest/merge.ts @@ -20,7 +20,7 @@ export class Merge extends ManifestCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const destinationNode = (await this.initializeNode(this.destination)).node const sourceNode = (await this.initializeNode(this.source)).node diff --git a/src/command/manifest/remove.ts b/src/command/manifest/remove.ts index 302bc1a2..41ab66b4 100644 --- a/src/command/manifest/remove.ts +++ b/src/command/manifest/remove.ts @@ -18,7 +18,7 @@ export class Remove extends ManifestCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const address = new BzzAddress(this.bzzUrl) diff --git a/src/command/manifest/sync.ts b/src/command/manifest/sync.ts index ce8241f4..477270d0 100644 --- a/src/command/manifest/sync.ts +++ b/src/command/manifest/sync.ts @@ -35,7 +35,7 @@ export class Sync extends ManifestCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const address = new BzzAddress(this.bzzUrl) const { node } = await this.initializeNode(address.hash) diff --git a/src/command/pss/send.ts b/src/command/pss/send.ts index d8384214..7522039a 100644 --- a/src/command/pss/send.ts +++ b/src/command/pss/send.ts @@ -69,7 +69,7 @@ export class Send extends PssCommand implements LeafCommand { } if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } this.console.log('Sending PSS message on topic ' + this.topic) diff --git a/src/command/root-command/command-config.ts b/src/command/root-command/command-config.ts index 0afe6c7c..4d529228 100644 --- a/src/command/root-command/command-config.ts +++ b/src/command/root-command/command-config.ts @@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs' import { homedir, platform } from 'os' import { join } from 'path' import { exit } from 'process' -import { beeApiUrl, beeDebugApiUrl } from '../../config' +import { beeApiUrl } from '../../config' import { Identity } from '../../service/identity/types' import { ConfigOption } from '../../utils/types/config-option' import { CommandLog } from './command-log' @@ -14,16 +14,11 @@ import { CommandLog } from './command-log' * `optionKey` is the kebab-case variant of the argument used in the parser, a.k.a. the key, * `propertyKey` is the camelCase variant used in TypeScript command classes, a.k.a. the property. */ -export const CONFIG_OPTIONS: ConfigOption[] = [ - { optionKey: 'bee-api-url', propertyKey: 'beeApiUrl' }, - { optionKey: 'bee-debug-api-url', propertyKey: 'beeDebugApiUrl' }, -] +export const CONFIG_OPTIONS: ConfigOption[] = [{ optionKey: 'bee-api-url', propertyKey: 'beeApiUrl' }] export interface Config { beeApiUrl: string - beeDebugApiUrl: string - identities: { [name: string]: Identity } } @@ -40,7 +35,6 @@ export class CommandConfig { this.console = console this.config = { beeApiUrl: beeApiUrl.default || '', - beeDebugApiUrl: beeDebugApiUrl.default || '', identities: {}, } this.configFolderPath = this.getConfigFolderPath(appName, configFolder) diff --git a/src/command/root-command/index.ts b/src/command/root-command/index.ts index d051f7ad..4050bb2e 100644 --- a/src/command/root-command/index.ts +++ b/src/command/root-command/index.ts @@ -1,6 +1,5 @@ -import { Bee, BeeDebug, BeeOptions } from '@ethersphere/bee-js' +import { Bee, BeeOptions } from '@ethersphere/bee-js' import { ExternalOption, Sourcemap, Utils } from 'furious-commander' -import { exit } from 'process' import { printCurlCommand } from '../../curl' import { parseHeaders } from '../../utils' import { ConfigOption } from '../../utils/types/config-option' @@ -11,9 +10,6 @@ export class RootCommand { @ExternalOption('bee-api-url') public beeApiUrl!: string - @ExternalOption('bee-debug-api-url') - public beeDebugApiUrl!: string - @ExternalOption('config-folder') public configFolder!: string @@ -39,43 +35,12 @@ export class RootCommand { public yes!: boolean public bee!: Bee - public _beeDebug!: BeeDebug public console!: CommandLog public readonly appName = 'swarm-cli' public commandConfig!: CommandConfig private sourcemap!: Sourcemap - /** - * Store Debug API errors here. It cannot be determined beforehand if Debug API is going to be used, - * since it is optional for some commands. The `beeDebug` getter should check if there are any errors - * here. Since the checks require async operations, this logic cannot be in the getter. - */ - private debugApiErrors: string[] = [] - - private async setupBeeDebug(): Promise { - if (!(await this.checkDebugApiHealth())) { - this.debugApiErrors.push('Could not reach Debug API at ' + this.beeDebugApiUrl) - this.debugApiErrors.push('Make sure you have the Debug API enabled in your Bee config') - this.debugApiErrors.push('or correct the URL with the --bee-debug-api-url option.') - } - } - - protected debugApiIsUsable(): boolean { - return this.debugApiErrors.length === 0 - } - - public get beeDebug(): BeeDebug { - if (!this.debugApiIsUsable()) { - for (const message of this.debugApiErrors) { - this.console.error(message) - } - - exit(1) - } - - return this._beeDebug - } - protected async init(): Promise { + protected init(): void { this.commandConfig = new CommandConfig(this.appName, this.console, this.configFile, this.configFolder) this.sourcemap = Utils.getSourcemap() @@ -93,7 +58,6 @@ export class RootCommand { beeOptions.headers = parseHeaders(this.header) } this.bee = new Bee(this.beeApiUrl, beeOptions) - this._beeDebug = new BeeDebug(this.beeDebugApiUrl, beeOptions) this.verbosity = VerbosityLevel.Normal if (this.quiet) { @@ -102,8 +66,6 @@ export class RootCommand { this.verbosity = VerbosityLevel.Verbose } this.console = new CommandLog(this.verbosity) - - await this.setupBeeDebug() } private maybeSetFromConfig(option: ConfigOption): void { @@ -115,14 +77,4 @@ export class RootCommand { } } } - - private async checkDebugApiHealth(): Promise { - try { - const health = await this._beeDebug.getHealth() - - return health.status === 'ok' - } catch (error) { - return false - } - } } diff --git a/src/command/stake.ts b/src/command/stake.ts index 9ff13dd8..39feba6e 100644 --- a/src/command/stake.ts +++ b/src/command/stake.ts @@ -1,11 +1,11 @@ import { BigNumber } from 'bignumber.js' import { LeafCommand, Option } from 'furious-commander' import { toSignificantDigits } from '../utils' +import { PLURConversionRate } from '../utils/conversions' +import { createSpinner } from '../utils/spinner' import { createKeyValue } from '../utils/text' import { RootCommand } from './root-command' -import { createSpinner } from '../utils/spinner' import { VerbosityLevel } from './root-command/command-log' -import { PLURConversionRate } from '../utils/conversions' const MIN_INITIAL_STAKE_PLUR = BigInt('100000000000000000') const MIN_INITIAL_STAKE_BZZ = 10 @@ -24,7 +24,7 @@ export class Stake extends RootCommand implements LeafCommand { public amount!: bigint | undefined private async deposit(amount: bigint): Promise { - const currentStake = BigInt(await this.beeDebug.getStake()) + const currentStake = BigInt(await this.bee.getStake()) if (!currentStake && amount < MIN_INITIAL_STAKE_PLUR) { if (this.quiet) { @@ -59,7 +59,7 @@ export class Stake extends RootCommand implements LeafCommand { } try { - await this.beeDebug.depositStake(amount.toString()) + await this.bee.depositStake(amount.toString()) spinner.stop() this.console.log('PLUR successfully staked!') @@ -76,7 +76,7 @@ export class Stake extends RootCommand implements LeafCommand { await this.deposit(this.amount) } - const stake = await this.beeDebug.getStake() + const stake = await this.bee.getStake() const stakeBN = BigNumber(stake).dividedBy(PLURConversionRate) this.console.log(createKeyValue('Staked BZZ', toSignificantDigits(stakeBN))) diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index 7e998236..9acbc6ee 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -93,7 +93,7 @@ export class Buy extends StampCommand implements LeafCommand { } try { - const batchId = await this.beeDebug.createPostageBatch(this.amount.toString(), this.depth, { + const batchId = await this.bee.createPostageBatch(this.amount.toString(), this.depth, { label: this.label, gasPrice: this.gasPrice?.toString(), immutableFlag: this.immutable, diff --git a/src/command/stamp/dilute.ts b/src/command/stamp/dilute.ts index 522475e7..44c373e4 100644 --- a/src/command/stamp/dilute.ts +++ b/src/command/stamp/dilute.ts @@ -28,10 +28,10 @@ export class Dilute extends StampCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } - const details = await this.beeDebug.getPostageBatch(this.stamp) + const details = await this.bee.getPostageBatch(this.stamp) if (this.depth <= details.depth) { throw new CommandLineError(`This postage stamp already has depth ${details.depth}. The new value must be higher.`) @@ -44,7 +44,7 @@ export class Dilute extends StampCommand implements LeafCommand { } try { - await this.beeDebug.diluteBatch(this.stamp, this.depth) + await this.bee.diluteBatch(this.stamp, this.depth) } finally { spinner.stop() } diff --git a/src/command/stamp/list.ts b/src/command/stamp/list.ts index 08d0de8d..bd960775 100644 --- a/src/command/stamp/list.ts +++ b/src/command/stamp/list.ts @@ -46,7 +46,7 @@ export class List extends StampCommand implements LeafCommand { await super.init() this.console.verbose(`Listing postage stamps...`) - const stamps = (await this.beeDebug.getAllPostageBatch()) || [] + const stamps = (await this.bee.getAllPostageBatch()) || [] if (stamps.length === 0) { this.console.error('You do not have any stamps.') diff --git a/src/command/stamp/show.ts b/src/command/stamp/show.ts index ed6db26f..a8c8b573 100644 --- a/src/command/stamp/show.ts +++ b/src/command/stamp/show.ts @@ -15,12 +15,12 @@ export class Show extends StampCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } this.console.verbose(`Looking up postage stamp ${this.stamp}...`) - const stamp = enrichStamp(await this.beeDebug.getPostageBatch(this.stamp)) + const stamp = enrichStamp(await this.bee.getPostageBatch(this.stamp)) printStamp(stamp, this.console, { printUsageInQuiet: true, showTtl: true }) } diff --git a/src/command/stamp/stamp-command.ts b/src/command/stamp/stamp-command.ts index 7dd867ec..b4ff6518 100644 --- a/src/command/stamp/stamp-command.ts +++ b/src/command/stamp/stamp-command.ts @@ -3,7 +3,7 @@ import { RootCommand } from '../root-command' export class StampCommand extends RootCommand { protected async printDepthAndAmount(id: string): Promise { - const stamp = await this.beeDebug.getPostageBatch(id) + const stamp = await this.bee.getPostageBatch(id) this.console.log(createKeyValue('Stamp ID', stamp.batchID)) this.console.log(createKeyValue('Depth', stamp.depth)) this.console.log(createKeyValue('Amount', stamp.amount)) diff --git a/src/command/stamp/topup.ts b/src/command/stamp/topup.ts index aab6a9ac..36d57b64 100644 --- a/src/command/stamp/topup.ts +++ b/src/command/stamp/topup.ts @@ -26,7 +26,7 @@ export class Topup extends StampCommand implements LeafCommand { await super.init() if (!this.stamp) { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } const spinner = createSpinner('Topup in progress. This may take a while.') @@ -36,7 +36,7 @@ export class Topup extends StampCommand implements LeafCommand { } try { - await this.beeDebug.topUpBatch(this.stamp, this.amount.toString()) + await this.bee.topUpBatch(this.stamp, this.amount.toString()) } finally { spinner.stop() } diff --git a/src/command/status.ts b/src/command/status.ts index db0eaa73..a2d93c0c 100644 --- a/src/command/status.ts +++ b/src/command/status.ts @@ -21,22 +21,15 @@ export class Status extends RootCommand implements LeafCommand { } catch { process.stdout.write(chalk.bold.red(' [FAILED]') + '\n') } - process.stdout.write(createKeyValue('Debug API', this.beeDebugApiUrl)) - try { - await this._beeDebug.getHealth() - process.stdout.write(chalk.bold.green(' [OK]') + '\n') - } catch { - process.stdout.write(chalk.bold.red(' [FAILED]') + '\n') - } - const versions = await this._beeDebug.getVersions() + const versions = await this.bee.getVersions() this.console.all(createKeyValue('Version', versions.beeVersion)) - const nodeInfo = await this._beeDebug.getNodeInfo() + const nodeInfo = await this.bee.getNodeInfo() this.console.all(createKeyValue('Mode', nodeInfo.beeMode)) if (nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Topology')) - const topology = await this._beeDebug.getTopology() + const topology = await this.bee.getTopology() this.console.all(createKeyValue('Connected Peers', topology.connected)) this.console.all(createKeyValue('Population', topology.population)) this.console.all(createKeyValue('Depth', topology.depth)) @@ -45,7 +38,7 @@ export class Status extends RootCommand implements LeafCommand { if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Wallet')) - const { bzzBalance, nativeTokenBalance } = await this._beeDebug.getWalletBalance() + const { bzzBalance, nativeTokenBalance } = await this.bee.getWalletBalance() this.console.all( createKeyValue( 'xBZZ', @@ -67,7 +60,7 @@ export class Status extends RootCommand implements LeafCommand { if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Chequebook')) - const { totalBalance, availableBalance } = await this._beeDebug.getChequebookBalance() + const { totalBalance, availableBalance } = await this.bee.getChequebookBalance() this.console.all( createKeyValue( 'Available xBZZ', @@ -89,7 +82,7 @@ export class Status extends RootCommand implements LeafCommand { if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Staking')) - const stake = await this._beeDebug.getStake() + const stake = await this.bee.getStake() this.console.all( createKeyValue( 'Staked BZZ', @@ -103,7 +96,7 @@ export class Status extends RootCommand implements LeafCommand { if (nodeInfo.beeMode === BeeModes.FULL) { this.console.all('') this.console.all(chalk.bold('Redistribution')) - const redistributionState = await this._beeDebug.getRedistributionState() + const redistributionState = await this.bee.getRedistributionState() this.console.all(createKeyValue('Reward', redistributionState.reward)) this.console.all(createKeyValue('Has sufficient funds', redistributionState.hasSufficientFunds)) this.console.all(createKeyValue('Fully synced', redistributionState.isFullySynced)) diff --git a/src/command/upload.ts b/src/command/upload.ts index 4805213d..9144e177 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -141,7 +141,7 @@ export class Upload extends RootCommand implements LeafCommand { if (isGateway(this.beeApiUrl)) { this.stamp = '0'.repeat(64) } else { - this.stamp = await pickStamp(this.beeDebug, this.console) + this.stamp = await pickStamp(this.bee, this.console) } } @@ -173,8 +173,8 @@ export class Upload extends RootCommand implements LeafCommand { if (!usedFromOtherCommand) { this.console.quiet(this.hash) - if (!isGateway(this.beeApiUrl) && !this.quiet && this.debugApiIsUsable()) { - printStamp(await this.beeDebug.getPostageBatch(this.stamp), this.console, { shortenBatchId: true }) + if (!isGateway(this.beeApiUrl) && !this.quiet) { + printStamp(await this.bee.getPostageBatch(this.stamp), this.console, { shortenBatchId: true }) } } } @@ -372,6 +372,7 @@ export class Upload extends RootCommand implements LeafCommand { this.console.log(`This setting will provide ${Math.round(currentSetting.errorTolerance * 100)}% error tolerance.`) this.console.log(`An additional ${extraSize.toString()} of data will be uploaded approximately.`) this.console.log(`${originalSize.toString()} → ${newSize.toString()} (+${extraSize.toString()})`) + if (!this.yes && !this.quiet) { const confirmation = await this.console.confirm('Do you want to proceed?') @@ -435,7 +436,7 @@ export class Upload extends RootCommand implements LeafCommand { if (connectedPeers === null) { this.console.log(warningSymbol()) this.console.log(warningText('Could not fetch connected peers info.')) - this.console.log(warningText('Either the debug API is not enabled, or you are uploading to a gateway node.')) + this.console.log(warningText('Are you uploading to a gateway node?')) this.console.log(warningText('Synchronization may time out.')) } else if (connectedPeers === 0) { this.console.log(warningSymbol()) @@ -446,7 +447,7 @@ export class Upload extends RootCommand implements LeafCommand { private async getConnectedPeers(): Promise { try { - const { connected } = await this._beeDebug.getTopology() + const { connected } = await this.bee.getTopology() return connected } catch { diff --git a/src/command/utility/unlock.ts b/src/command/utility/unlock.ts index 5af200c5..587a54ed 100644 --- a/src/command/utility/unlock.ts +++ b/src/command/utility/unlock.ts @@ -12,7 +12,6 @@ export class Unlock extends RootCommand implements LeafCommand { description: 'Wallet source (path or private key string)', required: true, autocompletePath: true, - conflicts: 'stdin', }) public walletSource!: string diff --git a/src/config.ts b/src/config.ts index fa4a0e66..f629b109 100644 --- a/src/config.ts +++ b/src/config.ts @@ -22,13 +22,6 @@ export const beeApiUrl: IOption = { envKey: 'BEE_API_URL', } -export const beeDebugApiUrl: IOption = { - key: 'bee-debug-api-url', - default: 'http://localhost:1635', - description: 'URL of the Bee-client Debug API', - envKey: 'BEE_DEBUG_API_URL', -} - export const configFolder: IOption = { key: 'config-folder', description: 'Path to the configuration folder that the CLI uses', @@ -100,7 +93,6 @@ export const yes: IOption = { export const optionParameters: IOption[] = [ beeApiUrl, - beeDebugApiUrl, configFolder, configFile, verbose, diff --git a/src/service/stamp/index.ts b/src/service/stamp/index.ts index 43a913fe..bc0efeac 100644 --- a/src/service/stamp/index.ts +++ b/src/service/stamp/index.ts @@ -1,4 +1,4 @@ -import { BeeDebug, PostageBatch, Utils } from '@ethersphere/bee-js' +import { Bee, PostageBatch, Utils } from '@ethersphere/bee-js' import { exit } from 'process' import { CommandLog } from '../../command/root-command/command-log' import { getFieldOrNull, secondsToDhms } from '../../utils' @@ -16,8 +16,8 @@ import { EnrichedStamp } from './types/stamp' * * @returns {Promise} Hex representation of the Stamp ID. */ -export async function pickStamp(beeDebug: BeeDebug, console: CommandLog): Promise { - const stamps = ((await beeDebug.getAllPostageBatch()) || []).map(enrichStamp) +export async function pickStamp(bee: Bee, console: CommandLog): Promise { + const stamps = ((await bee.getAllPostageBatch()) || []).map(enrichStamp) const choices = stamps .filter(stamp => stamp.usable || stamp.batchTTL > 0) diff --git a/test/command/cheque.spec.ts b/test/command/cheque.spec.ts index cf975c26..f46ddcdc 100644 --- a/test/command/cheque.spec.ts +++ b/test/command/cheque.spec.ts @@ -25,35 +25,27 @@ describeCommand( server.close() }) - it('should print helpful error message when api is unavailable', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:16737' - await invokeTestCli(['cheque', 'list']) - expect(getNthLastMessage(6)).toContain('Could not reach Debug API at http://localhost:16737') - expect(getNthLastMessage(5)).toContain('Make sure you have the Debug API enabled in your Bee config') - expect(getNthLastMessage(4)).toContain('or correct the URL with the --bee-debug-api-url option.') - }) - it('should print cheques', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'list']) expect(getLastMessage()).toContain('Cheque Value:') expect(getLastMessage()).toContain('8944000000000 PLUR') }) it('should not print cheques when --minimum is higher', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'list', '--minimum', '10000000000000000000']) expect(getLastMessage()).toContain('No uncashed cheques found') }) it('should print cheques when --minimum is lower', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'list', '--minimum', '1000']) expect(getLastMessage()).toContain('Cheque Value') }) it('should cashout all cheques', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'cashout', '--all']) expect(getNthLastMessage(3)).toContain('Peer Address:') expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') @@ -64,20 +56,20 @@ describeCommand( }) it('should allow specifying gas price and limit for cashout', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'cashout', '--all', '--gas-price', '100', '--gas-limit', '100']) expect(getLastMessage()).toContain('Tx:') expect(getLastMessage()).toContain('0x11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae') }) it('should not cashout any cheques when --minimum is higher', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli(['cheque', 'cashout', '--all', '--minimum', '10000000000000000000']) expect(getLastMessage()).toContain('Found 0 cheques') }) it('should cashout one specific cheque', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:1377' + process.env.BEE_API_URL = 'http://localhost:1377' await invokeTestCli([ 'cheque', 'cashout', diff --git a/test/command/stamp.spec.ts b/test/command/stamp.spec.ts index 91441189..9d1d6441 100644 --- a/test/command/stamp.spec.ts +++ b/test/command/stamp.spec.ts @@ -70,7 +70,7 @@ describeCommand( }) it.skip('should print custom message when there are no stamps', async () => { - await invokeTestCli(['stamp', 'list', '--bee-debug-api-url', 'http://localhost:11635']) + await invokeTestCli(['stamp', 'list', '--bee-api-url', 'http://localhost:11633']) expect(getNthLastMessage(4)).toContain('You do not have any stamps.') }) diff --git a/test/command/status.spec.ts b/test/command/status.spec.ts index 6c7bf87a..48f82140 100644 --- a/test/command/status.spec.ts +++ b/test/command/status.spec.ts @@ -24,21 +24,15 @@ describeCommand('Test Status command', ({ consoleMessages }) => { expect(consoleMessages).toMatchLinesInOrder(pattern) }) - it('should print when debug api is unavailable', async () => { - await invokeTestCli(['status', '--bee-debug-api-url', 'http://localhost:14999']) - const pattern = [['Debug API'], ['[FAILED]']] - expect(consoleMessages).toMatchLinesInOrder(pattern) - }) - - it('should print api and debug api connectivity', async () => { + it('should print api connectivity', async () => { await invokeTestCli(['status']) - const pattern = [['API'], ['[OK]'], ['Debug API'], ['[OK]']] + const pattern = [['API'], ['[OK]']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) it('should print bee info', async () => { await invokeTestCli(['status']) - const pattern = [['API'], ['Debug API'], ['Version'], ['Mode']] + const pattern = [['API'], ['Version'], ['Mode']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) diff --git a/test/misc/config.spec.ts b/test/misc/config.spec.ts deleted file mode 100644 index 6dc82244..00000000 --- a/test/misc/config.spec.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { writeFileSync } from 'fs' -import { join } from 'path' -import { describeCommand, invokeTestCli } from '../utility' - -describeCommand( - 'Test configuration loading', - ({ consoleMessages, configFolderPath }) => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const configFilePath = process.env.SWARM_CLI_CONFIG_FILE_PATH! - - it('should use config when env is not specified', async () => { - delete process.env.BEE_DEBUG_API_URL - - writeFileSync( - configFilePath, - JSON.stringify({ - beeDebugApiUrl: 'http://localhost:30003', - }), - ) - - await invokeTestCli(['cheque', 'list']) - expect(consoleMessages[1]).toContain('http://localhost:30003') - }) - - it('should use env over config when specified', async () => { - process.env.BEE_DEBUG_API_URL = 'http://localhost:30002' - - await invokeTestCli(['cheque', 'list']) - expect(consoleMessages[1]).toContain('http://localhost:30002') - }) - - it('should use explicit option over all', async () => { - await invokeTestCli(['cheque', 'list', '--bee-debug-api-url', 'http://localhost:30001']) - expect(consoleMessages[1]).toContain('http://localhost:30001') - }) - - it('should read config path explicitly, then use it for url', async () => { - delete process.env.BEE_DEBUG_API_URL - - writeFileSync( - join(configFolderPath, 'config2.config.json'), - JSON.stringify({ - beeDebugApiUrl: 'http://localhost:30004', - }), - ) - - await invokeTestCli(['cheque', 'list', '--config-file', 'config2.config.json']) - expect(consoleMessages[1]).toContain('http://localhost:30004') - }) - }, - { configFileName: 'test-config' }, -) diff --git a/test/misc/monetary-units.spec.ts b/test/misc/monetary-units.spec.ts index a3fb82b0..85b41581 100644 --- a/test/misc/monetary-units.spec.ts +++ b/test/misc/monetary-units.spec.ts @@ -58,17 +58,17 @@ describeCommand('Test Monetary units', ({ consoleMessages }) => { }) it('should show units after running: cheque list', async () => { - await invokeTestCli(['cheque', 'list', '--bee-debug-api-url', 'http://localhost:1378']) + await invokeTestCli(['cheque', 'list', '--bee-api-url', 'http://localhost:1378']) expectSubstringsPrinted('Cheque Value', 'PLUR') }) it('should show units after running: cheque cashout', async () => { - await invokeTestCli(['cheque', 'cashout', '--all', '--bee-debug-api-url', 'http://localhost:1378']) + await invokeTestCli(['cheque', 'cashout', '--all', '--bee-api-url', 'http://localhost:1378']) expectSubstringsPrinted('Cheque Value', 'PLUR') }) it('should show units after running: balance', async () => { - await invokeTestCli(['status', '--bee-debug-api-url', 'http://localhost:1378']) + await invokeTestCli(['status', '--bee-api-url', 'http://localhost:1378']) const pattern = [ ['Wallet'], ['xBZZ', '0.3904'], diff --git a/test/misc/unavailable-bee-debug.spec.ts b/test/misc/unavailable-bee-debug.spec.ts deleted file mode 100644 index a5e6da1a..00000000 --- a/test/misc/unavailable-bee-debug.spec.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { describeCommand, invokeTestCli } from '../utility' -import { getStampOption } from '../utility/stamp' - -describeCommand('Test unavailable bee-debug', ({ consoleMessages, hasMessageContaining }) => { - it('should fail for stamp commands (mandatory)', async () => { - await invokeTestCli(['stamp', 'list', '--bee-debug-api-url', 'http://localhost:3362']) - expect(consoleMessages[0]).toContain('Could not reach Debug API at http://localhost:3362') - expect(consoleMessages[1]).toContain('Make sure you have the Debug API enabled in your Bee config') - expect(consoleMessages[2]).toContain('or correct the URL with the --bee-debug-api-url option.') - }) - - it('should work for upload (optional)', async () => { - await invokeTestCli(['upload', 'README.md', '--bee-debug-api-url', 'http://localhost:3362', ...getStampOption()]) - expect(hasMessageContaining('Swarm hash')).toBeTruthy() - expect(hasMessageContaining('Could not reach Debug API')).toBeFalsy() - }) - - it('should work for feed upload (optional)', async () => { - const identityName = 'i' + Date.now() - await invokeTestCli(['identity', 'create', identityName, '--only-keypair']) - await invokeTestCli([ - 'feed', - 'upload', - 'README.md', - '--bee-debug-api-url', - 'http://localhost:3362', - '--identity', - identityName, - ...getStampOption(), - ]) - expect(hasMessageContaining('Swarm hash')).toBeTruthy() - expect(hasMessageContaining('Could not reach Debug API')).toBeFalsy() - }) -}) diff --git a/test/misc/unsure-bee-debug.spec.ts b/test/misc/unsure-bee-debug.spec.ts deleted file mode 100644 index 3b06f521..00000000 --- a/test/misc/unsure-bee-debug.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describeCommand, invokeTestCli } from '../utility' -import { getStampOption } from '../utility/stamp' - -describeCommand('Test unsure bee-debug', ({ hasMessageContaining }) => { - it('should work for upload (optional)', async () => { - delete process.env.BEE_API_URL - delete process.env.BEE_DEBUG_API_URL - await invokeTestCli(['upload', 'README.md', '--bee-api-url', 'http://localhost:1633', ...getStampOption()]) - expect(hasMessageContaining('Swarm hash')).toBeTruthy() - expect(hasMessageContaining('Could not reach Debug API')).toBeFalsy() - }) - - it('should work for feed upload (optional)', async () => { - delete process.env.BEE_API_URL - delete process.env.BEE_DEBUG_API_URL - const identityName = 'i' + Date.now() - await invokeTestCli(['identity', 'create', identityName, '--only-keypair']) - await invokeTestCli([ - 'feed', - 'upload', - 'README.md', - '--bee-api-url', - 'http://localhost:1633', - '--identity', - identityName, - ...getStampOption(), - ]) - expect(hasMessageContaining('Swarm hash')).toBeTruthy() - expect(hasMessageContaining('Could not reach Debug API')).toBeFalsy() - }) -}) diff --git a/test/utility/address.ts b/test/utility/address.ts index 56aea459..f363cb1c 100644 --- a/test/utility/address.ts +++ b/test/utility/address.ts @@ -1,8 +1,8 @@ import { invokeTestCli } from '.' import { Addresses } from '../../src/command/addresses' -export async function getPssAddress(beeDebugApiUrl: string): Promise { - const execution = await invokeTestCli(['addresses', '--bee-debug-api-url', beeDebugApiUrl]) +export async function getPssAddress(beeApiUrl: string): Promise { + const execution = await invokeTestCli(['addresses', '--bee-api-url', beeApiUrl]) return (execution.runnable as Addresses).nodeAddresses.pssPublicKey } diff --git a/test/utility/stamp.ts b/test/utility/stamp.ts index 4f37228d..40472204 100644 --- a/test/utility/stamp.ts +++ b/test/utility/stamp.ts @@ -1,12 +1,9 @@ /* eslint-disable no-console */ -import { BeeDebug } from '@ethersphere/bee-js' - -const DEFAULT_BEE_DEBUG = 'http://localhost:1635' +import { Bee } from '@ethersphere/bee-js' export const getOrBuyStamp = async (): Promise => { - const beeDebug = new BeeDebug(DEFAULT_BEE_DEBUG) - - const availableStamps = await beeDebug.getAllPostageBatch() + const bee = new Bee('http://localhost:1633') + const availableStamps = await bee.getAllPostageBatch() if (availableStamps.length > 0) { const usedStamp = availableStamps[0].batchID @@ -16,7 +13,7 @@ export const getOrBuyStamp = async (): Promise => { } console.log('Buying new stamp.') - const newStamp = await beeDebug.createPostageBatch('1000000', 20, { waitForUsable: true }) + const newStamp = await bee.createPostageBatch('500000000', 20, { waitForUsable: true }) console.log('Bought stamp: ', newStamp) return newStamp From 88a463f9b80740ec4c97a0194ed9f192ac571244 Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:53:59 +0200 Subject: [PATCH 04/26] chore: release 2.10.0 (#504) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd482b31..e13cf7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.10.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.9.0...v2.10.0) (2024-06-03) + + +### Features + +* merge api ([#503](https://www.github.com/ethersphere/swarm-cli/issues/503)) ([0106e4d](https://www.github.com/ethersphere/swarm-cli/commit/0106e4de697dfe97dfcae42eff8d2c74755df410)) + ## [2.9.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.8.0...v2.9.0) (2024-04-15) diff --git a/package-lock.json b/package-lock.json index dd3551ac..49b42064 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.9.0", + "version": "2.10.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.9.0", + "version": "2.10.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.0.0", diff --git a/package.json b/package.json index bc0aa803..e1a70cbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.9.0", + "version": "2.10.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From f4b24acbce3e6e9ae783f29e234e9c999f4e60fc Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Tue, 18 Jun 2024 05:12:22 -0700 Subject: [PATCH 05/26] feat: upgrade bee-js to 7.0.3 (#505) --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 49b42064..aa4cda74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.10.0", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^7.0.0", + "@ethersphere/bee-js": "^7.0.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": "7.0.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.0.tgz", - "integrity": "sha512-SbWsV/FBOu42SB3oBWiZluD5rLbnHlS+vfHSPiWmbFrqyRh8ZtM/NA8nxRF7IOstP7tXl6RYAQnAHrAei+54lQ==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.3.tgz", + "integrity": "sha512-1Z19V6AJey6BScvIg7/kb464B9oPS6/nIrvEODWEJTXsaC/DBXAdQhR76ypvhrW3ldbwT5NVDA0HEfc9QekVEw==", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "axios": "^0.28.1", @@ -10663,9 +10663,9 @@ } }, "@ethersphere/bee-js": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.0.tgz", - "integrity": "sha512-SbWsV/FBOu42SB3oBWiZluD5rLbnHlS+vfHSPiWmbFrqyRh8ZtM/NA8nxRF7IOstP7tXl6RYAQnAHrAei+54lQ==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.3.tgz", + "integrity": "sha512-1Z19V6AJey6BScvIg7/kb464B9oPS6/nIrvEODWEJTXsaC/DBXAdQhR76ypvhrW3ldbwT5NVDA0HEfc9QekVEw==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "axios": "^0.28.1", diff --git a/package.json b/package.json index e1a70cbc..40f382d3 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^7.0.0", + "@ethersphere/bee-js": "^7.0.3", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", "chalk": "^2.4.2", From 89110454c015c91c6e1d3caf03a81326d1a4b991 Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:13:34 +0200 Subject: [PATCH 06/26] chore: release 2.11.0 (#506) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13cf7d2..85e2f0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [2.11.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.10.0...v2.11.0) (2024-06-18) + + +### Features + +* upgrade bee-js to 7.0.3 ([#505](https://www.github.com/ethersphere/swarm-cli/issues/505)) ([f4b24ac](https://www.github.com/ethersphere/swarm-cli/commit/f4b24acbce3e6e9ae783f29e234e9c999f4e60fc)) + ## [2.10.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.9.0...v2.10.0) (2024-06-03) diff --git a/package-lock.json b/package-lock.json index aa4cda74..5fc18888 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.10.0", + "version": "2.11.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.10.0", + "version": "2.11.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.0.3", diff --git a/package.json b/package.json index 40f382d3..81dfebea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.10.0", + "version": "2.11.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From d3cd5a0ec8d81838effe51a3104e4ab442a53a60 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 05:07:54 -0700 Subject: [PATCH 07/26] docs: expand on node.js requirement in readme (#510) --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 151103a1..42566bd1 100644 --- a/README.md +++ b/README.md @@ -78,20 +78,17 @@ For the currently supported operations, see the [Commands](#commands) section. ## Installation -### From npm +Requires Node.js 18 or higher. It is recommended to use [NVM](https://github.com/nvm-sh/nvm) to manage Node.js versions. -To install globally (requires `npm root --global` to be writable): +> Warning! Installing Node.js via package managers (e.g. `apt`, `yum`, `brew`) may not work as expected, as they may +> install an older version of Node.js. -```sh -npm install --global @ethersphere/swarm-cli -``` +### From npm -To install locally: +Install globally: ```sh -cd [some directory for nodejs files] -npm install @ethersphere/swarm-cli -./node_modules/.bin/swarm-cli --help +npm install --global @ethersphere/swarm-cli ``` ### From source @@ -111,7 +108,7 @@ Running a command with the `--help` option prints out the usage of a command. Running `swarm-cli` without arguments prints the available commands: ``` -Swarm CLI 1.5.0 - Manage your Bee node and interact with the Swarm network via the CLI +Swarm CLI 2.11.0 - Manage your Bee node and interact with the Swarm network via the CLI █ Usage: @@ -126,6 +123,7 @@ cheque Deposit, withdraw and manage cheques stamp Buy, list and show postage stamps pss Send, receive, or subscribe to PSS messages manifest Operate on manifests +utility Utility commands for managing wallets Run 'swarm-cli GROUP --help' to see available commands in a group @@ -133,8 +131,10 @@ Run 'swarm-cli GROUP --help' to see available commands in a group upload Upload file to Swarm download Download arbitrary Swarm hash -status Check API availability and Bee compatibility +hash Print the Swarm hash of a file +status Check Bee status addresses Display the addresses of the Bee node +stake Manages nodes stake Run 'swarm-cli COMMAND --help' for more information on a command ``` From c0a53379cdb1e0558659f3e6d8386ebe5a4034c1 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:21:58 -0700 Subject: [PATCH 08/26] feat: disambiguate xdai and xbzz values (#511) * feat: disambiguate xdai and xbzz values * feat: disambiguate xdai and xbzz values --- README.md | 2 +- package-lock.json | 28 ++++++++--------- package.json | 2 +- src/command/stake.ts | 15 ++++----- src/command/stamp/buy.ts | 6 ++-- src/command/status.ts | 53 ++++++-------------------------- src/command/upload.ts | 5 +-- src/service/stamp/index.ts | 11 +++---- src/utils/conversions.ts | 3 -- src/utils/index.ts | 48 ----------------------------- test/command/pss.spec.ts | 6 ++-- test/command/stake.spec.ts | 4 +-- test/command/stamp.spec.ts | 29 +++++++---------- test/prompt/stamp-prompt.spec.ts | 2 +- test/utils/index.spec.ts | 23 -------------- 15 files changed, 59 insertions(+), 178 deletions(-) delete mode 100644 src/utils/conversions.ts delete mode 100644 test/utils/index.spec.ts diff --git a/README.md b/README.md index 42566bd1..7de51c6a 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ to sign updates. It's also possible to import and export Ethereum JSON V3 format (e.g. wallets). Another requirement for uploading to the Swarm network is a valid postage batch, also called a postage stamp or simply a -stamp. Stamps need to be purchased with BZZ tokens. We can use the `stamp buy` command to take care of this step. The +stamp. Stamps need to be purchased with xBZZ tokens. We can use the `stamp buy` command to take care of this step. The `--amount` and `--depth` options alter the capacity of the postage stamp. For example, running `stamp buy --amount 1 --depth 20` will get back with a Stamp ID after a while. We will be using that with the `--stamp` option in commands which upload files, or write feeds. diff --git a/package-lock.json b/package-lock.json index 5fc18888..cd6c1400 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@ethersphere/bee-js": "^7.0.3", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", + "cafe-utility": "^22.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", "ethereumjs-wallet": "^1.0.2", @@ -34,7 +35,6 @@ "@types/node": "^18.11.9", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/parser": "^5.43.0", - "cafe-utility": "^10.8.1", "eslint": "^8.27.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-jest": "^27.1.5", @@ -1242,9 +1242,9 @@ } }, "node_modules/@ethersphere/bee-js/node_modules/cafe-utility": { - "version": "21.3.1", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.3.1.tgz", - "integrity": "sha512-6e5dovyMdaWNbWOY+gvpb8LnIwyO7D53uf5At0abjeAbp998B3hohE5aePRSPRSY8nzbNNTsUFmExKpUQaR7Bw==" + "version": "21.5.0", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.5.0.tgz", + "integrity": "sha512-5u+9cf7fvcH3j2Q3jrd7nA3bUITUBj8b9Arg4eA6almqeA5+dwQA6NKba4GnW6zS9uL1iVCEQqM3z3tQVs2Xjw==" }, "node_modules/@ethersphere/swarm-cid": { "version": "0.1.0", @@ -3139,10 +3139,9 @@ } }, "node_modules/cafe-utility": { - "version": "10.8.1", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-10.8.1.tgz", - "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==", - "dev": true + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-22.0.0.tgz", + "integrity": "sha512-1nlKbWXznDPV+B7eQKm6VHgbDG80snNODRix54RTyv+Y/CJ9VPxlfrFiG/VCprR6mL4c9RK+KADGE1biVGVLSw==" }, "node_modules/callsites": { "version": "3.1.0", @@ -10678,9 +10677,9 @@ }, "dependencies": { "cafe-utility": { - "version": "21.3.1", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.3.1.tgz", - "integrity": "sha512-6e5dovyMdaWNbWOY+gvpb8LnIwyO7D53uf5At0abjeAbp998B3hohE5aePRSPRSY8nzbNNTsUFmExKpUQaR7Bw==" + "version": "21.5.0", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-21.5.0.tgz", + "integrity": "sha512-5u+9cf7fvcH3j2Q3jrd7nA3bUITUBj8b9Arg4eA6almqeA5+dwQA6NKba4GnW6zS9uL1iVCEQqM3z3tQVs2Xjw==" } } }, @@ -12135,10 +12134,9 @@ "optional": true }, "cafe-utility": { - "version": "10.8.1", - "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-10.8.1.tgz", - "integrity": "sha512-Tt7O4MRCJa3Nj7qGZGpy7o7PpbdLiKu1yOwQcXFgopnCmfwsSHHJZcIwkpPBu7tyXAbNjmN2f3+pdwwKYpYZcA==", - "dev": true + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/cafe-utility/-/cafe-utility-22.0.0.tgz", + "integrity": "sha512-1nlKbWXznDPV+B7eQKm6VHgbDG80snNODRix54RTyv+Y/CJ9VPxlfrFiG/VCprR6mL4c9RK+KADGE1biVGVLSw==" }, "callsites": { "version": "3.1.0", diff --git a/package.json b/package.json index 81dfebea..b41d8f3c 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "@types/node": "^18.11.9", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/parser": "^5.43.0", - "cafe-utility": "^10.8.1", "eslint": "^8.27.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-jest": "^27.1.5", @@ -66,6 +65,7 @@ "@ethersphere/bee-js": "^7.0.3", "@fairdatasociety/bmt-js": "^2.1.0", "bignumber.js": "^9.1.0", + "cafe-utility": "^22.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", "ethereumjs-wallet": "^1.0.2", diff --git a/src/command/stake.ts b/src/command/stake.ts index 39feba6e..30f6ea74 100644 --- a/src/command/stake.ts +++ b/src/command/stake.ts @@ -1,7 +1,5 @@ -import { BigNumber } from 'bignumber.js' +import { Numbers } from 'cafe-utility' import { LeafCommand, Option } from 'furious-commander' -import { toSignificantDigits } from '../utils' -import { PLURConversionRate } from '../utils/conversions' import { createSpinner } from '../utils/spinner' import { createKeyValue } from '../utils/text' import { RootCommand } from './root-command' @@ -28,15 +26,15 @@ export class Stake extends RootCommand implements LeafCommand { if (!currentStake && amount < MIN_INITIAL_STAKE_PLUR) { if (this.quiet) { - throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} BZZ!`) + throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ!`) } if ( !(await this.console.confirm( - `Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} BZZ. Do you want to increase the deposit to ${MIN_INITIAL_STAKE_BZZ} BZZ?`, + `Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ. Do you want to increase the deposit to ${MIN_INITIAL_STAKE_BZZ} xBZZ?`, )) ) { - throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} BZZ!`) + throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ!`) } amount = MIN_INITIAL_STAKE_PLUR @@ -77,9 +75,8 @@ export class Stake extends RootCommand implements LeafCommand { } const stake = await this.bee.getStake() - const stakeBN = BigNumber(stake).dividedBy(PLURConversionRate) - this.console.log(createKeyValue('Staked BZZ', toSignificantDigits(stakeBN))) - this.console.quiet(toSignificantDigits(stakeBN)) + this.console.log(createKeyValue('Staked xBZZ', Numbers.fromDecimals(stake, 16))) + this.console.quiet(Numbers.fromDecimals(stake, 16)) } } diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index 9acbc6ee..c84ef435 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -1,6 +1,6 @@ import { Utils } from '@ethersphere/bee-js' +import { Dates } from 'cafe-utility' import { LeafCommand, Option } from 'furious-commander' -import { secondsToDhms } from '../../utils' import { createSpinner } from '../../utils/spinner' import { Storage } from '../../utils/storage' import { createKeyValue } from '../../utils/text' @@ -63,9 +63,9 @@ export class Buy extends StampCommand implements LeafCommand { const estimatedCapacity = new Storage(Utils.getStampMaximumCapacityBytes(this.depth)) const estimatedTtl = Utils.getStampTtlSeconds(Number(this.amount)) - this.console.log(createKeyValue('Estimated cost', `${estimatedCost.toFixed(3)} BZZ`)) + this.console.log(createKeyValue('Estimated cost', `${estimatedCost.toFixed(3)} xBZZ`)) this.console.log(createKeyValue('Estimated capacity', estimatedCapacity.toString())) - this.console.log(createKeyValue('Estimated TTL', secondsToDhms(estimatedTtl))) + this.console.log(createKeyValue('Estimated TTL', Dates.secondsToHumanTime(estimatedTtl))) this.console.log(createKeyValue('Type', this.immutable ? 'Immutable' : 'Mutable')) if (this.immutable) { diff --git a/src/command/status.ts b/src/command/status.ts index a2d93c0c..c400e1ee 100644 --- a/src/command/status.ts +++ b/src/command/status.ts @@ -1,5 +1,5 @@ import { BeeModes } from '@ethersphere/bee-js' -import BigNumber from 'bignumber.js' +import { Numbers } from 'cafe-utility' import chalk from 'chalk' import { LeafCommand } from 'furious-commander' import { createKeyValue } from '../utils/text' @@ -39,72 +39,39 @@ export class Status extends RootCommand implements LeafCommand { this.console.all('') this.console.all(chalk.bold('Wallet')) const { bzzBalance, nativeTokenBalance } = await this.bee.getWalletBalance() - this.console.all( - createKeyValue( - 'xBZZ', - BigNumber(bzzBalance) - .div(10 ** 16) - .toString(10), - ), - ) - this.console.all( - createKeyValue( - 'xDAI', - BigNumber(nativeTokenBalance) - .div(10 ** 18) - .toString(10), - ), - ) + this.console.all(createKeyValue('xBZZ', Numbers.fromDecimals(bzzBalance, 16))) + this.console.all(createKeyValue('xDAI', Numbers.fromDecimals(nativeTokenBalance, 18))) } if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Chequebook')) const { totalBalance, availableBalance } = await this.bee.getChequebookBalance() - this.console.all( - createKeyValue( - 'Available xBZZ', - BigNumber(availableBalance) - .div(10 ** 16) - .toString(10), - ), - ) - this.console.all( - createKeyValue( - 'Total xBZZ', - BigNumber(totalBalance) - .div(10 ** 16) - .toString(10), - ), - ) + this.console.all(createKeyValue('Available xBZZ', Numbers.fromDecimals(availableBalance, 16))) + this.console.all(createKeyValue('Total xBZZ', Numbers.fromDecimals(totalBalance, 16))) } if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) { this.console.all('') this.console.all(chalk.bold('Staking')) const stake = await this.bee.getStake() - this.console.all( - createKeyValue( - 'Staked BZZ', - BigNumber(stake) - .div(10 ** 16) - .toString(10), - ), - ) + this.console.all(createKeyValue('Staked xBZZ', Numbers.fromDecimals(stake, 16))) } if (nodeInfo.beeMode === BeeModes.FULL) { this.console.all('') this.console.all(chalk.bold('Redistribution')) const redistributionState = await this.bee.getRedistributionState() - this.console.all(createKeyValue('Reward', redistributionState.reward)) + this.console.all(createKeyValue('Reward', Numbers.fromDecimals(redistributionState.reward, 16, 'xBZZ'))) this.console.all(createKeyValue('Has sufficient funds', redistributionState.hasSufficientFunds)) this.console.all(createKeyValue('Fully synced', redistributionState.isFullySynced)) this.console.all(createKeyValue('Frozen', redistributionState.isFrozen)) this.console.all(createKeyValue('Last selected round', redistributionState.lastSelectedRound)) this.console.all(createKeyValue('Last played round', redistributionState.lastPlayedRound)) this.console.all(createKeyValue('Last won round', redistributionState.lastWonRound)) - this.console.all(createKeyValue('Minimum gas funds', redistributionState.minimumGasFunds)) + this.console.all( + createKeyValue('Minimum gas funds', Numbers.fromDecimals(redistributionState.minimumGasFunds, 18, 'xDAI')), + ) } } } diff --git a/src/command/upload.ts b/src/command/upload.ts index 9144e177..b1b04840 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -1,4 +1,5 @@ import { RedundancyLevel, Tag, Utils } from '@ethersphere/bee-js' +import { System } from 'cafe-utility' import { Presets, SingleBar } from 'cli-progress' import * as FS from 'fs' import { Argument, LeafCommand, Option } from 'furious-commander' @@ -6,7 +7,7 @@ import { join, parse } from 'path' import { exit } from 'process' import { setCurlStore } from '../curl' import { pickStamp, printStamp } from '../service/stamp' -import { fileExists, isGateway, readStdin, sleep } from '../utils' +import { fileExists, isGateway, readStdin } from '../utils' import { CommandLineError } from '../utils/error' import { Message } from '../utils/message' import { getMime } from '../utils/mime' @@ -317,7 +318,7 @@ export class Upload extends RootCommand implements LeafCommand { progressBar.setTotal(tag.split) progressBar.update(syncProgress) } - await sleep(pollingTime) + await System.sleepMillis(pollingTime) } progressBar.stop() diff --git a/src/service/stamp/index.ts b/src/service/stamp/index.ts index bc0efeac..6b36124e 100644 --- a/src/service/stamp/index.ts +++ b/src/service/stamp/index.ts @@ -1,7 +1,8 @@ import { Bee, PostageBatch, Utils } from '@ethersphere/bee-js' +import { Dates } from 'cafe-utility' import { exit } from 'process' import { CommandLog } from '../../command/root-command/command-log' -import { getFieldOrNull, secondsToDhms } from '../../utils' +import { getFieldOrNull } from '../../utils' import { Storage } from '../../utils/storage' import { createKeyValue } from '../../utils/text' import { EnrichedStamp } from './types/stamp' @@ -21,7 +22,7 @@ export async function pickStamp(bee: Bee, console: CommandLog): Promise const choices = stamps .filter(stamp => stamp.usable || stamp.batchTTL > 0) - .map(stamp => `${stamp.batchID} ${stamp.remainingCapacity} expires in ${secondsToDhms(stamp.batchTTL, true)}`) + .map(stamp => `${stamp.batchID} ${stamp.remainingCapacity} expires in ${Dates.secondsToHumanTime(stamp.batchTTL)}`) if (!choices.length) { console.error('You need to have at least one stamp for this action.') @@ -54,7 +55,6 @@ export function enrichStamp(stamp: PostageBatch): EnrichedStamp { interface PrintStampSettings { shortenBatchId?: boolean showTtl?: boolean - shortenTtl?: boolean printUsageInQuiet?: boolean } @@ -80,11 +80,10 @@ export function printStamp( ) if (settings?.showTtl) { - const ttl = stamp.batchTTL === -1 ? 'unknown' : secondsToDhms(stamp.batchTTL, settings?.shortenTtl) + const ttl = stamp.batchTTL === -1 ? 'unknown' : Dates.secondsToHumanTime(stamp.batchTTL) const expires = stamp.batchTTL === -1 ? 'unknown' : new Date(Date.now() + stamp.batchTTL * 1000).toISOString().slice(0, 10) - console.log(createKeyValue('TTL', ttl)) - console.log(createKeyValue('Expires', expires)) + console.log(createKeyValue('TTL', `${ttl} (${expires})`)) } console.verbose(createKeyValue('Depth', stamp.depth)) diff --git a/src/utils/conversions.ts b/src/utils/conversions.ts deleted file mode 100644 index 8943f2f9..00000000 --- a/src/utils/conversions.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { BigNumber } from 'bignumber.js' - -export const PLURConversionRate = BigNumber(10).pow(16) diff --git a/src/utils/index.ts b/src/utils/index.ts index 750cb17a..41e77f83 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,19 +1,9 @@ import { Reference } from '@ethersphere/bee-js' -import BigNumber from 'bignumber.js' import { promises, statSync } from 'fs' import { join } from 'path' import { CommandLog } from '../command/root-command/command-log' import { CommandLineError } from './error' -/** - * Sleep for N miliseconds - * - * @param ms Number of miliseconds to sleep - */ -export function sleep(ms: number): Promise { - return new Promise(resolve => setTimeout(() => resolve(), ms)) -} - export function fileExists(path: string): boolean { try { const stat = statSync(path) @@ -52,24 +42,6 @@ export function getByteSize(data: string | Uint8Array): number { return Buffer.byteLength(data, 'utf-8') } -export function secondsToDhms(secs: number, abstractTimeFormat = false): string { - const d = Math.floor(secs / (3600 * 24)) - const h = Math.floor((secs % (3600 * 24)) / 3600) - const m = Math.floor((secs % 3600) / 60) - const s = Math.floor(secs % 60) - - const dDisplay = d > 0 ? d + (d === 1 ? ' day ' : ' days ') : '' - const hDisplay = h > 0 ? h + (h === 1 ? ' hour ' : ' hours ') : '' - const mDisplay = m > 0 ? m + (m === 1 ? ' minute ' : ' minutes ') : '' - const sDisplay = s > 0 ? s + (s === 1 ? ' second' : ' seconds') : '' - - if (abstractTimeFormat) { - return (dDisplay || hDisplay || mDisplay || sDisplay).trim() - } - - return (dDisplay + hDisplay + mDisplay + sDisplay).trim() -} - /** * Lists all files recursively in a folder * @param path folder path @@ -199,23 +171,3 @@ export function isPrivateKey(string: string): boolean { return /^[a-f0-9]{64}$/.test(normalized) } - -export function toSignificantDigits(val: BigNumber, digits = 4): string { - const asString = val.toFixed(16) - let indexOfSignificantDigit = -1 - let reachedDecimalPoint = false - - for (let i = 0; i < asString.length; i++) { - const char = asString[i] - - if (char === '.') { - reachedDecimalPoint = true - indexOfSignificantDigit = i + 1 - } else if (reachedDecimalPoint && char !== '0') { - indexOfSignificantDigit = i - break - } - } - - return asString.slice(0, indexOfSignificantDigit + digits) -} diff --git a/test/command/pss.spec.ts b/test/command/pss.spec.ts index aeb4971a..1dd12f52 100644 --- a/test/command/pss.spec.ts +++ b/test/command/pss.spec.ts @@ -1,6 +1,6 @@ +import { System } from 'cafe-utility' import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs' import { Receive } from '../../src/command/pss/receive' -import { sleep } from '../../src/utils' import { describeCommand, invokeTestCli } from '../utility' import { getWorkerPssAddress } from '../utility/address' import { getStampOption } from '../utility/stamp' @@ -19,7 +19,7 @@ async function sendAndExpect(message: string): Promise { '--timeout', '120000', ]) - await sleep(1000) + await System.sleepMillis(1000) await callSend(message, topic) const { receivedMessage } = (await receiveCommand).runnable as Receive expect(receivedMessage).toBe(message) @@ -68,7 +68,7 @@ describeCommand('Test PSS command', ({ getNthLastMessage, getLastMessage }) => { 'test/testconfig/in.txt', ...getStampOption(), ]) - await sleep(4000) + await System.sleepMillis(4000) expect(existsSync('test/testconfig/out.txt')).toBeTruthy() const messageFromFile = readFileSync('test/testconfig/out.txt', 'ascii') expect(messageFromFile).toBe('Message in a file') diff --git a/test/command/stake.spec.ts b/test/command/stake.spec.ts index 804c7c93..85f5616e 100644 --- a/test/command/stake.spec.ts +++ b/test/command/stake.spec.ts @@ -1,10 +1,10 @@ -import { describeCommand, invokeTestCli } from '../utility' import BigNumber from 'bignumber.js' +import { describeCommand, invokeTestCli } from '../utility' describeCommand('Test Stake command', ({ consoleMessages }) => { it('should print stake balance', async () => { await invokeTestCli(['stake']) - expect(consoleMessages[0]).toContain('Staked BZZ') + expect(consoleMessages[0]).toContain('Staked xBZZ') }) it('should print balance in quiet mode', async () => { diff --git a/test/command/stamp.spec.ts b/test/command/stamp.spec.ts index 9d1d6441..9fec9251 100644 --- a/test/command/stamp.spec.ts +++ b/test/command/stamp.spec.ts @@ -1,7 +1,6 @@ -import { Types } from 'cafe-utility' +import { System, Types } from 'cafe-utility' import inquirer from 'inquirer' import { Buy } from '../../src/command/stamp/buy' -import { sleep } from '../../src/utils' import { toMatchLinesInOrder } from '../custom-matcher' import { describeCommand, invokeTestCli } from '../utility' @@ -14,38 +13,32 @@ describeCommand( ({ consoleMessages, getLastMessage, getNthLastMessage, hasMessageContaining }) => { it('should list stamps', async () => { await invokeTestCli(['stamp', 'list']) - const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL'], ['Expires']] + const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) it('should show a specific stamp', async () => { await invokeTestCli(['stamp', 'show', Types.asString(process.env.STAMP)]) - const pattern = [ - ['Stamp ID', Types.asString(process.env.STAMP)], - ['Usage'], - ['Remaining Capacity'], - ['TTL'], - ['Expires'], - ] + const pattern = [['Stamp ID', Types.asString(process.env.STAMP)], ['Usage'], ['Remaining Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) it('should not allow buying stamp with amount 0', async () => { await invokeTestCli(['stamp', 'buy', '--amount', '0', '--depth', '20']) expect(getLastMessage()).toContain('[amount] must be at least 1') - await sleep(11_000) + await System.sleepMillis(11_000) }) it('should not allow buying stamp with depth 16', async () => { await invokeTestCli(['stamp', 'buy', '--amount', '1', '--depth', '16']) expect(getLastMessage()).toContain('[depth] must be at least 17') - await sleep(11_000) + await System.sleepMillis(11_000) }) it('should buy stamp', async () => { await invokeTestCli(['stamp', 'buy', '--amount', '100000', '--depth', '20', '--yes']) expect(getLastMessage()).toContain('Stamp ID:') - await sleep(11_000) + await System.sleepMillis(11_000) }) it('should buy stamp with immutable flag', async () => { @@ -66,7 +59,7 @@ describeCommand( await invokeTestCli(['stamp', 'show', id, '--verbose']) const pattern = [['Total Capacity (immutable)']] expect(consoleMessages).toMatchLinesInOrder(pattern) - await sleep(11_000) + await System.sleepMillis(11_000) }) it.skip('should print custom message when there are no stamps', async () => { @@ -76,7 +69,7 @@ describeCommand( it('should list with sorting and filter', async () => { await invokeTestCli(['stamp', 'list', '--min-usage', '0', '--max-usage', '100', '--least-used', '--limit', '1']) - const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL'], ['Expires']] + const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) @@ -112,7 +105,7 @@ describeCommand( const command = execution.runnable as Buy expect(command.yes).toBe(true) expect(inquirer.prompt).toHaveBeenCalledTimes(1) - await sleep(11_000) + await System.sleepMillis(11_000) }) it('should reject estimate cost prompt', async () => { @@ -121,7 +114,7 @@ describeCommand( const command = execution.runnable as Buy expect(command.yes).toBe(false) expect(inquirer.prompt).toHaveBeenCalledTimes(1) - await sleep(11_000) + await System.sleepMillis(11_000) }) it('should be possible to buy with underscores and units', async () => { @@ -139,7 +132,7 @@ describeCommand( const command = execution.runnable as Buy expect(command.yes).toBe(true) expect(getLastMessage()).toContain('Stamp ID:') - await sleep(11_000) + await System.sleepMillis(11_000) }) it.skip('should only be able to dilute stamp with greater depth', async () => { diff --git a/test/prompt/stamp-prompt.spec.ts b/test/prompt/stamp-prompt.spec.ts index bdc61bee..4cc5211a 100644 --- a/test/prompt/stamp-prompt.spec.ts +++ b/test/prompt/stamp-prompt.spec.ts @@ -6,7 +6,7 @@ describeCommand('Postage stamp price estimation prompt', ({ consoleMessages }) = it('stamp buy should prompt for price confirmation', async () => { jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'n' }) await invokeTestCli(['stamp', 'buy', '--depth', '24', '--amount', '596046400']) - expect(consoleMessages[0]).toBe('Estimated cost: 1.000 BZZ') + expect(consoleMessages[0]).toBe('Estimated cost: 1.000 xBZZ') expect(consoleMessages[1]).toBe('Estimated capacity: 64.00 GB') expect(consoleMessages[2]).toBe('Estimated TTL: 1 day 10 hours 29 minutes 36 seconds') expect(inquirer.prompt).toHaveBeenCalledWith({ diff --git a/test/utils/index.spec.ts b/test/utils/index.spec.ts deleted file mode 100644 index e0bb255b..00000000 --- a/test/utils/index.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import BigNumber from 'bignumber.js' -import { secondsToDhms, toSignificantDigits } from '../../src/utils' - -describe('utils', () => { - test('toSignificantDigits', () => { - expect(toSignificantDigits(BigNumber('0'))).toBe('0.0000') - expect(toSignificantDigits(BigNumber('100'))).toBe('100.0000') - expect(toSignificantDigits(BigNumber('0.123456789'))).toBe('0.1234') - expect(toSignificantDigits(BigNumber('0.0000100001'))).toBe('0.00001000') - expect(toSignificantDigits(BigNumber('123456789.123456789'))).toBe('123456789.1234') - }) - - test('secondsToDhms', () => { - expect(secondsToDhms(10)).toBe('10 seconds') - expect(secondsToDhms(61)).toBe('1 minute 1 second') - expect(secondsToDhms(3602)).toBe('1 hour 2 seconds') - expect(secondsToDhms(100000)).toBe('1 day 3 hours 46 minutes 40 seconds') - expect(secondsToDhms(10, true)).toBe('10 seconds') - expect(secondsToDhms(61, true)).toBe('1 minute') - expect(secondsToDhms(3602, true)).toBe('1 hour') - expect(secondsToDhms(100000, true)).toBe('1 day') - }) -}) From 55eacabd33e340ef4e6a126c2714fdc4f67e44ff Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:30:58 -0700 Subject: [PATCH 09/26] fix: set immutable stamps as default (#513) --- src/command/stamp/buy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/stamp/buy.ts b/src/command/stamp/buy.ts index c84ef435..f0586dcb 100644 --- a/src/command/stamp/buy.ts +++ b/src/command/stamp/buy.ts @@ -39,7 +39,7 @@ export class Buy extends StampCommand implements LeafCommand { }) public gasPrice!: bigint - @Option({ key: 'immutable', description: 'Disable stamp reuse', type: 'boolean' }) + @Option({ key: 'immutable', description: 'Disable stamp reuse', type: 'boolean', default: true }) public immutable!: boolean @Option({ key: 'label', description: 'Label of the postage stamp' }) From cf776abac64d8755dbf89c227efaac3f6921f8a4 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:37:28 -0700 Subject: [PATCH 10/26] feat: improve stamp capacity listing (#514) --- src/service/stamp/index.ts | 7 +++---- test/command/stamp.spec.ts | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/service/stamp/index.ts b/src/service/stamp/index.ts index 6b36124e..869d7d68 100644 --- a/src/service/stamp/index.ts +++ b/src/service/stamp/index.ts @@ -71,11 +71,10 @@ export function printStamp( console.log(createKeyValue('Label', stamp.label)) } console.log(createKeyValue('Usage', richStamp.usageText)) - console.log(createKeyValue('Remaining Capacity', richStamp.remainingCapacity.toString())) - console.verbose( + console.log( createKeyValue( - richStamp.immutableFlag ? 'Total Capacity (immutable)' : 'Total Capacity (mutable)', - richStamp.capacity.toString(), + richStamp.immutableFlag ? 'Capacity (immutable)' : 'Capacity (mutable)', + `${richStamp.remainingCapacity.toString()} remaining out of ${richStamp.capacity.toString()}`, ), ) diff --git a/test/command/stamp.spec.ts b/test/command/stamp.spec.ts index 9fec9251..20e4d4e5 100644 --- a/test/command/stamp.spec.ts +++ b/test/command/stamp.spec.ts @@ -13,13 +13,13 @@ describeCommand( ({ consoleMessages, getLastMessage, getNthLastMessage, hasMessageContaining }) => { it('should list stamps', async () => { await invokeTestCli(['stamp', 'list']) - const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL']] + const pattern = [['Stamp ID'], ['Usage'], ['Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) it('should show a specific stamp', async () => { await invokeTestCli(['stamp', 'show', Types.asString(process.env.STAMP)]) - const pattern = [['Stamp ID', Types.asString(process.env.STAMP)], ['Usage'], ['Remaining Capacity'], ['TTL']] + const pattern = [['Stamp ID', Types.asString(process.env.STAMP)], ['Usage'], ['Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) @@ -57,7 +57,7 @@ describeCommand( const id = command.postageBatchId await invokeTestCli(['stamp', 'show', id, '--verbose']) - const pattern = [['Total Capacity (immutable)']] + const pattern = [['Capacity (immutable)']] expect(consoleMessages).toMatchLinesInOrder(pattern) await System.sleepMillis(11_000) }) @@ -69,7 +69,7 @@ describeCommand( it('should list with sorting and filter', async () => { await invokeTestCli(['stamp', 'list', '--min-usage', '0', '--max-usage', '100', '--least-used', '--limit', '1']) - const pattern = [['Stamp ID'], ['Usage'], ['Remaining Capacity'], ['TTL']] + const pattern = [['Stamp ID'], ['Usage'], ['Capacity'], ['TTL']] expect(consoleMessages).toMatchLinesInOrder(pattern) }) From fb11c1985657d2bb45c371386a85127fb2afd5ff Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 08:58:27 -0700 Subject: [PATCH 11/26] feat: remove upload size warning (#515) --- src/command/upload.ts | 25 ------------------------- test/command/upload.spec.ts | 14 -------------- 2 files changed, 39 deletions(-) diff --git a/src/command/upload.ts b/src/command/upload.ts index b1b04840..b9a47f67 100644 --- a/src/command/upload.ts +++ b/src/command/upload.ts @@ -9,7 +9,6 @@ import { setCurlStore } from '../curl' import { pickStamp, printStamp } from '../service/stamp' import { fileExists, isGateway, readStdin } from '../utils' import { CommandLineError } from '../utils/error' -import { Message } from '../utils/message' import { getMime } from '../utils/mime' import { stampProperties } from '../utils/option' import { createSpinner } from '../utils/spinner' @@ -146,7 +145,6 @@ export class Upload extends RootCommand implements LeafCommand { } } - await this.maybeRunSizeChecks() await this.maybePrintRedundancyStats() const tag = this.sync ? await this.bee.createTag() : undefined @@ -330,29 +328,6 @@ export class Upload extends RootCommand implements LeafCommand { } } - private async maybeRunSizeChecks(): Promise { - if (this.yes) { - return - } - const size = await this.getUploadSize() - - if (size.getBytes() < MAX_UPLOAD_SIZE.getBytes()) { - return - } - - const message = `Size is larger than the recommended maximum value of ${MAX_UPLOAD_SIZE}` - - if (this.quiet) { - throw new CommandLineError(Message.requireOptionConfirmation('yes', message)) - } - - const confirmation = await this.console.confirm(message + ' Do you want to proceed?') - - if (!confirmation) { - exit(1) - } - } - private async maybePrintRedundancyStats(): Promise { if (!this.redundancy || this.quiet) { return diff --git a/test/command/upload.spec.ts b/test/command/upload.spec.ts index 0cb4245c..56503adc 100644 --- a/test/command/upload.spec.ts +++ b/test/command/upload.spec.ts @@ -55,20 +55,6 @@ describeCommand('Test Upload command', ({ consoleMessages, hasMessageContaining expect(inquirer.prompt).toHaveBeenCalledTimes(1) }) - it('should fail for large files in quiet mode', async () => { - await invokeTestCli(['upload', 'test/data/8mb.bin', '--quiet', ...getStampOption()]) - expect(consoleMessages[0]).toContain( - 'ERROR Size is larger than the recommended maximum value of 4.77 MB. Pass the --yes option to allow it', - ) - }) - - it('should fail for large folders in quiet mode', async () => { - await invokeTestCli(['upload', 'test/data', '--quiet', ...getStampOption()]) - expect(consoleMessages[0]).toContain( - 'ERROR Size is larger than the recommended maximum value of 4.77 MB. Pass the --yes option to allow it', - ) - }) - it('should not warn for large files with flag', async () => { await invokeTestCli(['upload', 'test/data/8mb.bin', '-v', '--yes', ...getStampOption()]) expect(hasMessageContaining('Uploading was successful!')).toBeTruthy() From 391ca6f18e29cb0e0abc290bef961bd61e2a616c Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:16:16 -0700 Subject: [PATCH 12/26] feat: print helpful message after topup and dilute (#516) --- src/command/stamp/dilute.ts | 6 ++++-- src/command/stamp/topup.ts | 6 ++++-- test/command/stamp.spec.ts | 6 ++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/command/stamp/dilute.ts b/src/command/stamp/dilute.ts index 44c373e4..88e3e3ff 100644 --- a/src/command/stamp/dilute.ts +++ b/src/command/stamp/dilute.ts @@ -37,7 +37,7 @@ export class Dilute extends StampCommand implements LeafCommand { throw new CommandLineError(`This postage stamp already has depth ${details.depth}. The new value must be higher.`) } - const spinner = createSpinner('Dilute in progress. This may take a while.') + const spinner = createSpinner('Dilute in progress. This may take a few minutes.') if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { spinner.start() @@ -49,6 +49,8 @@ export class Dilute extends StampCommand implements LeafCommand { spinner.stop() } - await this.printDepthAndAmount(this.stamp) + this.console.log(`Dilute finished. Your Bee node will soon synchronize the new values from the blockchain.`) + this.console.log(`This can take a few minutes until the value is updated.`) + this.console.log(`Check it later with swarm-cli stamp show ${this.stamp}`) } } diff --git a/src/command/stamp/topup.ts b/src/command/stamp/topup.ts index 36d57b64..f169a3e0 100644 --- a/src/command/stamp/topup.ts +++ b/src/command/stamp/topup.ts @@ -29,7 +29,7 @@ export class Topup extends StampCommand implements LeafCommand { this.stamp = await pickStamp(this.bee, this.console) } - const spinner = createSpinner('Topup in progress. This may take a while.') + const spinner = createSpinner('Topup in progress. This may take a few minutes.') if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { spinner.start() @@ -41,6 +41,8 @@ export class Topup extends StampCommand implements LeafCommand { spinner.stop() } - await this.printDepthAndAmount(this.stamp) + this.console.log(`Topup finished. Your Bee node will soon synchronize the new values from the blockchain.`) + this.console.log(`This can take a few minutes until the value is updated.`) + this.console.log(`Check it later with swarm-cli stamp show ${this.stamp}`) } } diff --git a/test/command/stamp.spec.ts b/test/command/stamp.spec.ts index 20e4d4e5..e31e325f 100644 --- a/test/command/stamp.spec.ts +++ b/test/command/stamp.spec.ts @@ -159,8 +159,7 @@ describeCommand( expect(hasMessageContaining('This postage stamp already has depth 19. The new value must be higher.')).toBe(true) consoleMessages.length = 0 await invokeTestCli(['stamp', 'dilute', '--stamp', postageBatchId, '--depth', '20']) - expect(getNthLastMessage(2)).toContain('Depth') - expect(getNthLastMessage(2)).toContain('20') + expect(getNthLastMessage(3)).toContain('Dilute finished') }) it.skip('should top up stamp', async () => { @@ -181,8 +180,7 @@ describeCommand( const { postageBatchId } = command consoleMessages.length = 0 await invokeTestCli(['stamp', 'topup', '--stamp', postageBatchId, '--amount', '1k']) - expect(getNthLastMessage(1)).toContain('Amount') - expect(getNthLastMessage(1)).toContain('2000') + expect(getNthLastMessage(3)).toContain('Topup finished') }) }, ) From 6de29f993df6a819c8e6ef816a5c759157f3280f Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:32:03 -0700 Subject: [PATCH 13/26] fix: do not error out on dev mode ttl (#517) --- src/service/stamp/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/service/stamp/index.ts b/src/service/stamp/index.ts index 869d7d68..73fea408 100644 --- a/src/service/stamp/index.ts +++ b/src/service/stamp/index.ts @@ -81,7 +81,9 @@ export function printStamp( if (settings?.showTtl) { const ttl = stamp.batchTTL === -1 ? 'unknown' : Dates.secondsToHumanTime(stamp.batchTTL) const expires = - stamp.batchTTL === -1 ? 'unknown' : new Date(Date.now() + stamp.batchTTL * 1000).toISOString().slice(0, 10) + stamp.batchTTL === -1 || stamp.batchTTL > 1e11 + ? 'unknown' + : new Date(Date.now() + stamp.batchTTL * 1000).toISOString().slice(0, 10) console.log(createKeyValue('TTL', `${ttl} (${expires})`)) } From 1fefbc3220c9225a199ec5a0168f04945af9fbaf Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:38:04 -0700 Subject: [PATCH 14/26] refactor: remove bignumber.js dependency (#518) --- package-lock.json | 14 -------------- package.json | 1 - test/command/stake.spec.ts | 7 +++---- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index cd6c1400..0c2c20d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@ethersphere/bee-js": "^7.0.3", "@fairdatasociety/bmt-js": "^2.1.0", - "bignumber.js": "^9.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", @@ -2946,14 +2945,6 @@ "tweetnacl": "^0.14.3" } }, - "node_modules/bignumber.js": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.0.tgz", - "integrity": "sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A==", - "engines": { - "node": "*" - } - }, "node_modules/bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", @@ -11987,11 +11978,6 @@ "tweetnacl": "^0.14.3" } }, - "bignumber.js": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.0.tgz", - "integrity": "sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A==" - }, "bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", diff --git a/package.json b/package.json index b41d8f3c..74bcd461 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "dependencies": { "@ethersphere/bee-js": "^7.0.3", "@fairdatasociety/bmt-js": "^2.1.0", - "bignumber.js": "^9.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", "cli-progress": "^3.11.2", diff --git a/test/command/stake.spec.ts b/test/command/stake.spec.ts index 85f5616e..d728b62c 100644 --- a/test/command/stake.spec.ts +++ b/test/command/stake.spec.ts @@ -1,4 +1,3 @@ -import BigNumber from 'bignumber.js' import { describeCommand, invokeTestCli } from '../utility' describeCommand('Test Stake command', ({ consoleMessages }) => { @@ -10,9 +9,9 @@ describeCommand('Test Stake command', ({ consoleMessages }) => { it('should print balance in quiet mode', async () => { await invokeTestCli(['stake', '--quiet']) - const initialStake = BigNumber(consoleMessages[0]) + const initialStake = parseFloat(consoleMessages[0]) await invokeTestCli(['stake', '--quiet', '--deposit', '100_000T']) - const afterDepositStake = BigNumber(consoleMessages[1]) - expect(afterDepositStake.minus(initialStake).isEqualTo(10)).toEqual(true) + const afterDepositStake = parseFloat(consoleMessages[1]) + expect(afterDepositStake).toBeGreaterThan(initialStake) }) }) From 764f958f01efdbf2d934d0e49c8b735b18804426 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 09:51:20 -0700 Subject: [PATCH 15/26] feat: add cheque withdraw-all command (#519) * feat: add cheque withdraw-all command * feat: print more info * style: newline * style: newline --- src/command/cheque/index.ts | 3 ++- src/command/cheque/withdraw-all.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/command/cheque/withdraw-all.ts diff --git a/src/command/cheque/index.ts b/src/command/cheque/index.ts index 808de981..0c605099 100644 --- a/src/command/cheque/index.ts +++ b/src/command/cheque/index.ts @@ -3,11 +3,12 @@ import { Cashout } from './cashout' import { Deposit } from './deposit' import { List } from './list' import { Withdraw } from './withdraw' +import { WithdrawAll } from './withdraw-all' export class Cheque implements GroupCommand { public readonly name = 'cheque' public readonly description = 'Deposit, withdraw and manage cheques' - public subCommandClasses = [List, Cashout, Deposit, Withdraw] + public subCommandClasses = [List, Cashout, Deposit, Withdraw, WithdrawAll] } diff --git a/src/command/cheque/withdraw-all.ts b/src/command/cheque/withdraw-all.ts new file mode 100644 index 00000000..38bbb690 --- /dev/null +++ b/src/command/cheque/withdraw-all.ts @@ -0,0 +1,28 @@ +import { Numbers } from 'cafe-utility' +import { LeafCommand } from 'furious-commander' +import { createKeyValue } from '../../utils/text' +import { ChequeCommand } from './cheque-command' + +export class WithdrawAll extends ChequeCommand implements LeafCommand { + public readonly name = 'withdraw-all' + + public readonly alias = 'wa' + + public readonly description = 'Withdraw all available tokens from the chequebook to the overlay address' + + public async run(): Promise { + await super.init() + + const balance = await this.bee.getChequebookBalance() + + if (balance.availableBalance === '0') { + this.console.error('No tokens to withdraw.') + + return + } + this.console.log(`Withdrawing ${Numbers.fromDecimals(balance.availableBalance, 16)} xBZZ from the chequebook`) + const response = await this.bee.withdrawTokens(balance.availableBalance) + this.console.log(createKeyValue('Tx', response)) + this.console.quiet(response) + } +} From 3907a4d838aff2d206ede94503ff02a93d0ec753 Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Wed, 26 Jun 2024 19:37:56 +0200 Subject: [PATCH 16/26] chore: release 2.12.0 (#512) --- CHANGELOG.md | 17 +++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e2f0cc..8b761162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [2.12.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.11.0...v2.12.0) (2024-06-26) + + +### Features + +* add cheque withdraw-all command ([#519](https://www.github.com/ethersphere/swarm-cli/issues/519)) ([764f958](https://www.github.com/ethersphere/swarm-cli/commit/764f958f01efdbf2d934d0e49c8b735b18804426)) +* disambiguate xdai and xbzz values ([#511](https://www.github.com/ethersphere/swarm-cli/issues/511)) ([c0a5337](https://www.github.com/ethersphere/swarm-cli/commit/c0a53379cdb1e0558659f3e6d8386ebe5a4034c1)) +* improve stamp capacity listing ([#514](https://www.github.com/ethersphere/swarm-cli/issues/514)) ([cf776ab](https://www.github.com/ethersphere/swarm-cli/commit/cf776abac64d8755dbf89c227efaac3f6921f8a4)) +* print helpful message after topup and dilute ([#516](https://www.github.com/ethersphere/swarm-cli/issues/516)) ([391ca6f](https://www.github.com/ethersphere/swarm-cli/commit/391ca6f18e29cb0e0abc290bef961bd61e2a616c)) +* remove upload size warning ([#515](https://www.github.com/ethersphere/swarm-cli/issues/515)) ([fb11c19](https://www.github.com/ethersphere/swarm-cli/commit/fb11c1985657d2bb45c371386a85127fb2afd5ff)) + + +### Bug Fixes + +* do not error out on dev mode ttl ([#517](https://www.github.com/ethersphere/swarm-cli/issues/517)) ([6de29f9](https://www.github.com/ethersphere/swarm-cli/commit/6de29f993df6a819c8e6ef816a5c759157f3280f)) +* set immutable stamps as default ([#513](https://www.github.com/ethersphere/swarm-cli/issues/513)) ([55eacab](https://www.github.com/ethersphere/swarm-cli/commit/55eacabd33e340ef4e6a126c2714fdc4f67e44ff)) + ## [2.11.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.10.0...v2.11.0) (2024-06-18) diff --git a/package-lock.json b/package-lock.json index 0c2c20d9..7bab3507 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.11.0", + "version": "2.12.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.11.0", + "version": "2.12.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.0.3", diff --git a/package.json b/package.json index 74bcd461..bfd0c0f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.11.0", + "version": "2.12.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From 01bc9b7d1476000c6a85fd25eb68d679796e99dc Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:11:23 -0700 Subject: [PATCH 17/26] fix: do not require stamp for feed print (#520) --- src/command/feed/feed-command.ts | 17 +++++------- src/command/feed/print.ts | 45 +++++++++++++++++++++++--------- src/command/feed/update.ts | 6 ++++- src/command/feed/upload.ts | 8 ++++-- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/command/feed/feed-command.ts b/src/command/feed/feed-command.ts index 4bfdba40..397a92a1 100644 --- a/src/command/feed/feed-command.ts +++ b/src/command/feed/feed-command.ts @@ -5,7 +5,7 @@ import { exit } from 'process' import { getWalletFromIdentity, pickIdentity } from '../../service/identity' import { Identity } from '../../service/identity/types' import { printStamp } from '../../service/stamp' -import { stampProperties, topicProperties, topicStringProperties } from '../../utils/option' +import { topicProperties, topicStringProperties } from '../../utils/option' import { createSpinner } from '../../utils/spinner' import { createKeyValue } from '../../utils/text' import { RootCommand } from '../root-command' @@ -17,9 +17,6 @@ interface FeedInfo { } export class FeedCommand extends RootCommand { - @Option(stampProperties) - public stamp!: string - @Option({ key: 'identity', alias: 'i', @@ -38,10 +35,10 @@ export class FeedCommand extends RootCommand { @Option({ key: 'password', alias: 'P', description: 'Password for the wallet' }) public password!: string - protected async updateFeedAndPrint(chunkReference: string): Promise { + protected async updateFeedAndPrint(stamp: string, chunkReference: string): Promise { const wallet = await this.getWallet() const topic = this.topic || this.bee.makeFeedTopic(this.topicString) - const { reference, manifest } = await this.writeFeed(wallet, topic, chunkReference) + const { reference, manifest } = await this.writeFeed(stamp, wallet, topic, chunkReference) this.console.verbose(createKeyValue('Chunk Reference', chunkReference)) this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${chunkReference}/`)) @@ -52,7 +49,7 @@ export class FeedCommand extends RootCommand { this.console.quiet(manifest) if (!this.quiet) { - printStamp(await this.bee.getPostageBatch(this.stamp), this.console, { shortenBatchId: true }) + printStamp(await this.bee.getPostageBatch(stamp), this.console, { shortenBatchId: true }) } return manifest @@ -79,7 +76,7 @@ export class FeedCommand extends RootCommand { return identities[this.identity] || identities[await pickIdentity(this.commandConfig, this.console)] } - private async writeFeed(wallet: Wallet, topic: string, chunkReference: string): Promise { + private async writeFeed(stamp: string, wallet: Wallet, topic: string, chunkReference: string): Promise { const spinner = createSpinner('Writing feed...') if (this.verbosity !== VerbosityLevel.Quiet && !this.curl) { @@ -88,9 +85,9 @@ export class FeedCommand extends RootCommand { try { const writer = this.bee.makeFeedWriter('sequence', topic, wallet.getPrivateKey()) - const reference = await writer.upload(this.stamp, chunkReference as Reference) + const reference = await writer.upload(stamp, chunkReference as Reference) const { reference: manifest } = await this.bee.createFeedManifest( - this.stamp, + stamp, 'sequence', topic, wallet.getAddressString(), diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index d0b76b44..753163ef 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -1,9 +1,10 @@ +import { makeChunk } from '@fairdatasociety/bmt-js' +import { Binary } from 'cafe-utility' import Wallet from 'ethereumjs-wallet' import { LeafCommand, Option } from 'furious-commander' import { exit } from 'process' import { isSimpleWallet, isV3Wallet } from '../../service/identity' import { Identity } from '../../service/identity/types' -import { pickStamp } from '../../service/stamp' import { getFieldOrNull } from '../../utils' import { createSpinner } from '../../utils/spinner' import { createKeyValue } from '../../utils/text' @@ -28,21 +29,43 @@ export class Print extends FeedCommand implements LeafCommand { await super.init() const topic = this.topic || this.bee.makeFeedTopic(this.topicString) + + const body = Binary.concatBytes( + new Uint8Array(32), + new Uint8Array([ + 0x57, 0x68, 0xb3, 0xb6, 0xa7, 0xdb, 0x56, 0xd2, 0x1d, 0x1a, 0xbf, 0xf4, 0x0d, 0x41, 0xce, 0xbf, 0xc8, 0x34, + 0x48, 0xfe, 0xd8, 0xd7, 0xe9, 0xb0, 0x6e, 0xc0, 0xd3, 0xb0, 0x73, 0xf2, 0x8f, 0x20, + ]), + new Uint8Array(37), + new Uint8Array([0x80]), + new Uint8Array(26), + new Uint8Array([0x12, 0x01, 0x2f]), + new Uint8Array(29), + new Uint8Array([ + 0x85, 0x04, 0xf2, 0xa1, 0x07, 0xca, 0x94, 0x0b, 0xea, 0xfc, 0x4c, 0xe2, 0xf6, 0xc9, 0xa9, 0xf0, 0x96, 0x8c, + 0x62, 0xa5, 0xb5, 0x89, 0x3f, 0xf0, 0xe4, 0xe1, 0xe2, 0x98, 0x30, 0x48, 0xd2, 0x76, 0x00, 0xbe, + ]), + new TextEncoder().encode( + `{"swarm-feed-owner":"${this.address}","swarm-feed-topic":"${this.topic}","swarm-feed-type":"Sequence"}`, + ), + new Uint8Array(12).fill(0x0a), + ) + + const manifest = Binary.uint8ArrayToHex(makeChunk(body).address()) + this.console.quiet(manifest) + + if (this.quiet) { + return + } + this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`)) + const spinner = createSpinner(`Looking up feed topic ${topic}`) spinner.start() + try { const addressString = this.address || (await this.getAddressString()) const reader = this.bee.makeFeedReader('sequence', topic, addressString) const { reference, feedIndex, feedIndexNext } = await reader.download() - - if (!this.stamp) { - spinner.stop() - this.stamp = await pickStamp(this.bee, this.console) - spinner.start() - } - - const { reference: manifest } = await this.bee.createFeedManifest(this.stamp, 'sequence', topic, addressString) - spinner.stop() this.console.verbose(createKeyValue('Chunk Reference', reference)) this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`)) @@ -50,9 +73,7 @@ export class Print extends FeedCommand implements LeafCommand { 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 as string, 16) + 1)) } catch (error) { spinner.stop() diff --git a/src/command/feed/update.ts b/src/command/feed/update.ts index c4dbd5d4..a46ae421 100644 --- a/src/command/feed/update.ts +++ b/src/command/feed/update.ts @@ -1,5 +1,6 @@ import { LeafCommand, Option } from 'furious-commander' import { pickStamp } from '../../service/stamp' +import { stampProperties } from '../../utils/option' import { FeedCommand } from './feed-command' export class Update extends FeedCommand implements LeafCommand { @@ -7,6 +8,9 @@ export class Update extends FeedCommand implements LeafCommand { public readonly description = 'Update feed' + @Option(stampProperties) + public stamp!: string + @Option({ key: 'reference', alias: 'r', description: 'The new reference', required: true }) public reference!: string @@ -17,7 +21,7 @@ export class Update extends FeedCommand implements LeafCommand { this.stamp = await pickStamp(this.bee, this.console) } - await this.updateFeedAndPrint(this.reference) + await this.updateFeedAndPrint(this.stamp, this.reference) this.console.dim('Successfully updated feed.') } } diff --git a/src/command/feed/upload.ts b/src/command/feed/upload.ts index 03207637..c9590031 100644 --- a/src/command/feed/upload.ts +++ b/src/command/feed/upload.ts @@ -1,5 +1,6 @@ -import { Aggregation, LeafCommand } from 'furious-commander' +import { Aggregation, LeafCommand, Option } from 'furious-commander' import { pickStamp } from '../../service/stamp' +import { stampProperties } from '../../utils/option' import { Upload as FileUpload } from '../upload' import { FeedCommand } from './feed-command' @@ -13,6 +14,9 @@ export class Upload extends FeedCommand implements LeafCommand { @Aggregation(['upload']) public fileUpload!: FileUpload + @Option(stampProperties) + public stamp!: string + public async run(): Promise { await super.init() @@ -23,7 +27,7 @@ export class Upload extends FeedCommand implements LeafCommand { } const reference = await this.runUpload() - this.feedManifest = await this.updateFeedAndPrint(reference) + this.feedManifest = await this.updateFeedAndPrint(this.stamp, reference) this.console.dim('Successfully uploaded to feed.') } From 972c750edfa73accade0481ff8fd7794e1e17449 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:53:43 -0700 Subject: [PATCH 18/26] feat: print feed update references (#522) --- src/command/feed/print.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index 753163ef..de514d23 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -1,3 +1,4 @@ +import { Utils } from '@ethersphere/bee-js' import { makeChunk } from '@fairdatasociety/bmt-js' import { Binary } from 'cafe-utility' import Wallet from 'ethereumjs-wallet' @@ -25,11 +26,15 @@ export class Print extends FeedCommand implements LeafCommand { }) public address!: string + @Option({ key: 'list', type: 'boolean', description: 'List all updates' }) + public list!: boolean + public async run(): Promise { await super.init() const topic = this.topic || this.bee.makeFeedTopic(this.topicString) + // construct the feed manifest chunk const body = Binary.concatBytes( new Uint8Array(32), new Uint8Array([ @@ -74,7 +79,25 @@ export class Print extends FeedCommand implements LeafCommand { this.console.verbose(createKeyValue('Feed Manifest', manifest)) this.console.log(createKeyValue('Topic', `${topic}`)) - this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex as string, 16) + 1)) + const numberOfUpdates = parseInt(feedIndex as string, 16) + 1 + this.console.log(createKeyValue('Number of Updates', numberOfUpdates)) + + if (this.list) { + for (let i = 0; i < numberOfUpdates; i++) { + const indexBytes = Binary.numberToUint64BE(i) + const identifier = Utils.keccak256Hash(Binary.hexToUint8Array(topic), indexBytes) + const owner = Binary.hexToUint8Array(this.address) + const soc = Binary.uint8ArrayToHex(Utils.keccak256Hash(identifier, owner)) + const chunk = await this.bee.downloadChunk(soc) + // span + identifier + signature + span + const cac = Binary.uint8ArrayToHex(chunk.slice(8 + 32 + 65 + 8, 8 + 32 + 65 + 32 + 8)) + this.console.log('') + this.console.log(createKeyValue(`Update ${i}`, cac)) + this.console.log(`${this.bee.url}/bzz/${cac}/`) + } + } else { + this.console.log('Run with --list to see all updates') + } } catch (error) { spinner.stop() const message = getFieldOrNull(error, 'message') From 167678757516910bdf1c863ae6176619635bca6e Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Thu, 27 Jun 2024 01:55:27 +0200 Subject: [PATCH 19/26] chore: release 2.13.0 (#523) --- CHANGELOG.md | 12 ++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b761162..01e8d330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [2.13.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.12.0...v2.13.0) (2024-06-26) + + +### Features + +* print feed update references ([#522](https://www.github.com/ethersphere/swarm-cli/issues/522)) ([972c750](https://www.github.com/ethersphere/swarm-cli/commit/972c750edfa73accade0481ff8fd7794e1e17449)) + + +### Bug Fixes + +* do not require stamp for feed print ([#520](https://www.github.com/ethersphere/swarm-cli/issues/520)) ([01bc9b7](https://www.github.com/ethersphere/swarm-cli/commit/01bc9b7d1476000c6a85fd25eb68d679796e99dc)) + ## [2.12.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.11.0...v2.12.0) (2024-06-26) diff --git a/package-lock.json b/package-lock.json index 7bab3507..39871745 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.12.0", + "version": "2.13.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.12.0", + "version": "2.13.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.0.3", diff --git a/package.json b/package.json index bfd0c0f4..2068129c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.12.0", + "version": "2.13.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From 8f633c035ed2367cb3d789d90bfea0ce4e21ea4d Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Thu, 8 Aug 2024 03:45:58 -0700 Subject: [PATCH 20/26] fix: support identity in feed print (#526) * fix: support identity in feed print * fix: use topic and remove 0x --- src/command/feed/print.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/command/feed/print.ts b/src/command/feed/print.ts index de514d23..5b682140 100644 --- a/src/command/feed/print.ts +++ b/src/command/feed/print.ts @@ -32,6 +32,11 @@ export class Print extends FeedCommand implements LeafCommand { public async run(): Promise { await super.init() + if (!this.address) { + const wallet = await this.getWallet() + this.address = wallet.getAddressString() + } + const topic = this.topic || this.bee.makeFeedTopic(this.topicString) // construct the feed manifest chunk @@ -51,7 +56,10 @@ export class Print extends FeedCommand implements LeafCommand { 0x62, 0xa5, 0xb5, 0x89, 0x3f, 0xf0, 0xe4, 0xe1, 0xe2, 0x98, 0x30, 0x48, 0xd2, 0x76, 0x00, 0xbe, ]), new TextEncoder().encode( - `{"swarm-feed-owner":"${this.address}","swarm-feed-topic":"${this.topic}","swarm-feed-type":"Sequence"}`, + `{"swarm-feed-owner":"${this.address.replace( + '0x', + '', + )}","swarm-feed-topic":"${topic}","swarm-feed-type":"Sequence"}`, ), new Uint8Array(12).fill(0x0a), ) From b40da21556c4dfd0d5f4706e029787db7ac7d009 Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Thu, 8 Aug 2024 12:50:23 +0200 Subject: [PATCH 21/26] chore: release 2.13.1 (#527) --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01e8d330..bd69298a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +### [2.13.1](https://www.github.com/ethersphere/swarm-cli/compare/v2.13.0...v2.13.1) (2024-08-08) + + +### Bug Fixes + +* support identity in feed print ([#526](https://www.github.com/ethersphere/swarm-cli/issues/526)) ([8f633c0](https://www.github.com/ethersphere/swarm-cli/commit/8f633c035ed2367cb3d789d90bfea0ce4e21ea4d)) + ## [2.13.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.12.0...v2.13.0) (2024-06-26) diff --git a/package-lock.json b/package-lock.json index 39871745..5c0db9be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.13.0", + "version": "2.13.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.13.0", + "version": "2.13.1", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.0.3", diff --git a/package.json b/package.json index 2068129c..677aa244 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.13.0", + "version": "2.13.1", "description": "CLI tool for Bee", "keywords": [ "Bee", From b00a6e9b824bb13bcf2482f954118d92d46b6e67 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 11 Sep 2024 02:54:31 -0700 Subject: [PATCH 22/26] feat: update to bee-js 7.1.2 (#528) --- package-lock.json | 15 ++++++++------- package.json | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c0db9be..5497bf67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.13.1", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^7.0.3", + "@ethersphere/bee-js": "^7.1.2", "@fairdatasociety/bmt-js": "^2.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", @@ -1226,9 +1226,10 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.3.tgz", - "integrity": "sha512-1Z19V6AJey6BScvIg7/kb464B9oPS6/nIrvEODWEJTXsaC/DBXAdQhR76ypvhrW3ldbwT5NVDA0HEfc9QekVEw==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.1.2.tgz", + "integrity": "sha512-Q4F7G5litzXiZeVMLzCUmlRcJhPrR3r01Tf71cRYZ7Zj/PEpUib8fM5gthsKvcd9UT4MXJUfkxmLcyd+LkLiIQ==", + "license": "BSD-3-Clause", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", "axios": "^0.28.1", @@ -10653,9 +10654,9 @@ } }, "@ethersphere/bee-js": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.0.3.tgz", - "integrity": "sha512-1Z19V6AJey6BScvIg7/kb464B9oPS6/nIrvEODWEJTXsaC/DBXAdQhR76ypvhrW3ldbwT5NVDA0HEfc9QekVEw==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.1.2.tgz", + "integrity": "sha512-Q4F7G5litzXiZeVMLzCUmlRcJhPrR3r01Tf71cRYZ7Zj/PEpUib8fM5gthsKvcd9UT4MXJUfkxmLcyd+LkLiIQ==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "axios": "^0.28.1", diff --git a/package.json b/package.json index 677aa244..2042949b 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^7.0.3", + "@ethersphere/bee-js": "^7.1.2", "@fairdatasociety/bmt-js": "^2.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", From 4067a193a21bac9ae38b8e75a182fc07aa110f81 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Wed, 11 Sep 2024 03:03:42 -0700 Subject: [PATCH 23/26] feat: allow setting default stamp with stamp env (#530) --- src/utils/option.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/option.ts b/src/utils/option.ts index c200b373..eee8f591 100644 --- a/src/utils/option.ts +++ b/src/utils/option.ts @@ -2,6 +2,7 @@ import { IOption } from 'furious-commander' export const stampProperties: IOption = { key: 'stamp', + envKey: 'STAMP', type: 'hex-string', length: 64, description: 'ID of the postage stamp to use', From 930b3a32aabc07d6141e2d0212308d60568e8210 Mon Sep 17 00:00:00 2001 From: bee-worker <70210089+bee-worker@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:05:12 +0200 Subject: [PATCH 24/26] chore: release 2.14.0 (#529) --- CHANGELOG.md | 8 ++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd69298a..8a3b7965 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.14.0](https://www.github.com/ethersphere/swarm-cli/compare/v2.13.1...v2.14.0) (2024-09-11) + + +### Features + +* allow setting default stamp with stamp env ([#530](https://www.github.com/ethersphere/swarm-cli/issues/530)) ([4067a19](https://www.github.com/ethersphere/swarm-cli/commit/4067a193a21bac9ae38b8e75a182fc07aa110f81)) +* update to bee-js 7.1.2 ([#528](https://www.github.com/ethersphere/swarm-cli/issues/528)) ([b00a6e9](https://www.github.com/ethersphere/swarm-cli/commit/b00a6e9b824bb13bcf2482f954118d92d46b6e67)) + ### [2.13.1](https://www.github.com/ethersphere/swarm-cli/compare/v2.13.0...v2.13.1) (2024-08-08) diff --git a/package-lock.json b/package-lock.json index 5497bf67..aa9ed521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.13.1", + "version": "2.14.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ethersphere/swarm-cli", - "version": "2.13.1", + "version": "2.14.0", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/bee-js": "^7.1.2", diff --git a/package.json b/package.json index 2042949b..6fa88272 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ethersphere/swarm-cli", - "version": "2.13.1", + "version": "2.14.0", "description": "CLI tool for Bee", "keywords": [ "Bee", From e8b18422c0b72383e51c41596b2b10f85b2529b1 Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Mon, 16 Sep 2024 01:42:52 -0700 Subject: [PATCH 25/26] feat: upgrade to bee-js 8 (#531) * feat: upgrade to bee-js 8 * chore: add new line --- package-lock.json | 14 +++++++------- package.json | 2 +- src/command/feed/feed-command.ts | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index aa9ed521..d2c0ba75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.14.0", "license": "BSD-3-Clause", "dependencies": { - "@ethersphere/bee-js": "^7.1.2", + "@ethersphere/bee-js": "^8.0.0", "@fairdatasociety/bmt-js": "^2.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", @@ -1226,9 +1226,9 @@ } }, "node_modules/@ethersphere/bee-js": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.1.2.tgz", - "integrity": "sha512-Q4F7G5litzXiZeVMLzCUmlRcJhPrR3r01Tf71cRYZ7Zj/PEpUib8fM5gthsKvcd9UT4MXJUfkxmLcyd+LkLiIQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-8.0.0.tgz", + "integrity": "sha512-+Vii3Pxa+eQ0HPMhzlHFq/7NoOqQl3DZk/ENVw3ddzr78uWvi0ZQRk7SObrq09Z0BqmA0kxyr9nOexNcx+kXJw==", "license": "BSD-3-Clause", "dependencies": { "@ethersphere/swarm-cid": "^0.1.0", @@ -10654,9 +10654,9 @@ } }, "@ethersphere/bee-js": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-7.1.2.tgz", - "integrity": "sha512-Q4F7G5litzXiZeVMLzCUmlRcJhPrR3r01Tf71cRYZ7Zj/PEpUib8fM5gthsKvcd9UT4MXJUfkxmLcyd+LkLiIQ==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-8.0.0.tgz", + "integrity": "sha512-+Vii3Pxa+eQ0HPMhzlHFq/7NoOqQl3DZk/ENVw3ddzr78uWvi0ZQRk7SObrq09Z0BqmA0kxyr9nOexNcx+kXJw==", "requires": { "@ethersphere/swarm-cid": "^0.1.0", "axios": "^0.28.1", diff --git a/package.json b/package.json index 6fa88272..d998122c 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "typescript": "^4.8.4" }, "dependencies": { - "@ethersphere/bee-js": "^7.1.2", + "@ethersphere/bee-js": "^8.0.0", "@fairdatasociety/bmt-js": "^2.1.0", "cafe-utility": "^22.0.0", "chalk": "^2.4.2", diff --git a/src/command/feed/feed-command.ts b/src/command/feed/feed-command.ts index 397a92a1..1a429762 100644 --- a/src/command/feed/feed-command.ts +++ b/src/command/feed/feed-command.ts @@ -85,13 +85,13 @@ export class FeedCommand extends RootCommand { try { const writer = this.bee.makeFeedWriter('sequence', topic, wallet.getPrivateKey()) - const reference = await writer.upload(stamp, chunkReference as Reference) const { reference: manifest } = await this.bee.createFeedManifest( stamp, 'sequence', topic, wallet.getAddressString(), ) + const { reference } = await writer.upload(stamp, chunkReference as Reference) return { reference, manifest } } finally { From 05cb0ed83dc69cbc964d18630feffd26da8c12ba Mon Sep 17 00:00:00 2001 From: Cafe137 <77121044+Cafe137@users.noreply.github.com> Date: Mon, 16 Sep 2024 05:36:48 -0700 Subject: [PATCH 26/26] fix: handle missing chequebook in addresses command (#534) * fix: handle missing chequebook in addresses command * style: add newline --- src/command/addresses.ts | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/command/addresses.ts b/src/command/addresses.ts index a6596050..5af5be39 100644 --- a/src/command/addresses.ts +++ b/src/command/addresses.ts @@ -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' @@ -11,13 +12,23 @@ export class Addresses extends RootCommand implements LeafCommand { public nodeAddresses!: NodeAddresses - public chequebookAddress!: string - public async run(): Promise { 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() + }) const longest = 'PSS Public Key'.length this.console.log(chalk.bold('Node Addresses')) @@ -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) + }) } }