From e9d7d9299c38ce1b17a72f96ea694025c56de3bd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 5 Mar 2021 16:49:49 +1100 Subject: [PATCH] Simplify the GET request to the tx status URL --- swap/src/bitcoin/wallet.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index cc305253..d019d578 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -246,25 +246,20 @@ impl Wallet { } pub async fn transaction_block_height(&self, txid: Txid) -> Result { - 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)] struct TransactionStatus { block_height: Option, confirmed: bool, } let height = retry(ConstantBackoff::new(Duration::from_secs(1)), || async { - let resp = reqwest::Client::new() - .request(Method::GET, url.clone()) - .send() + let block_height = reqwest::get(status_url.clone()) .await - .map_err(|err| backoff::Error::Transient(Error::Io(err)))?; - - let tx_status: TransactionStatus = resp - .json() + .map_err(|err| backoff::Error::Transient(Error::Io(err)))? + .json::() .await - .map_err(|err| backoff::Error::Permanent(Error::JsonDeserialization(err)))?; - - let block_height = tx_status + .map_err(|err| backoff::Error::Permanent(Error::JsonDeserialization(err)))? .block_height .ok_or(backoff::Error::Transient(Error::NotYetMined))?;