use rustyline::Editor;
use structopt::StructOpt;
+#[cfg(feature = "compact_filters")]
+use bdk::blockchain::compact_filters::{BitcoinPeerConfig, CompactFiltersBlockchainConfig};
#[cfg(feature = "esplora")]
use bdk::blockchain::esplora::EsploraBlockchainConfig;
use bdk::blockchain::{
timeout: wallet_opts.electrum_opts.timeout,
});
- // Fall back to Electrum config if Esplora config isn't provided
- let config = config_esplora.unwrap_or(config_electrum);
+ #[cfg(feature = "compact_filters")]
+ let compact_filter_config: Option<AnyBlockchainConfig> = {
+ let peerconfig = BitcoinPeerConfig {
+ address: wallet_opts.compactfilter_opts.address.clone(),
+ socks5: None,
+ socks5_credentials: None,
+ };
+
+ Some(AnyBlockchainConfig::CompactFilters(
+ CompactFiltersBlockchainConfig {
+ peers: vec![peerconfig],
+ network,
+ storage_dir: wallet_opts.wallet.clone(),
+ skip_blocks: wallet_opts.compactfilter_opts.skip_blocks,
+ },
+ ))
+ };
+
+ #[cfg(not(feature = "compact_filters"))]
+ let compact_filter_config = None;
+
+ // Fall back to Electrum config if Esplora or Compact Filter config isn't provided
+ let config = config_esplora.unwrap_or_else(|| match compact_filter_config {
+ Some(config) => config,
+ None => config_electrum,
+ });
let descriptor = wallet_opts.descriptor.as_str();
let change_descriptor = wallet_opts.change_descriptor.as_deref();
#[cfg(feature = "esplora")]
#[structopt(flatten)]
pub esplora_opts: EsploraOpts,
+ #[cfg(feature = "compact_filters")]
+ #[structopt(flatten)]
+ pub compactfilter_opts: CompactFilterOpts,
+}
+
+/// Compact Filter options
+///
+/// Compact filter peer information used by [`OnlineWalletSubCommand`]s.
+#[cfg(feature = "compact_filters")]
+#[derive(Debug, StructOpt, Clone, PartialEq)]
+pub struct CompactFilterOpts {
+ /// Sets the light client network address
+ #[structopt(name = "ADDRESS:PORT", short = "n", long = "node")]
+ pub address: String,
+
+ /// Optionally skip initial `skip_blocks` blocks (default: 0)
+ #[structopt(name = "SKIP_BLOCKS", short = "k", long = "skip_blocks")]
+ pub skip_blocks: Option<usize>,
}
/// Electrum options
use super::{CliOpts, WalletOpts};
#[cfg(feature = "compiler")]
use crate::handle_compile_subcommand;
+ #[cfg(feature = "compact_filters")]
+ use crate::CompactFilterOpts;
#[cfg(feature = "electrum")]
use crate::ElectrumOpts;
#[cfg(feature = "esplora")]
esplora: None,
esplora_concurrency: 4
},
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ }
},
subcommand: WalletSubCommand::OfflineWalletSubCommand(GetNewAddress),
},
esplora_opts: EsploraOpts {
esplora: None,
esplora_concurrency: 4,
- }
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ },
},
subcommand: WalletSubCommand::OfflineWalletSubCommand(GetNewAddress),
},
esplora_opts: EsploraOpts {
esplora: Some("https://blockstream.info/api/".to_string()),
esplora_concurrency: 5,
- }
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ },
+ },
+ subcommand: WalletSubCommand::OfflineWalletSubCommand(GetNewAddress),
+ },
+ };
+
+ assert_eq!(expected_cli_opts, cli_opts);
+ }
+
+ #[cfg(feature = "compact_filters")]
+ #[test]
+ fn test_parse_wallet_compact_filters() {
+ let cli_args = vec!["bdk-cli", "--network", "bitcoin", "wallet",
+ "--descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)",
+ "--change_descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)",
+ "--node", "127.0.0.1:18444",
+ "--skip_blocks", "5",
+ "get_new_address"];
+
+ let cli_opts = CliOpts::from_iter(&cli_args);
+
+ let expected_cli_opts = CliOpts {
+ network: Network::Bitcoin,
+ subcommand: CliSubCommand::Wallet {
+ wallet_opts: WalletOpts {
+ wallet: "main".to_string(),
+ descriptor: "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)".to_string(),
+ change_descriptor: Some("wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)".to_string()),
+ #[cfg(feature = "electrum")]
+ electrum_opts: ElectrumOpts {
+ proxy: None,
+ retries: 5,
+ timeout: None,
+ electrum: "ssl://electrum.blockstream.info:60002".to_string(),
+ },
+ #[cfg(feature = "esplora")]
+ esplora_opts: EsploraOpts {
+ esplora: Some("https://blockstream.info/api/".to_string()),
+ esplora_concurrency: 5,
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: Some(5)
+ },
},
subcommand: WalletSubCommand::OfflineWalletSubCommand(GetNewAddress),
},
esplora_opts: EsploraOpts {
esplora: None,
esplora_concurrency: 4,
- }
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ },
},
subcommand: WalletSubCommand::OnlineWalletSubCommand(Sync {
max_addresses: Some(50)
esplora_opts: EsploraOpts {
esplora: None,
esplora_concurrency: 4,
- }
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ },
},
subcommand: WalletSubCommand::OfflineWalletSubCommand(CreateTx {
recipients: vec![(script1, 123456), (script2, 78910)],
esplora_opts: EsploraOpts {
esplora: None,
esplora_concurrency: 4,
- }
+ },
+ #[cfg(feature = "compact_filters")]
+ compactfilter_opts: CompactFilterOpts{
+ address: "127.0.0.1:18444".to_string(),
+ skip_blocks: None
+ },
},
subcommand: WalletSubCommand::OnlineWalletSubCommand(Broadcast {
psbt: Some("cHNidP8BAEICAAAAASWhGE1AhvtO+2GjJHopssFmgfbq+WweHd8zN/DeaqmDAAAAAAD/////AQAAAAAAAAAABmoEAAECAwAAAAAAAAA=".to_string()),