Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bitcoin-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub trait BitcoinWallet: Send + Sync {

async fn sync(&self) -> Result<()>;

async fn health_check(&self) -> Result<()>;

async fn subscribe_to(&self, tx: Box<dyn Watchable>) -> Subscription;

async fn status_of_script(&self, tx: &dyn Watchable) -> Result<ScriptStatus>;
Expand Down
17 changes: 16 additions & 1 deletion bitcoin-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,13 @@ impl Wallet {
.context("Failed to sync Bitcoin wallet after retries")
}

pub async fn health_check(&self) -> Result<()> {
self.electrum_client
.update_block_height()
.await
.context("Bitcoin wallet failed to reach the Electrum backend")
}

/// Calculate the fee for a given transaction.
///
/// Will fail if the transaction inputs are not owned by this wallet.
Expand Down Expand Up @@ -1663,7 +1670,7 @@ impl Client {
}

/// Update the block height.
async fn update_block_height(&self) -> Result<()> {
pub async fn update_block_height(&self) -> Result<()> {
let latest_block = self
.inner
.call_async("block_headers_subscribe", |client| {
Expand Down Expand Up @@ -2166,6 +2173,10 @@ impl BitcoinWallet for Wallet {
Wallet::sync(self).await
}

async fn health_check(&self) -> Result<()> {
Wallet::health_check(self).await
}

async fn subscribe_to(&self, tx: Box<dyn Watchable>) -> Subscription {
Wallet::subscribe_to(self, tx).await
}
Expand Down Expand Up @@ -2976,6 +2987,10 @@ impl BitcoinWallet for Wallet<Connection, StaticFeeRate> {
unimplemented!("stub method called erroneously")
}

async fn health_check(&self) -> Result<()> {
unimplemented!("stub method called erroneously")
}

async fn subscribe_to(&self, tx: Box<dyn Watchable>) -> Subscription {
unimplemented!("stub method called erroneously")
}
Expand Down
5 changes: 5 additions & 0 deletions swap/src/asb/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,11 @@ async fn capture_wallet_snapshot(
) -> Result<WalletSnapshot> {
let start_time = Instant::now();

bitcoin_wallet
.health_check()
.await
.context("Bitcoin wallet health check failed while capturing wallet snapshot")?;

let unlocked_balance = monero_wallet.main_wallet().await.unlocked_balance().await?;
let total_balance = monero_wallet.main_wallet().await.total_balance().await?;

Expand Down
Loading