From 6ef9b23c70deecc2319dbc2acd0298aff01f0352 Mon Sep 17 00:00:00 2001 From: emma31-dev Date: Thu, 17 Sep 2026 12:52:44 +0100 Subject: [PATCH 1/2] Ignore .env files and add optional dotenv support Introduce an `env` feature that loads arguments from a .env file via dotenvy, disabled by default. --- .gitignore | 2 +- Cargo.lock | 7 +++++++ Cargo.toml | 6 +++++- src/main.rs | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6dfb84d0..654825df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /target - +.env *.swp .idea diff --git a/Cargo.lock b/Cargo.lock index b88b288f..b551688b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,6 +261,7 @@ dependencies = [ "clap_complete", "cli-table", "dirs", + "dotenvy", "env_logger", "log", "payjoin", @@ -1230,6 +1231,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + [[package]] name = "dunce" version = "1.0.5" diff --git a/Cargo.toml b/Cargo.toml index adc1d9c9..810a2c26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,14 @@ reqwest = { version = "0.13.2", default-features = false, features = ["rustls"], url = { version = "2.5.8", optional = true } bdk_message_signer = { version = "0.2.0", optional = true } bitcoin-payment-instructions = { version = "0.7.0", optional = true} +dotenvy = { version = "0.15.7", optional = true } [features] default = ["repl", "sqlite"] +# Load arguments from a .env file instead of typing them manually +env = ["dotenvy"] + # To use the app in a REPL mode repl = ["shlex"] @@ -56,7 +60,7 @@ cbf = ["bdk_kyoto", "_payjoin-dependencies"] electrum = ["bdk_electrum", "_payjoin-dependencies"] esplora = ["bdk_esplora", "_payjoin-dependencies"] rpc = ["bdk_bitcoind_rpc", "_payjoin-dependencies"] -dns_payment = ["bitcoin-payment-instructions"] +dns_payment = ["bitcoin-payment-instructions"] # Internal features _payjoin-dependencies = ["payjoin", "reqwest", "url", "sqlite"] diff --git a/src/main.rs b/src/main.rs index 06e3ea24..0a698664 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,8 @@ use clap::{CommandFactory, Parser}; #[tokio::main] async fn main() { env_logger::init(); + #[cfg(feature = "env")] + dotenvy::dotenv().ok(); let cli_opts: CliOpts = CliOpts::parse(); let network = &cli_opts.network; From 4034a84a1f1f753e055de78ffc54e8545945c35e Mon Sep 17 00:00:00 2001 From: emma31-dev Date: Thu, 17 Sep 2026 13:03:54 +0100 Subject: [PATCH 2/2] Enable env feature by default The `env` feature is now included in the default features, removing the need for the conditional compilation guard around the dotenv call. Signed-off-by: emma31-dev --- CHANGELOG.md | 1 + Cargo.toml | 2 +- README.md | 3 ++- src/main.rs | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 098eee19..26d13255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details. ## [Unreleased] - Added support for Multipath (two-paths) descriptors. +- Add `env` feature that loads arguments from a .env file via dotenvy ## [4.0.0] diff --git a/Cargo.toml b/Cargo.toml index 810a2c26..50c541af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ bitcoin-payment-instructions = { version = "0.7.0", optional = true} dotenvy = { version = "0.15.7", optional = true } [features] -default = ["repl", "sqlite"] +default = ["repl", "sqlite", "env"] # Load arguments from a .env file instead of typing them manually env = ["dotenvy"] diff --git a/README.md b/README.md index 94278f3c..948025c3 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,13 @@ bdk-cli can be compiled with different features to suit your experimental needs. - `rpc`: Connects the wallet to Bitcoind server. - Extra Utility Tools - `repl` : use bdk-cli as a [REPL](https://codewith.mu/en/tutorials/1.0/repl) shell (useful for quick manual testing of wallet operations). + - `env` : loads arguments from a .env file via dotenvy - `compiler` : opens up bdk-cli policy compiler commands. - `message_signer`: BIP322 message signing/verification. - `silent-payments`: Experimental BIP-352 silent payment sending - `dns_payment`: BIP-353 DNS payment instructions -The `default` feature set is `repl` and `sqlite`. With the `default` features, `bdk-cli` can be used as an **air-gapped** wallet, and can do everything that doesn't require a network connection. +The `default` feature set is `repl`, `env` and `sqlite`. With the `default` features, `bdk-cli` can be used as an **air-gapped** wallet, and can do everything that doesn't require a network connection. ## Install bdk-cli diff --git a/src/main.rs b/src/main.rs index 0a698664..47226943 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,6 @@ use clap::{CommandFactory, Parser}; #[tokio::main] async fn main() { env_logger::init(); - #[cfg(feature = "env")] dotenvy::dotenv().ok(); let cli_opts: CliOpts = CliOpts::parse();