bitcoin: add sync_wallet method to interface

This includes changes from darosior's comment in
https://github.com/wizardsardine/liana/pull/1222#issuecomment-2324894986.
This commit is contained in:
jp1ac4 2024-08-06 14:55:05 +01:00 committed by Michael Mallan
parent 34b9a49328
commit 89e004d4fd
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB
2 changed files with 39 additions and 1 deletions

View File

@ -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<Option<BlockChainTip>, 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<Option<BlockChainTip>, String> {
Ok(None)
}
fn received_coins(
&self,
tip: &BlockChainTip,
@ -410,6 +430,16 @@ impl BitcoinInterface for sync::Arc<sync::Mutex<dyn BitcoinInterface + 'static>>
self.lock().unwrap().is_in_chain(tip)
}
fn sync_wallet(
&mut self,
receive_index: ChildNumber,
change_index: ChildNumber,
) -> Result<Option<BlockChainTip>, String> {
self.lock()
.unwrap()
.sync_wallet(receive_index, change_index)
}
fn received_coins(
&self,
tip: &BlockChainTip,

View File

@ -64,6 +64,14 @@ impl BitcoinInterface for DummyBitcoind {
true
}
fn sync_wallet(
&mut self,
_receive_index: bip32::ChildNumber,
_change_index: bip32::ChildNumber,
) -> Result<Option<BlockChainTip>, String> {
Ok(None)
}
fn received_coins(
&self,
_: &BlockChainTip,