From 89e004d4fdd88324da255bc85aeb8adbb90653b1 Mon Sep 17 00:00:00 2001
From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com>
Date: Tue, 6 Aug 2024 14:55:05 +0100
Subject: [PATCH] bitcoin: add sync_wallet method to interface
This includes changes from darosior's comment in
https://github.com/wizardsardine/liana/pull/1222#issuecomment-2324894986.
---
src/bitcoin/mod.rs | 32 +++++++++++++++++++++++++++++++-
src/testutils.rs | 8 ++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
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