mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Distinguish permanent and transient error when watching tx
This commit is contained in:
parent
b66bb00c77
commit
77ec7e502f
@ -29,6 +29,7 @@ enum Error {
|
||||
Parse(std::num::ParseIntError),
|
||||
NotYetMined,
|
||||
JsonDeserialisation(reqwest::Error),
|
||||
ElectrumConnection(electrum_client::Error),
|
||||
}
|
||||
|
||||
pub struct Wallet {
|
||||
@ -163,14 +164,20 @@ impl BroadcastSignedTransaction for Wallet {
|
||||
impl WatchForRawTransaction for Wallet {
|
||||
async fn watch_for_raw_transaction(&self, txid: Txid) -> Result<Transaction> {
|
||||
tracing::debug!("watching for tx: {}", txid);
|
||||
retry(ConstantBackoff::new(Duration::from_secs(1)), || async {
|
||||
let client = Client::new(self.rpc_url.as_ref())?;
|
||||
let tx = client.transaction_get(&txid)?;
|
||||
let tx = retry(ConstantBackoff::new(Duration::from_secs(1)), || async {
|
||||
let client = Client::new(self.rpc_url.as_ref())
|
||||
.map_err(|err| backoff::Error::Permanent(Error::ElectrumConnection(err)))?;
|
||||
let tx = client
|
||||
.transaction_get(&txid)
|
||||
.map_err(|_| backoff::Error::Transient(Error::NotYetMined))?;
|
||||
tracing::debug!("found tx: {}", txid);
|
||||
Ok(tx)
|
||||
|
||||
Result::<_, backoff::Error<Error>>::Ok(tx)
|
||||
})
|
||||
.await
|
||||
.map_err(|err| anyhow!("transient errors to be retried: {:?}", err))
|
||||
.map_err(|err| anyhow!("transient errors to be retried: {:?}", err))?;
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ async fn run_until_internal(
|
||||
swap_id: Uuid,
|
||||
db: Arc<Database>,
|
||||
) -> Result<AliceState> {
|
||||
info!("Current state:{}", state);
|
||||
info!("Current state: {}", state);
|
||||
if is_target_state(&state) {
|
||||
Ok(state)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user