Skip to content

Commit 159a522

Browse files
committed
fix: added async-https-native and async-https-rustls.
1 parent 43a8603 commit 159a522

File tree

4 files changed

+20
-25
lines changed

4 files changed

+20
-25
lines changed

.clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv="1.63.0"
1+
msrv="1.71.0"

Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/esplora-client/"
1010
description = "Bitcoin Esplora API client library. Supports plaintext, TLS and Onion servers. Blocking or async"
1111
keywords = ["bitcoin", "esplora"]
1212
readme = "README.md"
13-
rust-version = "1.70.0"
13+
rust-version = "1.71.0"
1414

1515
[lib]
1616
name = "esplora_client"
@@ -22,8 +22,7 @@ bitcoin = { version = "0.32", features = ["serde", "std"], default-features = fa
2222
hex = { version = "0.2", package = "hex-conservative" }
2323
log = "^0.4"
2424
minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true }
25-
async_minreq = { git = "https://github.com/psg-19/async-minreq.git", default-features = false, optional = true }
26-
serde_json = "1.0.100"
25+
async_minreq = { git = "https://github.com/psg-19/async-minreq.git", default-features = false, features = [], optional = true }
2726

2827
# default async runtime
2928
tokio = { version = "1", features = ["time"], optional = true }
@@ -43,8 +42,8 @@ blocking-https-native = ["blocking", "minreq/https-native"]
4342
blocking-https-bundled = ["blocking", "minreq/https-bundled"]
4443

4544
tokio = ["dep:tokio"]
46-
async = ["async_minreq","tokio?/time"]
45+
async = ["async_minreq", "async_minreq/json-using-serde", "tokio?/time"]
4746
async-https = ["async"]
48-
async-https-native = ["async"]
49-
async-https-rustls = ["async"]
50-
async-https-rustls-manual-roots = ["async"]
47+
async-https-native = ["async", "async_minreq/https-rustls-probe", "async_minreq/webpki-roots", "async_minreq/json-using-serde", "async_minreq/https-native"]
48+
async-https-rustls = ["async", "async_minreq/json-using-serde", "async_minreq/https-rustls-probe", "async_minreq/https-rustls"]
49+
async-https-rustls-manual-roots = ["async"]

src/async.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use std::str::FromStr;
2525
use crate::api::AddressStats;
2626
use crate::{
2727
BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus,
28-
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
28+
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES, VALID_HTTP_CODE
2929
};
30-
use async_minreq::{Method, Request};
30+
use async_minreq::{Method, Request, Response};
3131
#[allow(unused_imports)]
3232
use log::{debug, error, info, trace};
3333

@@ -77,7 +77,7 @@ impl<S: Sleeper> AsyncClient<S> {
7777
let url = format!("{}{}", self.url, path);
7878
let response = self.get_with_retry(&url).await?;
7979

80-
if response.status_code > 299 {
80+
if response.status_code > VALID_HTTP_CODE {
8181
return Err(Error::HttpResponse {
8282
status: response.status_code as u16,
8383
message: match response.as_str() {
@@ -120,7 +120,7 @@ impl<S: Sleeper> AsyncClient<S> {
120120
let url = format!("{}{}", self.url, path);
121121
let response = self.get_with_retry(&url).await?;
122122

123-
if response.status_code > 299 {
123+
if response.status_code > VALID_HTTP_CODE {
124124
return Err(Error::HttpResponse {
125125
status: response.status_code as u16,
126126
message: match response.as_str() {
@@ -129,11 +129,7 @@ impl<S: Sleeper> AsyncClient<S> {
129129
},
130130
});
131131
}
132-
serde_json::from_str(match response.as_str() {
133-
Ok(resp) => resp,
134-
Err(_) => return Err(Error::InvalidResponse),
135-
})
136-
.map_err(Error::Json)
132+
response.json().map_err(Error::AsyncMinreq)
137133
}
138134

139135
/// Make an HTTP GET request to given URL, deserializing to `Option<T>`.
@@ -168,7 +164,7 @@ impl<S: Sleeper> AsyncClient<S> {
168164
let url = format!("{}{}", self.url, path);
169165
let response = self.get_with_retry(&url).await?;
170166

171-
if response.status_code > 299 {
167+
if response.status_code > VALID_HTTP_CODE {
172168
return Err(Error::HttpResponse {
173169
status: response.status_code as u16,
174170
message: match response.as_str() {
@@ -210,7 +206,7 @@ impl<S: Sleeper> AsyncClient<S> {
210206
let url = format!("{}{}", self.url, path);
211207
let response = self.get_with_retry(&url).await?;
212208

213-
if response.status_code > 299 {
209+
if response.status_code > VALID_HTTP_CODE {
214210
return Err(Error::HttpResponse {
215211
status: response.status_code as u16,
216212
message: match response.as_str() {
@@ -259,7 +255,7 @@ impl<S: Sleeper> AsyncClient<S> {
259255
}
260256

261257
let response = request.send().await.map_err(Error::AsyncMinreq)?;
262-
if response.status_code > 299 {
258+
if response.status_code > VALID_HTTP_CODE {
263259
return Err(Error::HttpResponse {
264260
status: response.status_code as u16,
265261
message: match response.as_str() {
@@ -280,7 +276,7 @@ impl<S: Sleeper> AsyncClient<S> {
280276
pub async fn get_tx_no_opt(&self, txid: &Txid) -> Result<Transaction, Error> {
281277
match self.get_tx(txid).await {
282278
Ok(Some(tx)) => Ok(tx),
283-
Ok(None) => Err(Error::TransactionNotFound(*txid)), //look into
279+
Ok(None) => Err(Error::TransactionNotFound(*txid)),
284280
Err(e) => Err(e),
285281
}
286282
}
@@ -452,7 +448,7 @@ impl<S: Sleeper> AsyncClient<S> {
452448

453449
/// Sends a GET request to the given `url`, retrying failed attempts
454450
/// for retryable error codes until max retries hit.
455-
async fn get_with_retry(&self, url: &str) -> Result<async_minreq::Response, Error> {
451+
async fn get_with_retry(&self, url: &str) -> Result<Response, Error> {
456452
let mut delay = BASE_BACKOFF_MILLIS;
457453
let mut attempts = 0;
458454

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ const BASE_BACKOFF_MILLIS: Duration = Duration::from_millis(256);
102102
/// Default max retries.
103103
const DEFAULT_MAX_RETRIES: usize = 6;
104104

105+
/// Valid HTTP code
106+
const VALID_HTTP_CODE: i32 = 299;
107+
105108
/// Get a fee value in sats/vbytes from the estimates
106109
/// that matches the confirmation target set as parameter.
107110
///
@@ -206,8 +209,6 @@ pub enum Error {
206209
/// Error during async_minreq HTTP request
207210
#[cfg(feature = "async")]
208211
AsyncMinreq(async_minreq::Error),
209-
/// JSON Error
210-
Json(serde_json::Error),
211212
/// HTTP response error
212213
HttpResponse { status: u16, message: String },
213214
/// Invalid number returned
@@ -257,7 +258,6 @@ impl std::error::Error for Error {}
257258
impl_error!(::minreq::Error, Minreq, Error);
258259
#[cfg(feature = "async")]
259260
impl_error!(::async_minreq::Error, AsyncMinreq, Error);
260-
impl_error!(::serde_json::Error, Json, Error);
261261
impl_error!(std::num::ParseIntError, Parsing, Error);
262262
impl_error!(bitcoin::consensus::encode::Error, BitcoinEncoding, Error);
263263
impl_error!(bitcoin::hex::HexToArrayError, HexToArray, Error);

0 commit comments

Comments
 (0)