From: Steve Myers Date: Fri, 6 Aug 2021 01:35:17 +0000 (-0700) Subject: Add cli feature and make it required for bin build X-Git-Tag: v0.3.0~27 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/enum.FromScriptError.html?a=commitdiff_plain;h=85c7201d2c2bce9f91f28d4f146d3258e5535f7e;p=bdk-cli Add cli feature and make it required for bin build --- diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index a4e0441..af0b4f3 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -14,7 +14,6 @@ jobs: - 1.46.0 # MSRV features: - default - - repl - electrum - esplora - compiler @@ -40,11 +39,11 @@ jobs: override: true components: rustfmt, clippy - name: Build - run: cargo build --features ${{ matrix.features }} --no-default-features --locked + run: cargo build --features ${{ matrix.features }} --locked - name: Clippy run: cargo clippy -- -D warnings - name: Test - run: cargo test --features ${{ matrix.features }} --no-default-features + run: cargo test --features ${{ matrix.features }} fmt: name: Rust fmt diff --git a/Cargo.lock b/Cargo.lock index 173963b..8e1e8fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,7 @@ dependencies = [ "rustyline", "serde_json", "structopt", + "zeroize", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 507c2f5..aa52095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,9 @@ clap = { version = "2.33", optional = true } regex = {version = "1", optional = true } [features] -default = ["repl", "electrum"] -repl = ["bdk/key-value-db", "clap", "dirs-next", "env_logger", "regex", "rustyline"] +default = ["cli", "repl"] +cli = ["bdk/key-value-db", "clap", "dirs-next", "env_logger"] +repl = ["regex", "rustyline"] electrum = ["bdk/electrum"] esplora = ["bdk/esplora"] compiler = ["bdk/compiler"] @@ -39,7 +40,7 @@ compact_filters = ["bdk/compact_filters"] [[bin]] name = "bdk-cli" path = "src/bdk_cli.rs" -required-features = ["repl"] +required-features = ["cli"] [package.metadata.docs.rs] features = ["compiler"] diff --git a/README.md b/README.md index 1855ed0..484d08a 100644 --- a/README.md +++ b/README.md @@ -10,28 +10,31 @@ wallet tool based on the [bdk](https://github.com/bitcoindevkit/bdk) library. ## Install bdk-cli ### From source -To install dev version of `bdk-cli` from local git repo: +To install dev version of `bdk-cli` from local git repo with the `electrum` blockchain client enabled: ```shell cd -cargo install --path . +cargo install --path . --features electrum bdk-cli help # to verify it worked ``` -By default the `electrum` client feature is enabled, to use the `esplora` or another blockchain backend -client instead the default features must be disabled and the desired client feature enabled. Below -is an example of how to enable the `esplora` blockchain client feature instead of `electrum`. +If no blockchain client feature is enabled online wallet commands `sync` and `broadcast` will be +disabled. To enable these commands a blockchain client features such as `electrum` or another +blockchain backend feature must be enabled. Below is an example of how run the `bdk-cli` bin with +the `esplora` blockchain client feature. ```shell -RUST_LOG=debug cargo run --no-default-features --features repl,esplora -- wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync +RUST_LOG=debug cargo run --features esplora -- wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync ``` -If no blockchain client feature is enabled then online wallet commands are disabled. +At most one blockchain feature can be enabled, available blockchain client features are: +`electrum`, `esplora`, and `compact_filters`. ### From crates.io -You can the install the binaries for the latest tag of `bdk-cli` directly from [crates.io](https://crates.io/crates/bdk-cli) like so: +You can the install the binaries for the latest tag of `bdk-cli` with online wallet features +directly from [crates.io](https://crates.io/crates/bdk-cli) with a command as below: ```sh -cargo install bdk-cli +cargo install bdk-cli --features `electrum` ``` ### bdk-cli bin usage examples @@ -46,7 +49,7 @@ cargo run To sync a wallet to the default electrum server: ```shell -cargo run -- wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync +cargo run --features electrum -- wallet --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync ``` To sync a wallet to Bitcoin Core node (assuming a regtest node at 127.0.0.1:18444) serving compact filters: @@ -55,7 +58,7 @@ Note: - Bitcoin Core v0.21.0 or higher is required to serve compact filters. ```shell -cargo run --no-default-features --features repl,compact_filters -- --network regtest wallet --node 127.0.0.1:18444 --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync +cargo run --features compact_filters -- --network regtest wallet --node 127.0.0.1:18444 --descriptor "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/*)" sync ``` To get a wallet balance with customized logging: diff --git a/src/bdk_cli.rs b/src/bdk_cli.rs index 88d4bef..be19a7f 100644 --- a/src/bdk_cli.rs +++ b/src/bdk_cli.rs @@ -28,8 +28,12 @@ use std::path::PathBuf; use bitcoin::Network; use clap::AppSettings; use log::{debug, error, info, warn}; + +#[cfg(feature = "repl")] use rustyline::error::ReadlineError; +#[cfg(feature = "repl")] use rustyline::Editor; + use structopt::StructOpt; #[cfg(feature = "compact_filters")] @@ -53,8 +57,10 @@ use bdk_cli::{CliOpts, CliSubCommand, KeySubCommand, OfflineWalletSubCommand, Wa #[cfg(any(feature = "electrum", feature = "esplora", feature = "compact_filters"))] use bdk_cli::OnlineWalletSubCommand; +#[cfg(feature = "repl")] use regex::Regex; +#[cfg(feature = "repl")] const REPL_LINE_SPLIT_REGEX: &str = r#""([^"]*)"|'([^']*)'|([\w\-]+)"#; /// REPL mode @@ -251,6 +257,7 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result let result = bdk_cli::handle_compile_subcommand(network, policy, script_type)?; serde_json::to_string_pretty(&result)? } + #[cfg(feature = "repl")] CliSubCommand::Repl { wallet_opts } => { let database = open_database(&wallet_opts); diff --git a/src/lib.rs b/src/lib.rs index 19a3eaf..ea68a7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,6 +258,7 @@ pub enum CliSubCommand { script_type: String, }, /// Enter REPL command loop mode + #[cfg(feature = "repl")] #[structopt(long_about = "REPL command loop mode")] Repl { #[structopt(flatten)]