Browse Source

Convert tracing::error into anyhow::Error context

This prevents us from reporting an error when the transaction was
actually on-chain.
hotfix/0.1.1
Lucas Soriano del Pino 3 years ago
parent
commit
f90dd1fa53
No known key found for this signature in database GPG Key ID: EE611E973A1530E7
  1. 20
      daemon/src/wallet.rs

20
daemon/src/wallet.rs

@ -96,18 +96,10 @@ impl Wallet {
pub async fn try_broadcast_transaction(&self, tx: Transaction) -> Result<Txid> {
let wallet = self.wallet.lock().await;
// TODO: Optimize this match to be a map_err / more readable in general
let txid = tx.txid();
let result = wallet.broadcast(tx.clone());
if result.is_err() {
tracing::error!(
"Broadcasting transaction failed. Raw transaction: {}",
serialize_hex(&tx)
);
}
if let Err(&bdk::Error::Electrum(electrum_client::Error::Protocol(ref value))) =
result.as_ref()
{
@ -116,11 +108,21 @@ impl Wallet {
})?;
if error_code == i64::from(RpcErrorCode::RpcVerifyAlreadyInChain) {
tracing::trace!(
%txid, "Attempted to broadcast transaction that was already on-chain",
);
return Ok(txid);
}
}
let txid = result?;
let txid = result.with_context(|| {
format!(
"Broadcasting transaction failed. Txid: {}. Raw transaction: {}",
txid,
serialize_hex(&tx)
)
})?;
Ok(txid)
}

Loading…
Cancel
Save