Skip to content

Commit

Permalink
ref(esplora): Box a large esplora_client::Error
Browse files Browse the repository at this point in the history
to address `clippy::result_large_err`. Clippy's default large-error-
threshold is 128. `esplora_client::Error` currently has size 272.
  • Loading branch information
ValuedMammal committed Nov 6, 2023
1 parent 2b52918 commit f90d696
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 7 additions & 4 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ use bdk_chain::{
local_chain::{self, CheckPoint},
BlockId, ConfirmationTimeAnchor, TxGraph,
};
use esplora_client::{Error, TxStatus};
use esplora_client::TxStatus;
use futures::{stream::FuturesOrdered, TryStreamExt};

use crate::{anchor_from_status, ASSUME_FINAL_DEPTH};

/// `Box` a large [`esplora_client::Error`]
type Error = Box<esplora_client::Error>;

/// Alias `Result` to use our `Error`
type Result<T, E = Error> = core::result::Result<T, E>;

/// Trait to extend the functionality of [`esplora_client::AsyncClient`].
///
/// Refer to [crate-level documentation] for more.
Expand All @@ -29,7 +35,6 @@ pub trait EsploraAsyncExt {
/// [`LocalChain`]: bdk_chain::local_chain::LocalChain
/// [`LocalChain::tip`]: bdk_chain::local_chain::LocalChain::tip
/// [`LocalChain::apply_update`]: bdk_chain::local_chain::LocalChain::apply_update
#[allow(clippy::result_large_err)]
async fn update_local_chain(
&self,
local_tip: Option<CheckPoint>,
Expand All @@ -47,7 +52,6 @@ pub trait EsploraAsyncExt {
/// The scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
/// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
/// parallel.
#[allow(clippy::result_large_err)]
async fn scan_txs_with_keychains<K: Ord + Clone + Send>(
&self,
keychain_spks: BTreeMap<
Expand All @@ -63,7 +67,6 @@ pub trait EsploraAsyncExt {
/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
///
/// [`scan_txs_with_keychains`]: EsploraAsyncExt::scan_txs_with_keychains
#[allow(clippy::result_large_err)]
async fn scan_txs(
&self,
misc_spks: impl IntoIterator<IntoIter = impl Iterator<Item = ScriptBuf> + Send> + Send,
Expand Down
18 changes: 13 additions & 5 deletions crates/esplora/src/blocking_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ use bdk_chain::{
local_chain::{self, CheckPoint},
BlockId, ConfirmationTimeAnchor, TxGraph,
};
use esplora_client::{Error, TxStatus};
use esplora_client::TxStatus;

use crate::{anchor_from_status, ASSUME_FINAL_DEPTH};

/// `Box` a large [`esplora_client::Error`]
type Error = Box<esplora_client::Error>;

/// Alias `Result` to use our `Error`
type Result<T, E = Error> = core::result::Result<T, E>;

/// Trait to extend the functionality of [`esplora_client::BlockingClient`].
///
/// Refer to [crate-level documentation] for more.
Expand All @@ -27,7 +33,6 @@ pub trait EsploraExt {
/// [`LocalChain`]: bdk_chain::local_chain::LocalChain
/// [`LocalChain::tip`]: bdk_chain::local_chain::LocalChain::tip
/// [`LocalChain::apply_update`]: bdk_chain::local_chain::LocalChain::apply_update
#[allow(clippy::result_large_err)]
fn update_local_chain(
&self,
local_tip: Option<CheckPoint>,
Expand All @@ -45,7 +50,6 @@ pub trait EsploraExt {
/// The scan for each keychain stops after a gap of `stop_gap` script pubkeys with no associated
/// transactions. `parallel_requests` specifies the max number of HTTP requests to make in
/// parallel.
#[allow(clippy::result_large_err)]
fn scan_txs_with_keychains<K: Ord + Clone>(
&self,
keychain_spks: BTreeMap<K, impl IntoIterator<Item = (u32, ScriptBuf)>>,
Expand All @@ -58,7 +62,6 @@ pub trait EsploraExt {
/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
///
/// [`scan_txs_with_keychains`]: EsploraExt::scan_txs_with_keychains
#[allow(clippy::result_large_err)]
fn scan_txs(
&self,
misc_spks: impl IntoIterator<Item = ScriptBuf>,
Expand Down Expand Up @@ -271,7 +274,12 @@ impl EsploraExt for esplora_client::BlockingClient {
.map(|txid| {
std::thread::spawn({
let client = self.clone();
move || client.get_tx_status(&txid).map(|s| (txid, s))
move || {
client
.get_tx_status(&txid)
.map_err(Box::new)
.map(|s| (txid, s))
}
})
})
.collect::<Vec<JoinHandle<Result<(Txid, TxStatus), Error>>>>();
Expand Down

0 comments on commit f90d696

Please sign in to comment.