Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details.
## [Unreleased]
- Add wallet subcommand `config` to save wallet configs
- Add `wallets` command to list all wallets saved configs
- Added `completions` subcommand to generate shell completions

## [2.0.0]

- Removed MSRV and bumped Rust Edition to 2024
- Add `--pretty` flag for formatting outputs in human-readable form
- Added `--pretty` flag for formatting outputs in human-readable form
- Updated `bdk_wallet ` to `2.1.0`, `bdk_bitcoind_rpc` to `0.21.0`, `bdk_esplora` to `0.22.1`, `bdk_kyoto` to `0.13.1`
- Updated `tracing-subscriber` to 0.3.20
- Added `tr` script type to `compile` command to support creating taproot descriptors
Expand Down
10 changes: 10 additions & 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 @@ -14,6 +14,7 @@ license = "MIT"
[dependencies]
bdk_wallet = { version = "2.1.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
clap = { version = "4.5", features = ["derive","env"] }
clap_complete = "4.5"
dirs = { version = "6.0.0" }
env_logger = "0.11.6"
log = "0.4"
Expand Down
33 changes: 33 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use bdk_wallet::bitcoin::{
bip32::{DerivationPath, Xpriv},
};
use clap::{Args, Parser, Subcommand, ValueEnum, value_parser};
use clap_complete::Shell;

#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
use crate::utils::parse_proxy_auth;
Expand Down Expand Up @@ -127,7 +128,39 @@ pub enum CliSubCommand {
},
/// List all saved wallet configurations.
Wallets,
/// Generate tab-completion scripts for your shell.
///
/// Outputs a shell-specific completion script to stdout.
/// To enable completions you need to redirect this output into the appropriate location for your shell.
///
/// Bash:
/// bdk-cli completions bash > ~/.local/share/bash-completion/completions/bdk-cli
///
/// Zsh:
/// bdk-cli completions zsh > ~/.zfunc/_bdk-cli
/// # Make sure ~/.zfunc is in your fpath (add to .zshrc):
/// # fpath=(~/.zfunc $fpath)
/// # autoload -Uz compinit && compinit
///
/// Fish:
/// bdk-cli completions fish > ~/.config/fish/completions/bdk-cli.fish
///
/// PowerShell:
/// bdk-cli completions powershell >> $PROFILE
///
/// Elvish:
/// bdk-cli completions elvish >> ~/.elvish/rc.elv
Comment thread
va-an marked this conversation as resolved.
Outdated
///
/// After installing the completion script, restart your shell or source
/// the configuration file for the changes to take effect.
#[command(verbatim_doc_comment)]
Completions {
/// Target shell syntax
#[arg(value_enum)]
shell: Shell,
},
}

/// Wallet operation subcommands.
#[derive(Debug, Subcommand, Clone, PartialEq)]
pub enum WalletSubCommand {
Expand Down
9 changes: 8 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum BDKCliError {

#[cfg(feature = "redb")]
#[error("Redb StoreError: {0}")]
RedbStoreError(#[from] bdk_redb::error::StoreError),
RedbStoreError(Box<bdk_redb::error::StoreError>),

#[cfg(feature = "redb")]
#[error("Redb dabtabase error: {0}")]
Expand Down Expand Up @@ -119,3 +119,10 @@ impl From<ExtractTxError> for BDKCliError {
BDKCliError::PsbtExtractTxError(Box::new(value))
}
}

#[cfg(feature = "redb")]
impl From<bdk_redb::error::StoreError> for BDKCliError {
fn from(err: bdk_redb::error::StoreError) -> Self {
BDKCliError::RedbStoreError(Box::new(err))
}
}
11 changes: 11 additions & 0 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use bdk_wallet::{
descriptor::{Descriptor, Legacy, Miniscript},
miniscript::{Tap, descriptor::TapTree, policy::Concrete},
};
use clap::CommandFactory;
use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
use serde_json::json;
#[cfg(feature = "cbf")]
Expand Down Expand Up @@ -1422,6 +1423,16 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
let descriptor = handle_descriptor_command(cli_opts.network, desc_type, key, pretty)?;
Ok(descriptor)
}
CliSubCommand::Completions { shell } => {
clap_complete::generate(
shell,
&mut CliOpts::command(),
"bdk-cli",
&mut std::io::stdout(),
);

Ok("".to_string())
}
};
result
}
Expand Down
17 changes: 8 additions & 9 deletions src/payjoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> PayjoinManager<'a> {
let persister = payjoin::persist::NoopSessionPersister::<ReceiverSessionEvent>::default();

let checked_max_fee_rate = max_fee_rate
.map(|rate| FeeRate::from_sat_per_kwu(rate))
.map(FeeRate::from_sat_per_kwu)
.unwrap_or(FeeRate::BROADCAST_MIN);

let receiver = payjoin::receive::v2::ReceiverBuilder::new(
Expand Down Expand Up @@ -296,7 +296,7 @@ impl<'a> PayjoinManager<'a> {
.await
}
ReceiveSession::HasReplyableError(error) => self.handle_error(error, persister).await,
ReceiveSession::Closed(_) => return Err(Error::Generic("Session closed".to_string())),
ReceiveSession::Closed(_) => Err(Error::Generic("Session closed".to_string())),
}
}

Expand Down Expand Up @@ -334,7 +334,7 @@ impl<'a> PayjoinManager<'a> {
Err(e) => {
return Err(Error::Generic(format!(
"Error occurred when polling for Payjoin proposal from the directory: {}",
e.to_string()
e
)));
}
}
Expand Down Expand Up @@ -637,16 +637,15 @@ impl<'a> PayjoinManager<'a> {
return Err(ImplementationError::from("Cannot find the transaction in the mempool or the blockchain"));
};

let is_seen = match tx_details.chain_position {
bdk_wallet::chain::ChainPosition::Confirmed { .. } => true,
bdk_wallet::chain::ChainPosition::Unconfirmed { first_seen: Some(_), .. } => true,
_ => false
};
let is_seen = matches!(
tx_details.chain_position, bdk_wallet::chain::ChainPosition::Confirmed { .. }
| bdk_wallet::chain::ChainPosition::Unconfirmed { first_seen: Some(_), .. }
);

if is_seen {
return Ok(Some(tx_details.tx.as_ref().clone()));
}
return Err(ImplementationError::from("Cannot find the transaction in the mempool or the blockchain"));
Err(ImplementationError::from("Cannot find the transaction in the mempool or the blockchain"))
},
|outpoint| {
let utxo = self.wallet.get_utxo(outpoint);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn new_blockchain_client(
}
#[cfg(feature = "esplora")]
ClientType::Esplora => {
let client = bdk_esplora::esplora_client::Builder::new(&url).build_async()?;
let client = bdk_esplora::esplora_client::Builder::new(url).build_async()?;
BlockchainClient::Esplora {
client: Box::new(client),
parallel_requests: wallet_opts.parallel_requests,
Expand Down
Loading