Move error message on sync _into_ the function

The bitcoin::Wallet::sync_wallet function doesn't do anything else
other than delegating. As such, we have just as much information
about what went wrong inside this function as we have outside.

By moving the .context call into the function, we can avoid repeating
us on every call-site.
This commit is contained in:
Thomas Eizinger 2021-03-04 17:05:00 +11:00
parent 5953037b81
commit 4f66269887
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
4 changed files with 15 additions and 37 deletions

View File

@ -141,10 +141,7 @@ async fn init_wallets(
) )
.await?; .await?;
bitcoin_wallet bitcoin_wallet.sync_wallet().await?;
.sync_wallet()
.await
.expect("Could not sync btc wallet");
let bitcoin_balance = bitcoin_wallet.balance().await?; let bitcoin_balance = bitcoin_wallet.balance().await?;
info!( info!(

View File

@ -256,10 +256,7 @@ async fn init_bitcoin_wallet(
) )
.await?; .await?;
wallet wallet.sync_wallet().await?;
.sync_wallet()
.await
.context("failed to sync balance of bitcoin wallet")?;
Ok(wallet) Ok(wallet)
} }

View File

@ -106,7 +106,12 @@ impl Wallet {
} }
pub async fn sync_wallet(&self) -> Result<()> { pub async fn sync_wallet(&self) -> Result<()> {
self.inner.lock().await.sync(noop_progress(), None)?; self.inner
.lock()
.await
.sync(noop_progress(), None)
.context("failed to sync balance of Bitcoin wallet")?;
Ok(()) Ok(())
} }

View File

@ -151,10 +151,7 @@ impl TestContext {
assert!(matches!(state, AliceState::BtcRedeemed)); assert!(matches!(state, AliceState::BtcRedeemed));
self.alice_bitcoin_wallet self.alice_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap(); let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap();
assert_eq!( assert_eq!(
@ -184,10 +181,7 @@ impl TestContext {
assert!(matches!(state, AliceState::XmrRefunded)); assert!(matches!(state, AliceState::XmrRefunded));
self.alice_bitcoin_wallet self.alice_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap(); let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap();
assert_eq!(btc_balance_after_swap, self.alice_starting_balances.btc); assert_eq!(btc_balance_after_swap, self.alice_starting_balances.btc);
@ -206,10 +200,7 @@ impl TestContext {
pub async fn assert_alice_punished(&self, state: AliceState) { pub async fn assert_alice_punished(&self, state: AliceState) {
assert!(matches!(state, AliceState::BtcPunished)); assert!(matches!(state, AliceState::BtcPunished));
self.alice_bitcoin_wallet self.alice_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap(); let btc_balance_after_swap = self.alice_bitcoin_wallet.as_ref().balance().await.unwrap();
assert_eq!( assert_eq!(
@ -228,10 +219,7 @@ impl TestContext {
} }
pub async fn assert_bob_redeemed(&self, state: BobState) { pub async fn assert_bob_redeemed(&self, state: BobState) {
self.bob_bitcoin_wallet self.bob_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let lock_tx_id = if let BobState::XmrRedeemed { tx_lock_id } = state { let lock_tx_id = if let BobState::XmrRedeemed { tx_lock_id } = state {
tx_lock_id tx_lock_id
@ -263,10 +251,7 @@ impl TestContext {
} }
pub async fn assert_bob_refunded(&self, state: BobState) { pub async fn assert_bob_refunded(&self, state: BobState) {
self.bob_bitcoin_wallet self.bob_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let lock_tx_id = if let BobState::BtcRefunded(state4) = state { let lock_tx_id = if let BobState::BtcRefunded(state4) = state {
state4.tx_lock_id() state4.tx_lock_id()
@ -300,10 +285,7 @@ impl TestContext {
} }
pub async fn assert_bob_punished(&self, state: BobState) { pub async fn assert_bob_punished(&self, state: BobState) {
self.bob_bitcoin_wallet self.bob_bitcoin_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync wallet");
let lock_tx_id = if let BobState::BtcPunished { tx_lock_id } = state { let lock_tx_id = if let BobState::BtcPunished { tx_lock_id } = state {
tx_lock_id tx_lock_id
@ -654,10 +636,7 @@ async fn init_test_wallets(
let max_retries = 30u8; let max_retries = 30u8;
loop { loop {
retries += 1; retries += 1;
btc_wallet btc_wallet.sync_wallet().await.unwrap();
.sync_wallet()
.await
.expect("Could not sync btc wallet");
let btc_balance = btc_wallet.balance().await.unwrap(); let btc_balance = btc_wallet.balance().await.unwrap();