]> Untitled Git - bdk-cli/commitdiff
[WIP] Update to bdk 0.17.0
authorSteve Myers <steve@notmandatory.org>
Fri, 4 Mar 2022 04:09:50 +0000 (20:09 -0800)
committerSteve Myers <steve@notmandatory.org>
Tue, 29 Mar 2022 22:48:53 +0000 (15:48 -0700)
.github/workflows/cont_integration.yml
Cargo.lock
Cargo.toml
src/bdk_cli.rs
src/lib.rs

index 9f31349edbe6205dfa3367488211a74ab5a5fc86..95eead95a9dd9ea951580aec8dc0fb652b583e03 100644 (file)
@@ -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
index e9cc31d354cd27e910d070d36827c614957c140e..54c906c78a738cb97c934314cdceaf6ffdfcf396 100644 (file)
@@ -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",
 ]
index 6daf25b5751bec6c3271a850f214426a544df2a7..8330520aa188fdb9b65eb0e506dd57bdf5f92c7d 100644 (file)
@@ -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" }
index b094834c75ac48bc6519fb796a15b89e09b0f576..9844d6282337d25fc7ef8dcf8f91e46e751db583 100644 (file)
@@ -127,14 +127,7 @@ fn open_database(wallet_opts: &WalletOpts) -> Result<Tree, Error> {
     feature = "compact_filters",
     feature = "rpc"
 ))]
-fn new_online_wallet<D>(
-    network: Network,
-    wallet_opts: &WalletOpts,
-    database: D,
-) -> Result<Wallet<AnyBlockchain, D>, Error>
-where
-    D: BatchDatabase,
-{
+pub fn new_blockchain(_network: Network, wallet_opts: &WalletOpts) -> Result<AnyBlockchain, Error> {
     #[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<D>(
+pub fn new_wallet<D>(
     network: Network,
     wallet_opts: &WalletOpts,
     database: D,
-) -> Result<Wallet<(), D>, Error>
+) -> Result<Wallet<D>, 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<String, Error>
         } => {
             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<String, Error>
         } => {
             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<String, Error>
                 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<String, Error>
                 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<String, Error>
                                 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(
index 6cdb0bbe096ba5b1bfe2bbfc46809fc5a872b8fe..c1a1a0fbf3be4d5005458bff8dee983ddf47e039 100644 (file)
 //!
 //!     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<OutPoint, String> {
 /// Execute an offline wallet sub-command
 ///
 /// Offline wallet sub-commands are described in [`OfflineWalletSubCommand`].
-pub fn handle_offline_wallet_subcommand<T, D>(
-    wallet: &Wallet<T, D>,
+pub fn handle_offline_wallet_subcommand<D>(
+    wallet: &Wallet<D>,
     wallet_opts: &WalletOpts,
     offline_subcommand: OfflineWalletSubCommand,
 ) -> Result<serde_json::Value, Error>
@@ -1082,17 +1082,26 @@ where
     feature = "rpc"
 ))]
 #[maybe_async]
-pub fn handle_online_wallet_subcommand<C, D>(
-    wallet: &Wallet<C, D>,
+pub fn handle_online_wallet_subcommand<B, D>(
+    wallet: &Wallet<D>,
+    blockchain: &B,
     online_subcommand: OnlineWalletSubCommand,
 ) -> Result<serde_json::Value, Error>
 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")]