Skip to content

Commit 8187765

Browse files
committed
Merge #171: Add Error::SerdeJson variant and remove unwraps on submit_package
d651e71 chore(client): remove `serde_json` unwraps in favor of `Error::SerdeJson` (Luis Schwab) d7cd704 feat(lib)!: add `Error::SerdeJson` variant (Luis Schwab) d6a07af chore(deps): bump `electrsd` to v0.36.1 (Luis Schwab) 31a8dc4 chore(ci): fix pins for 1.75.0 MSRV (Luis Schwab) Pull request description: Closes #161. Replaces #163. This PR adds a new error variant for `serde_json` and removes the lingering unwraps on the `submit_package` methods. ### Changelog Notice ``` # Added - New `Error::SerdeJson` error variant ``` Also bumps `electrsd` to v0.36.1 and fixes MSRV dependency pinning. ACKs for top commit: oleonardolima: ACK d651e71 Tree-SHA512: b011e2bb3fba5eb05ba08c6349c39acef680f29524e6142bb392ecd2257bc51384ccd8a4b98021ee4d24ed26ea99c6857771bd1c57a0c2ca3481ffdd3eebd939
2 parents 788b67b + d651e71 commit 8187765

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

.github/workflows/cont_integration.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ jobs:
5151
if: matrix.rust.version == '1.75.0'
5252
run: |
5353
cargo update -p minreq --precise "2.13.2"
54-
cargo update -p home --precise "0.5.9"
55-
cargo update -p native-tls --precise "0.2.13"
5654
cargo update -p idna_adapter --precise "1.2.0"
55+
cargo update -p native-tls --precise "0.2.13"
5756
cargo update -p zerofrom --precise "0.1.5"
5857
cargo update -p litemap --precise "0.7.4"
5958
- name: Build

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tokio = { version = "1", features = ["time"], optional = true }
3333

3434
[dev-dependencies]
3535
tokio = { version = "1.20.1", features = ["full"] }
36-
electrsd = { version = "0.33.0", features = ["legacy", "esplora_a33e97e1", "corepc-node_28_0"] }
36+
electrsd = { version = "0.36.1", features = ["legacy", "esplora_a33e97e1", "corepc-node_29_0"] }
3737
lazy_static = "1.4.0"
3838

3939
[features]

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ To build with the MSRV you will need to pin dependencies as follows:
2020

2121
```shell
2222
cargo update -p minreq --precise "2.13.2"
23-
cargo update -p home --precise "0.5.9"
24-
cargo update -p native-tls --precise "0.2.13"
2523
cargo update -p idna_adapter --precise "1.2.0"
24+
cargo update -p native-tls --precise "0.2.13"
2625
cargo update -p zerofrom --precise "0.1.5"
2726
cargo update -p litemap --precise "0.7.4"
2827
```

src/async.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ impl<S: Sleeper> AsyncClient<S> {
394394
maxfeerate: Option<f64>,
395395
maxburnamount: Option<f64>,
396396
) -> Result<SubmitPackageResult, Error> {
397+
let serialized_txs = transactions
398+
.iter()
399+
.map(|tx| serialize_hex(&tx))
400+
.collect::<Vec<_>>();
401+
397402
let mut queryparams = HashSet::<(&str, String)>::new();
398403
if let Some(maxfeerate) = maxfeerate {
399404
queryparams.insert(("maxfeerate", maxfeerate.to_string()));
@@ -402,15 +407,10 @@ impl<S: Sleeper> AsyncClient<S> {
402407
queryparams.insert(("maxburnamount", maxburnamount.to_string()));
403408
}
404409

405-
let serialized_txs = transactions
406-
.iter()
407-
.map(|tx| serialize_hex(&tx))
408-
.collect::<Vec<_>>();
409-
410410
let response = self
411411
.post_request_bytes(
412412
"/txs/package",
413-
serde_json::to_string(&serialized_txs).unwrap_or_default(),
413+
serde_json::to_string(&serialized_txs).map_err(Error::SerdeJson)?,
414414
Some(queryparams),
415415
)
416416
.await?;

src/blocking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl BlockingClient {
332332
let mut request = self.post_request(
333333
"/txs/package",
334334
serde_json::to_string(&serialized_txs)
335-
.unwrap_or_default()
335+
.map_err(Error::SerdeJson)?
336336
.into_bytes(),
337337
)?;
338338

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ impl Builder {
204204
pub enum Error {
205205
/// Error during `minreq` HTTP request
206206
#[cfg(feature = "blocking")]
207-
Minreq(::minreq::Error),
208-
/// Error during reqwest HTTP request
207+
Minreq(minreq::Error),
208+
/// Error during `reqwest` HTTP request
209209
#[cfg(feature = "async")]
210-
Reqwest(::reqwest::Error),
210+
Reqwest(reqwest::Error),
211+
/// Error during JSON (de)serialization
212+
SerdeJson(serde_json::Error),
211213
/// HTTP response error
212214
HttpResponse {
213215
/// The HTTP status code returned by the server.
@@ -263,6 +265,7 @@ impl std::error::Error for Error {}
263265
impl_error!(::minreq::Error, Minreq, Error);
264266
#[cfg(feature = "async")]
265267
impl_error!(::reqwest::Error, Reqwest, Error);
268+
impl_error!(serde_json::Error, SerdeJson, Error);
266269
impl_error!(std::num::ParseIntError, Parsing, Error);
267270
impl_error!(bitcoin::consensus::encode::Error, BitcoinEncoding, Error);
268271
impl_error!(bitcoin::hex::HexToArrayError, HexToArray, Error);

0 commit comments

Comments
 (0)