Drop `futures` dependency from `lightning-block-sync`
[rust-lightning] / lightning-block-sync / src / rest.rs
index c73b23b600c2925e3e0a085a99fc75560527f064..c2926b7a0f766fdc975614735f025d80c05e5e9f 100644 (file)
@@ -7,15 +7,12 @@ use crate::http::{BinaryResponse, HttpEndpoint, HttpClient, JsonResponse};
 use bitcoin::hash_types::BlockHash;
 use bitcoin::hashes::hex::ToHex;
 
-use futures_util::lock::Mutex;
-
 use std::convert::TryFrom;
 use std::convert::TryInto;
 
 /// A simple REST client for requesting resources using HTTP `GET`.
 pub struct RestClient {
        endpoint: HttpEndpoint,
-       client: Mutex<HttpClient>,
 }
 
 impl RestClient {
@@ -23,8 +20,7 @@ impl RestClient {
        ///
        /// The endpoint should contain the REST path component (e.g., http://127.0.0.1:8332/rest).
        pub fn new(endpoint: HttpEndpoint) -> std::io::Result<Self> {
-               let client = Mutex::new(HttpClient::connect(&endpoint)?);
-               Ok(Self { endpoint, client })
+               Ok(Self { endpoint })
        }
 
        /// Requests a resource encoded in `F` format and interpreted as type `T`.
@@ -32,7 +28,8 @@ impl RestClient {
        where F: TryFrom<Vec<u8>, Error = std::io::Error> + TryInto<T, Error = std::io::Error> {
                let host = format!("{}:{}", self.endpoint.host(), self.endpoint.port());
                let uri = format!("{}/{}", self.endpoint.path().trim_end_matches("/"), resource_path);
-               self.client.lock().await.get::<F>(&uri, &host).await?.try_into()
+               let mut client = HttpClient::connect(&self.endpoint)?;
+               client.get::<F>(&uri, &host).await?.try_into()
        }
 }