diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 8574e02cf..ffa4e9ce9 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -44,6 +44,7 @@ jobs: cargo update -p zip:0.6.6 --precise "0.6.2" cargo update -p time --precise "0.3.13" cargo update -p cc --precise "1.0.81" + cargo update -p byteorder --precise "1.4.3" - name: Build run: cargo build ${{ matrix.features }} - name: Test diff --git a/README.md b/README.md index d454e6428..ca6e5b9ef 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ cargo update -p zip:0.6.6 --precise "0.6.2" cargo update -p time --precise "0.3.13" # cc 1.0.82 has MSRV 1.61.0+ cargo update -p cc --precise "1.0.81" +# byteorder 1.5.0 has MSRV 1.60+ +cargo update -p byteorder --precise "1.4.3" ``` ## License diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index 9ee72b4b6..3a8bad93d 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -113,6 +113,33 @@ pub struct Update { pub chain: Option, } +impl From> for Update { + fn from(graph: TxGraph) -> Self { + Self { + graph, + ..Default::default() + } + } +} + +impl From> for Update { + fn from(last_active_indices: BTreeMap) -> Self { + Self { + last_active_indices, + ..Default::default() + } + } +} + +impl From for Update { + fn from(chain: local_chain::Update) -> Self { + Self { + chain: Some(chain), + ..Default::default() + } + } +} + /// The changes made to a wallet by applying an [`Update`]. #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, Default)] pub struct ChangeSet { @@ -1916,10 +1943,13 @@ impl Wallet { /// transactions related to your wallet into it. /// /// [`commit`]: Self::commit - pub fn apply_update(&mut self, update: Update) -> Result<(), CannotConnectError> + pub fn apply_update(&mut self, update: U) -> Result<(), CannotConnectError> where + U: Into, D: PersistBackend, { + let update = update.into(); + let mut changeset = match update.chain { Some(chain_update) => ChangeSet::from(self.chain.apply_update(chain_update)?), None => ChangeSet::default(), @@ -1940,6 +1970,11 @@ impl Wallet { Ok(()) } + /// Get heights of missing checkpoints. + pub fn missing_checkpoints(&self) -> impl Iterator + '_ { + self.tx_graph().missing_heights(self.local_chain()) + } + /// Commits all currently [`staged`] changed to the persistence backend returning and error when /// this fails. /// diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index c7a729af6..86047e5c3 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -2,7 +2,7 @@ use std::{io::Write, str::FromStr}; use bdk::{ bitcoin::{Address, Network}, - wallet::{AddressIndex, Update}, + wallet::AddressIndex, SignOptions, Wallet, }; use bdk_esplora::{esplora_client, EsploraAsyncExt}; @@ -53,17 +53,18 @@ async fn main() -> Result<(), Box> { (k, k_spks) }) .collect(); + let (update_graph, last_active_indices) = client .scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS) .await?; - let missing_heights = wallet.tx_graph().missing_heights(wallet.local_chain()); - let chain_update = client.update_local_chain(prev_tip, missing_heights).await?; - let update = Update { - last_active_indices, - graph: update_graph, - chain: Some(chain_update), - }; - wallet.apply_update(update)?; + wallet.apply_update(update_graph)?; + wallet.apply_update(last_active_indices)?; + + let chain_update = client + .update_local_chain(prev_tip, wallet.missing_checkpoints()) + .await?; + wallet.apply_update(chain_update)?; + wallet.commit()?; println!(); diff --git a/example-crates/wallet_esplora_blocking/src/main.rs b/example-crates/wallet_esplora_blocking/src/main.rs index a93a449c8..caad2e322 100644 --- a/example-crates/wallet_esplora_blocking/src/main.rs +++ b/example-crates/wallet_esplora_blocking/src/main.rs @@ -7,7 +7,7 @@ use std::{io::Write, str::FromStr}; use bdk::{ bitcoin::{Address, Network}, - wallet::{AddressIndex, Update}, + wallet::AddressIndex, SignOptions, Wallet, }; use bdk_esplora::{esplora_client, EsploraExt}; @@ -55,15 +55,12 @@ fn main() -> Result<(), Box> { let (update_graph, last_active_indices) = client.scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)?; - let missing_heights = wallet.tx_graph().missing_heights(wallet.local_chain()); - let chain_update = client.update_local_chain(prev_tip, missing_heights)?; - let update = Update { - last_active_indices, - graph: update_graph, - chain: Some(chain_update), - }; - - wallet.apply_update(update)?; + wallet.apply_update(update_graph)?; + wallet.apply_update(last_active_indices)?; + + let chain_update = client.update_local_chain(prev_tip, wallet.missing_checkpoints())?; + wallet.apply_update(chain_update)?; + wallet.commit()?; println!();