mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-07-04 18:41:38 +00:00
Use context instead of map_error
This commit is contained in:
parent
2ced9ddba4
commit
9b93cabfdf
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
execution_params::ExecutionParams,
|
execution_params::ExecutionParams,
|
||||||
};
|
};
|
||||||
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
|
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use backoff::{backoff::Constant as ConstantBackoff, tokio::retry};
|
use backoff::{backoff::Constant as ConstantBackoff, tokio::retry};
|
||||||
use bdk::{
|
use bdk::{
|
||||||
|
@ -23,12 +23,17 @@ use tokio::{sync::Mutex, time::interval};
|
||||||
|
|
||||||
const SLED_TREE_NAME: &str = "default_tree";
|
const SLED_TREE_NAME: &str = "default_tree";
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
enum Error {
|
enum Error {
|
||||||
|
#[error("Sending the request failed")]
|
||||||
Io(reqwest::Error),
|
Io(reqwest::Error),
|
||||||
|
#[error("Conversion to Integer failed")]
|
||||||
Parse(std::num::ParseIntError),
|
Parse(std::num::ParseIntError),
|
||||||
|
#[error("The transaction is not minded yet")]
|
||||||
NotYetMined,
|
NotYetMined,
|
||||||
JsonDeserialisation(reqwest::Error),
|
#[error("Deserialization failed")]
|
||||||
|
JsonDeserialization(reqwest::Error),
|
||||||
|
#[error("Connecting to Electrum failed")]
|
||||||
ElectrumConnection(electrum_client::Error),
|
ElectrumConnection(electrum_client::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +180,7 @@ impl WatchForRawTransaction for Wallet {
|
||||||
Result::<_, backoff::Error<Error>>::Ok(tx)
|
Result::<_, backoff::Error<Error>>::Ok(tx)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|err| anyhow!("transient errors to be retried: {:?}", err))?;
|
.context("transient errors to be retried")?;
|
||||||
|
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
@ -208,7 +213,7 @@ impl GetBlockHeight for Wallet {
|
||||||
Result::<_, backoff::Error<Error>>::Ok(height)
|
Result::<_, backoff::Error<Error>>::Ok(height)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|err| anyhow!("transient errors to be retried: {:?}", err))?;
|
.context("transient errors to be retried")?;
|
||||||
|
|
||||||
Ok(BlockHeight::new(height))
|
Ok(BlockHeight::new(height))
|
||||||
}
|
}
|
||||||
|
@ -233,7 +238,7 @@ impl TransactionBlockHeight for Wallet {
|
||||||
let tx_status: TransactionStatus = resp
|
let tx_status: TransactionStatus = resp
|
||||||
.json()
|
.json()
|
||||||
.await
|
.await
|
||||||
.map_err(|err| backoff::Error::Permanent(Error::JsonDeserialisation(err)))?;
|
.map_err(|err| backoff::Error::Permanent(Error::JsonDeserialization(err)))?;
|
||||||
|
|
||||||
let block_height = tx_status
|
let block_height = tx_status
|
||||||
.block_height
|
.block_height
|
||||||
|
@ -242,7 +247,7 @@ impl TransactionBlockHeight for Wallet {
|
||||||
Result::<_, backoff::Error<Error>>::Ok(block_height)
|
Result::<_, backoff::Error<Error>>::Ok(block_height)
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|err| anyhow!("transient errors to be retried: {:?}", err))?;
|
.context("transient errors to be retried")?;
|
||||||
|
|
||||||
Ok(BlockHeight::new(height))
|
Ok(BlockHeight::new(height))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user