From c1c650374db7ef4de06e47723a55b0656c0e82ed Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 3 Mar 2022 20:09:50 -0800 Subject: [PATCH] [WIP] Update to bdk 0.17.0 --- .github/workflows/cont_integration.yml | 9 +++-- Cargo.lock | 21 ++++++++++- Cargo.toml | 2 +- src/bdk_cli.rs | 51 +++++++++++--------------- src/lib.rs | 44 +++++++++++++--------- 5 files changed, 72 insertions(+), 55 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 9f31349..95eead9 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -19,10 +19,11 @@ jobs: - esplora-reqwest - compiler - compact_filters - - reserves - - reserves,electrum - - reserves,esplora-ureq - - reserves,compact_filters +# - reserves +# - reserves,electrum +# - reserves,esplora-ureq +# - reserves,compact_filters +# - reserves,rpc - rpc steps: - name: Checkout diff --git a/Cargo.lock b/Cargo.lock index e9cc31d..54c906c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,23 @@ name = "bdk" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3face7de38293a2f7e2a9f69a48b442f28e864da0fc7a6a977388e31bdc367d7" +dependencies = [ + "async-trait", + "bdk-macros", + "bitcoin", + "js-sys", + "log", + "miniscript", + "rand", + "serde", + "serde_json", + "tokio", +] + +[[package]] +name = "bdk" +version = "0.16.2-dev" +source = "git+https://github.com/LLFourn/bdk.git?branch=remove-blockchain-from-wallet#0cc4700bd67be84bb5cb0814bf5c8aa9fc3f3cdc" dependencies = [ "async-trait", "bdk-macros", @@ -112,7 +129,7 @@ name = "bdk-cli" version = "0.4.0" dependencies = [ "base64 0.11.0", - "bdk", + "bdk 0.16.2-dev", "bdk-macros", "bdk-reserves", "clap", @@ -145,7 +162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85397162a769b6162033c4ed8edc6285d347006eac5299dd186dee7bd77e8c88" dependencies = [ "base64 0.11.0", - "bdk", + "bdk 0.16.1", "bitcoinconsensus", "log", ] diff --git a/Cargo.toml b/Cargo.toml index 6daf25b..8330520 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" license = "MIT" [dependencies] -bdk = { version = "0.16", default-features = false, features = ["all-keys"]} +bdk = { git = "https://github.com/LLFourn/bdk.git", branch = "remove-blockchain-from-wallet", default-features = false, features = ["all-keys"]} bdk-macros = "0.6" structopt = "^0.3" serde_json = { version = "^1.0" } diff --git a/src/bdk_cli.rs b/src/bdk_cli.rs index b094834..9844d62 100644 --- a/src/bdk_cli.rs +++ b/src/bdk_cli.rs @@ -127,14 +127,7 @@ fn open_database(wallet_opts: &WalletOpts) -> Result { feature = "compact_filters", feature = "rpc" ))] -fn new_online_wallet( - network: Network, - wallet_opts: &WalletOpts, - database: D, -) -> Result, Error> -where - D: BatchDatabase, -{ +pub fn new_blockchain(_network: Network, wallet_opts: &WalletOpts) -> Result { #[cfg(feature = "electrum")] let config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { url: wallet_opts.electrum_opts.server.clone(), @@ -168,7 +161,7 @@ where AnyBlockchainConfig::CompactFilters(CompactFiltersBlockchainConfig { peers, - network, + network: _network, storage_dir: prepare_home_dir()? .into_os_string() .into_string() @@ -194,7 +187,7 @@ where let wallet_name = wallet_name_from_descriptor( &wallet_opts.descriptor[..], wallet_opts.change_descriptor.as_deref(), - network, + _network, &Secp256k1::new(), )?; @@ -204,37 +197,28 @@ where let rpc_config = RpcConfig { url: rpc_url, auth, - network, + network: _network, wallet_name, skip_blocks: wallet_opts.rpc_opts.skip_blocks, }; AnyBlockchainConfig::Rpc(rpc_config) }; - let descriptor = wallet_opts.descriptor.as_str(); - let change_descriptor = wallet_opts.change_descriptor.as_deref(); - let wallet = Wallet::new( - descriptor, - change_descriptor, - network, - database, - AnyBlockchain::from_config(&config)?, - )?; - Ok(wallet) + Ok(AnyBlockchain::from_config(&config)?) } -fn new_offline_wallet( +pub fn new_wallet( network: Network, wallet_opts: &WalletOpts, database: D, -) -> Result, Error> +) -> Result, Error> where D: BatchDatabase, { let descriptor = wallet_opts.descriptor.as_str(); let change_descriptor = wallet_opts.change_descriptor.as_deref(); - let wallet = Wallet::new_offline(descriptor, change_descriptor, network, database)?; + let wallet = Wallet::new(descriptor, change_descriptor, network, database)?; Ok(wallet) } @@ -294,8 +278,10 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result } => { let wallet_opts = maybe_descriptor_wallet_name(wallet_opts, network)?; let database = open_database(&wallet_opts)?; - let wallet = new_online_wallet(network, &wallet_opts, database)?; - let result = bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand)?; + let blockchain = new_blockchain(network, &wallet_opts)?; + let wallet = new_wallet(network, &wallet_opts, database)?; + let result = + bdk_cli::handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand)?; serde_json::to_string_pretty(&result)? } CliSubCommand::Wallet { @@ -304,7 +290,7 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result } => { let wallet_opts = maybe_descriptor_wallet_name(wallet_opts, network)?; let database = open_database(&wallet_opts)?; - let wallet = new_offline_wallet(network, &wallet_opts, database)?; + let wallet = new_wallet(network, &wallet_opts, database)?; let result = bdk_cli::handle_offline_wallet_subcommand( &wallet, &wallet_opts, @@ -337,7 +323,7 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result feature = "compact_filters", feature = "rpc" ))] - let wallet = new_online_wallet(network, &wallet_opts, database)?; + let wallet = new_wallet(network, &wallet_opts, database)?; #[cfg(not(any( feature = "electrum", @@ -345,7 +331,7 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result feature = "compact_filters", feature = "rpc" )))] - let wallet = new_offline_wallet(network, &wallet_opts, database)?; + let wallet = new_wallet(network, &wallet_opts, database)?; let mut rl = Editor::<()>::new(); @@ -391,7 +377,12 @@ fn handle_command(cli_opts: CliOpts, network: Network) -> Result feature = "rpc" ))] ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => { - bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand) + let blockchain = new_blockchain(network, &wallet_opts)?; + bdk_cli::handle_online_wallet_subcommand( + &wallet, + &blockchain, + online_subcommand, + ) } ReplSubCommand::OfflineWalletSubCommand(offline_subcommand) => { bdk_cli::handle_offline_wallet_subcommand( diff --git a/src/lib.rs b/src/lib.rs index 6cdb0bb..c1a1a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,23 +61,23 @@ //! //! let database = MemoryDatabase::new(); //! -//! let config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { -//! url: wallet_opts.electrum_opts.server, -//! socks5: wallet_opts.proxy_opts.proxy, -//! retry: wallet_opts.proxy_opts.retries, -//! timeout: None, -//! stop_gap: 10 -//! }); +//! let blockchain_config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig { +//! url: wallet_opts.electrum_opts.server.clone(), +//! socks5: wallet_opts.proxy_opts.proxy.clone(), +//! retry: wallet_opts.proxy_opts.retries, +//! timeout: wallet_opts.electrum_opts.timeout, +//! stop_gap: wallet_opts.electrum_opts.stop_gap, +//! }); +//! let blockchain = AnyBlockchain::from_config(&blockchain_config).expect("blockchain"); //! //! let wallet = Wallet::new( //! descriptor, //! change_descriptor, //! network, //! database, -//! AnyBlockchain::from_config(&config).unwrap(), -//! ).unwrap(); +//! ).expect("wallet"); //! -//! let result = bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand).unwrap(); +//! let result = bdk_cli::handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand).expect("result"); //! println!("{}", serde_json::to_string_pretty(&result).unwrap()); //! } //! # } @@ -881,8 +881,8 @@ fn parse_outpoint(s: &str) -> Result { /// Execute an offline wallet sub-command /// /// Offline wallet sub-commands are described in [`OfflineWalletSubCommand`]. -pub fn handle_offline_wallet_subcommand( - wallet: &Wallet, +pub fn handle_offline_wallet_subcommand( + wallet: &Wallet, wallet_opts: &WalletOpts, offline_subcommand: OfflineWalletSubCommand, ) -> Result @@ -1082,17 +1082,26 @@ where feature = "rpc" ))] #[maybe_async] -pub fn handle_online_wallet_subcommand( - wallet: &Wallet, +pub fn handle_online_wallet_subcommand( + wallet: &Wallet, + blockchain: &B, online_subcommand: OnlineWalletSubCommand, ) -> Result where - C: Blockchain, + B: Blockchain, D: BatchDatabase, { + use bdk::SyncOptions; + match online_subcommand { Sync { max_addresses } => { - maybe_await!(wallet.sync(log_progress(), max_addresses))?; + maybe_await!(wallet.sync( + blockchain, + SyncOptions { + progress: Some(Box::new(log_progress())), + max_addresses, + } + ))?; Ok(json!({})) } Broadcast { psbt, tx } => { @@ -1106,8 +1115,7 @@ where (Some(_), Some(_)) => panic!("Both `psbt` and `tx` options not allowed"), (None, None) => panic!("Missing `psbt` and `tx` option"), }; - - let txid = maybe_await!(wallet.broadcast(&tx))?; + let txid = maybe_await!(blockchain.broadcast(&tx))?; Ok(json!({ "txid": txid })) } #[cfg(feature = "reserves")] -- 2.49.0