diff --git a/src/bitcoin/mod.rs b/src/bitcoin/mod.rs index a278d33a..effc0320 100644 --- a/src/bitcoin/mod.rs +++ b/src/bitcoin/mod.rs @@ -13,7 +13,7 @@ pub use d::{MempoolEntry, SyncProgress}; use std::{fmt, sync}; -use miniscript::bitcoin::{self, address}; +use miniscript::bitcoin::{self, address, bip32::ChildNumber}; const COINBASE_MATURITY: i32 = 100; @@ -58,6 +58,17 @@ pub trait BitcoinInterface: Send { /// Check whether this former tip is part of the current best chain. fn is_in_chain(&self, tip: &BlockChainTip) -> bool; + /// Sync the wallet with the current best chain. + /// `receive_index` and `change_index` are the last derivation indices + /// that are expected to have been used by the wallet. + /// In case there has been a reorg, returns the common ancestor between + /// the wallet and the reorged chain. + fn sync_wallet( + &mut self, + receive_index: ChildNumber, + change_index: ChildNumber, + ) -> Result, String>; + /// Get coins received since the specified tip. fn received_coins( &self, @@ -157,6 +168,15 @@ impl BitcoinInterface for d::BitcoinD { .unwrap_or(false) } + // The watchonly wallet handles this for us. + fn sync_wallet( + &mut self, + _receive_index: ChildNumber, + _change_index: ChildNumber, + ) -> Result, String> { + Ok(None) + } + fn received_coins( &self, tip: &BlockChainTip, @@ -410,6 +430,16 @@ impl BitcoinInterface for sync::Arc> self.lock().unwrap().is_in_chain(tip) } + fn sync_wallet( + &mut self, + receive_index: ChildNumber, + change_index: ChildNumber, + ) -> Result, String> { + self.lock() + .unwrap() + .sync_wallet(receive_index, change_index) + } + fn received_coins( &self, tip: &BlockChainTip, diff --git a/src/testutils.rs b/src/testutils.rs index cb3418f9..ffea3ddc 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -64,6 +64,14 @@ impl BitcoinInterface for DummyBitcoind { true } + fn sync_wallet( + &mut self, + _receive_index: bip32::ChildNumber, + _change_index: bip32::ChildNumber, + ) -> Result, String> { + Ok(None) + } + fn received_coins( &self, _: &BlockChainTip,