Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bdk_redb = { version = "0.1.0", optional = true }
shlex = { version = "1.3.0", optional = true }
tracing = "0.1.41"
tracing-subscriber = "0.3.20"
electrum-client = "0.24.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bdk_electrum is built on this crate, so no need pulling it here.


[features]
default = ["repl", "sqlite"]
Expand Down
12 changes: 9 additions & 3 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! All subcommands are defined in the below enums.

#![allow(clippy::large_enum_variant)]

use bdk_wallet::bitcoin::{
Address, Network, OutPoint, ScriptBuf,
bip32::{DerivationPath, Xpriv},
Expand Down Expand Up @@ -186,6 +185,10 @@ pub struct WalletOpts {
#[cfg(feature = "electrum")]
#[arg(env = "ELECTRUM_BATCH_SIZE", short = 'b', long, default_value = "10")]
pub batch_size: usize,
///Electrum validate domain option.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is not needed

#[cfg(feature = "electrum")]
#[arg(env="VALIDATE_DOMAIN",long = "validate-domain", action = clap::ArgAction::Set, default_value_t = true)]
pub validate_domain: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a user do not need to specifically indicate whether the domain should be validated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry if I misunderstood but doesn't the issue want us to provide validate_domain as an option? Because otherwise config.validate_domain is true by default anyways.

/// Esplora parallel requests.
#[cfg(feature = "esplora")]
#[arg(
Expand Down Expand Up @@ -396,8 +399,11 @@ pub enum OnlineWalletSubCommand {
stop_gap: usize,
},
/// Syncs with the chosen blockchain server.
Sync,
/// Broadcasts a transaction to the network. Takes either a raw transaction or a PSBT to extract.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc comment should not be removed.

Sync {
#[command(flatten)]
wallet_opts: WalletOpts,
},

Broadcast {
/// Sets the PSBT to sign.
#[arg(
Expand Down
17 changes: 13 additions & 4 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! Command Handlers
//!
//! This module describes all the command handling logic used by bdk-cli.

use crate::commands::OfflineWalletSubCommand::*;
use crate::commands::*;
use crate::error::BDKCliError as Error;
Expand Down Expand Up @@ -619,7 +618,11 @@ pub(crate) async fn handle_online_wallet_subcommand(
});
match client {
#[cfg(feature = "electrum")]
Electrum { client, batch_size } => {
Electrum {
client,
batch_size,
validate_domain: _,
} => {
// Populate the electrum client's transaction cache so it doesn't re-download transaction we
// already have.
client
Expand Down Expand Up @@ -686,17 +689,22 @@ pub(crate) async fn handle_online_wallet_subcommand(
}
Ok(serde_json::to_string_pretty(&json!({}))?)
}
Sync => {
sync => {
#[cfg(any(feature = "electrum", feature = "esplora"))]
let request = wallet
.start_sync_with_revealed_spks()
.inspect(|item, progress| {
let pc = (100 * progress.consumed()) as f32 / progress.total() as f32;
eprintln!("[ SCANNING {pc:03.0}% ] {item}");
});

match client {
#[cfg(feature = "electrum")]
Electrum { client, batch_size } => {
Electrum {
client,
batch_size,
validate_domain,
} => {
// Populate the electrum client's transaction cache so it doesn't re-download transaction we
// already have.
client
Expand Down Expand Up @@ -788,6 +796,7 @@ pub(crate) async fn handle_online_wallet_subcommand(
Electrum {
client,
batch_size: _,
validate_domain,
} => client
.transaction_broadcast(&tx)
.map_err(|e| Error::Generic(e.to_string()))?,
Expand Down
18 changes: 11 additions & 7 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
//! Utility Tools
//!
//! This module includes all the utility tools used by the App.
use crate::error::BDKCliError as Error;
use std::fmt::Display;
use std::str::FromStr;

use std::path::{Path, PathBuf};

use crate::commands::WalletOpts;
use crate::error::BDKCliError as Error;
#[cfg(feature = "cbf")]
use bdk_kyoto::{
BuilderExt, Info, LightClient, Receiver, ScanType::Sync, UnboundedReceiver, Warning,
builder::Builder,
};
use bdk_wallet::bitcoin::{Address, Network, OutPoint, ScriptBuf};
use electrum_client::ConfigBuilder;
use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::str::FromStr;

#[cfg(any(
feature = "electrum",
Expand Down Expand Up @@ -127,6 +126,7 @@ pub(crate) enum BlockchainClient {
Electrum {
client: Box<bdk_electrum::BdkElectrumClient<bdk_electrum::electrum_client::Client>>,
batch_size: usize,
validate_domain: bool,
},
#[cfg(feature = "esplora")]
Esplora {
Expand Down Expand Up @@ -159,11 +159,15 @@ pub(crate) fn new_blockchain_client(
let client = match wallet_opts.client_type {
#[cfg(feature = "electrum")]
ClientType::Electrum => {
let client = bdk_electrum::electrum_client::Client::new(url)
let config = ConfigBuilder::new()
.validate_domain(wallet_opts.validate_domain)
.build();
let client = bdk_electrum::electrum_client::Client::from_config(url, config)
.map(bdk_electrum::BdkElectrumClient::new)?;
BlockchainClient::Electrum {
client: Box::new(client),
batch_size: wallet_opts.batch_size,
validate_domain: wallet_opts.validate_domain,
}
}
#[cfg(feature = "esplora")]
Expand Down