Skip to content

Commit de249b6

Browse files
committed
Merge #159: chore(submit_package): use unwrap_or_default instead of .unwrap()
ea9b5d1 refactor(blocking): propagate `hex-conservative` errors instead of `.unwrap()`. (Leonardo Lima) c2c5485 refactor(submit_package): use `unwrap_or_default` instead of `.unwrap()` (Leonardo Lima) Pull request description: ### Description - use `unwrap_or_default()` instead of `.unwrap()`, ideally it should return a specific error variant, it'd be a breaking change though and can be added in a follow-up. - it's only possible to use the internal `minreq::Error` to wrap the `serde_json::Error`, but not the `reqwest::Error` as it does not have public constructors. ### Notes to the reviewers I personally wanted to remove the `.unwrap()` and properly handle the error, though the options I had in mind: - (i) adding a new `SerdeJson` variant is a breaking change; we can do it as a follow-up for 0.13.0 - (ii) mapping and wrapping it into either minreq/reqwest errors is only possible in minreq, so I thought it's better to keep it standard and use `.unwrap_or_default()` on both for now. ACKs for top commit: luisschwab: ACK ea9b5d1 ValuedMammal: ACK ea9b5d1 Tree-SHA512: 860e9351e256b8bd494d6cac259986b20b2e97c4955abce5cbe1663f47df48665262d440954899177c2482377d2ef558cd8fe6d32f635b61b3ba2be1e03a92ae
2 parents e0f7985 + ea9b5d1 commit de249b6

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<S: Sleeper> AsyncClient<S> {
410410
let response = self
411411
.post_request_bytes(
412412
"/txs/package",
413-
serde_json::to_string(&serialized_txs).unwrap(),
413+
serde_json::to_string(&serialized_txs).unwrap_or_default(),
414414
Some(queryparams),
415415
)
416416
.await?;

src/blocking.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl BlockingClient {
144144
}
145145
Ok(resp) => {
146146
let hex_str = resp.as_str().map_err(Error::Minreq)?;
147-
let hex_vec = Vec::from_hex(hex_str).unwrap();
147+
let hex_vec = Vec::from_hex(hex_str)?;
148148
deserialize::<T>(&hex_vec)
149149
.map_err(Error::BitcoinEncoding)
150150
.map(|r| Some(r))
@@ -162,7 +162,7 @@ impl BlockingClient {
162162
}
163163
Ok(resp) => {
164164
let hex_str = resp.as_str().map_err(Error::Minreq)?;
165-
let hex_vec = Vec::from_hex(hex_str).unwrap();
165+
let hex_vec = Vec::from_hex(hex_str)?;
166166
deserialize::<T>(&hex_vec).map_err(Error::BitcoinEncoding)
167167
}
168168
Err(e) => Err(e),
@@ -332,9 +332,8 @@ impl BlockingClient {
332332
let mut request = self.post_request(
333333
"/txs/package",
334334
serde_json::to_string(&serialized_txs)
335-
.unwrap()
336-
.as_bytes()
337-
.to_vec(),
335+
.unwrap_or_default()
336+
.into_bytes(),
338337
)?;
339338

340339
if let Some(maxfeerate) = maxfeerate {

0 commit comments

Comments
 (0)