mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Simplify the GET request to the tx status URL
This commit is contained in:
parent
418ad7089d
commit
e9d7d9299c
@ -246,25 +246,20 @@ impl Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn transaction_block_height(&self, txid: Txid) -> Result<BlockHeight> {
|
pub async fn transaction_block_height(&self, txid: Txid) -> Result<BlockHeight> {
|
||||||
let url = make_tx_status_url(&self.http_url, txid)?;
|
let status_url = make_tx_status_url(&self.http_url, txid)?;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct TransactionStatus {
|
struct TransactionStatus {
|
||||||
block_height: Option<u32>,
|
block_height: Option<u32>,
|
||||||
confirmed: bool,
|
confirmed: bool,
|
||||||
}
|
}
|
||||||
let height = retry(ConstantBackoff::new(Duration::from_secs(1)), || async {
|
let height = retry(ConstantBackoff::new(Duration::from_secs(1)), || async {
|
||||||
let resp = reqwest::Client::new()
|
let block_height = reqwest::get(status_url.clone())
|
||||||
.request(Method::GET, url.clone())
|
|
||||||
.send()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|err| backoff::Error::Transient(Error::Io(err)))?;
|
.map_err(|err| backoff::Error::Transient(Error::Io(err)))?
|
||||||
|
.json::<TransactionStatus>()
|
||||||
let tx_status: TransactionStatus = resp
|
|
||||||
.json()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|err| backoff::Error::Permanent(Error::JsonDeserialization(err)))?;
|
.map_err(|err| backoff::Error::Permanent(Error::JsonDeserialization(err)))?
|
||||||
|
|
||||||
let block_height = tx_status
|
|
||||||
.block_height
|
.block_height
|
||||||
.ok_or(backoff::Error::Transient(Error::NotYetMined))?;
|
.ok_or(backoff::Error::Transient(Error::NotYetMined))?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user