Skip to content

Commit

Permalink
refactor(esplora_ext): rename scan_txs to scan and scan_txs_with_keyc…
Browse files Browse the repository at this point in the history
…hains to scan_with_keychain
  • Loading branch information
notmandatory committed Dec 7, 2023
1 parent 5bf7725 commit c761103
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
12 changes: 6 additions & 6 deletions crates/esplora/src/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait EsploraAsyncExt {
/// 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>(
async fn scan_with_keychain<K: Ord + Clone + Send>(
&self,
keychain_spks: BTreeMap<
K,
Expand All @@ -60,18 +60,18 @@ pub trait EsploraAsyncExt {
parallel_requests: usize,
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error>;

/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
/// Convenience method to call [`scan_with_keychain`] without requiring a keychain.
///
/// [`scan_txs_with_keychains`]: EsploraAsyncExt::scan_txs_with_keychains
/// [`scan_with_keychain`]: EsploraAsyncExt::scan_with_keychain
#[allow(clippy::result_large_err)]
async fn scan_txs(
async fn scan(
&self,
misc_spks: impl IntoIterator<IntoIter = impl Iterator<Item = ScriptBuf> + Send> + Send,
txids: impl IntoIterator<IntoIter = impl Iterator<Item = Txid> + Send> + Send,
outpoints: impl IntoIterator<IntoIter = impl Iterator<Item = OutPoint> + Send> + Send,
parallel_requests: usize,
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
self.scan_txs_with_keychains(
self.scan_with_keychain(
[(
(),
misc_spks
Expand Down Expand Up @@ -199,7 +199,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
})
}

async fn scan_txs_with_keychains<K: Ord + Clone + Send>(
async fn scan_with_keychain<K: Ord + Clone + Send>(
&self,
keychain_spks: BTreeMap<
K,
Expand Down
12 changes: 6 additions & 6 deletions crates/esplora/src/blocking_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait EsploraExt {
/// 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>(
fn scan_with_keychain<K: Ord + Clone>(
&self,
keychain_spks: BTreeMap<K, impl IntoIterator<Item = (u32, ScriptBuf)>>,
txids: impl IntoIterator<Item = Txid>,
Expand All @@ -55,18 +55,18 @@ pub trait EsploraExt {
parallel_requests: usize,
) -> Result<(TxGraph<ConfirmationTimeHeightAnchor>, BTreeMap<K, u32>), Error>;

/// Convenience method to call [`scan_txs_with_keychains`] without requiring a keychain.
/// Convenience method to call [`scan_with_keychain`] without requiring a keychain.
///
/// [`scan_txs_with_keychains`]: EsploraExt::scan_txs_with_keychains
/// [`scan_with_keychain`]: EsploraExt::scan_with_keychain
#[allow(clippy::result_large_err)]
fn scan_txs(
fn scan(
&self,
misc_spks: impl IntoIterator<Item = ScriptBuf>,
txids: impl IntoIterator<Item = Txid>,
outpoints: impl IntoIterator<Item = OutPoint>,
parallel_requests: usize,
) -> Result<TxGraph<ConfirmationTimeHeightAnchor>, Error> {
self.scan_txs_with_keychains(
self.scan_with_keychain(
[(
(),
misc_spks
Expand Down Expand Up @@ -190,7 +190,7 @@ impl EsploraExt for esplora_client::BlockingClient {
})
}

fn scan_txs_with_keychains<K: Ord + Clone>(
fn scan_with_keychain<K: Ord + Clone>(
&self,
keychain_spks: BTreeMap<K, impl IntoIterator<Item = (u32, ScriptBuf)>>,
txids: impl IntoIterator<Item = Txid>,
Expand Down
10 changes: 5 additions & 5 deletions crates/esplora/tests/async_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {

let graph_update = env
.client
.scan_txs(
.scan(
misc_spks.into_iter(),
vec![].into_iter(),
vec![].into_iter(),
Expand Down Expand Up @@ -168,7 +168,7 @@ pub async fn test_async_update_tx_graph_gap_limit() -> anyhow::Result<()> {
// will.
let (graph_update, active_indices) = env
.client
.scan_txs_with_keychains(
.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand All @@ -180,7 +180,7 @@ pub async fn test_async_update_tx_graph_gap_limit() -> anyhow::Result<()> {
assert!(active_indices.is_empty());
let (graph_update, active_indices) = env
.client
.scan_txs_with_keychains(
.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand Down Expand Up @@ -211,7 +211,7 @@ pub async fn test_async_update_tx_graph_gap_limit() -> anyhow::Result<()> {
// The last active indice won't be updated in the first case but will in the second one.
let (graph_update, active_indices) = env
.client
.scan_txs_with_keychains(
.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand All @@ -225,7 +225,7 @@ pub async fn test_async_update_tx_graph_gap_limit() -> anyhow::Result<()> {
assert_eq!(active_indices[&0], 3);
let (graph_update, active_indices) = env
.client
.scan_txs_with_keychains(keychains, vec![].into_iter(), vec![].into_iter(), 5, 1)
.scan_with_keychain(keychains, vec![].into_iter(), vec![].into_iter(), 5, 1)
.await?;
let txs: HashSet<_> = graph_update.full_txs().map(|tx| tx.txid).collect();
assert_eq!(txs.len(), 2);
Expand Down
18 changes: 7 additions & 11 deletions crates/esplora/tests/blocking_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
sleep(Duration::from_millis(10))
}

let graph_update = env.client.scan_txs(
let graph_update = env.client.scan(
misc_spks.into_iter(),
vec![].into_iter(),
vec![].into_iter(),
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn test_update_tx_graph_gap_limit() -> anyhow::Result<()> {

// A scan with a gap limit of 2 won't find the transaction, but a scan with a gap limit of 3
// will.
let (graph_update, active_indices) = env.client.scan_txs_with_keychains(
let (graph_update, active_indices) = env.client.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand All @@ -173,7 +173,7 @@ pub fn test_update_tx_graph_gap_limit() -> anyhow::Result<()> {
)?;
assert!(graph_update.full_txs().next().is_none());
assert!(active_indices.is_empty());
let (graph_update, active_indices) = env.client.scan_txs_with_keychains(
let (graph_update, active_indices) = env.client.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn test_update_tx_graph_gap_limit() -> anyhow::Result<()> {

// A scan with gap limit 4 won't find the second transaction, but a scan with gap limit 5 will.
// The last active indice won't be updated in the first case but will in the second one.
let (graph_update, active_indices) = env.client.scan_txs_with_keychains(
let (graph_update, active_indices) = env.client.scan_with_keychain(
keychains.clone(),
vec![].into_iter(),
vec![].into_iter(),
Expand All @@ -212,13 +212,9 @@ pub fn test_update_tx_graph_gap_limit() -> anyhow::Result<()> {
assert_eq!(txs.len(), 1);
assert!(txs.contains(&txid_4th_addr));
assert_eq!(active_indices[&0], 3);
let (graph_update, active_indices) = env.client.scan_txs_with_keychains(
keychains,
vec![].into_iter(),
vec![].into_iter(),
5,
1,
)?;
let (graph_update, active_indices) =
env.client
.scan_with_keychain(keychains, vec![].into_iter(), vec![].into_iter(), 5, 1)?;
let txs: HashSet<_> = graph_update.full_txs().map(|tx| tx.txid).collect();
assert_eq!(txs.len(), 2);
assert!(txs.contains(&txid_4th_addr) && txs.contains(&txid_last_addr));
Expand Down
4 changes: 2 additions & 2 deletions example-crates/example_esplora/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn main() -> anyhow::Result<()> {
// represents the last active spk derivation indices of keychains
// (`keychain_indices_update`).
let (graph_update, last_active_indices) = client
.scan_txs_with_keychains(
.scan_with_keychain(
keychain_spks,
core::iter::empty(),
core::iter::empty(),
Expand Down Expand Up @@ -312,7 +312,7 @@ fn main() -> anyhow::Result<()> {
}

let graph_update =
client.scan_txs(spks, txids, outpoints, scan_options.parallel_requests)?;
client.scan(spks, txids, outpoints, scan_options.parallel_requests)?;

graph.lock().unwrap().apply_update(graph_update)
}
Expand Down
2 changes: 1 addition & 1 deletion example-crates/wallet_esplora_async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> Result<(), anyhow::Error> {
})
.collect();
let (update_graph, last_active_indices) = client
.scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)
.scan_with_keychain(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)
.await?;
let missing_heights = update_graph.missing_heights(wallet.local_chain());
let chain_update = client.update_local_chain(prev_tip, missing_heights).await?;
Expand Down
2 changes: 1 addition & 1 deletion example-crates/wallet_esplora_blocking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> Result<(), anyhow::Error> {
.collect();

let (update_graph, last_active_indices) =
client.scan_txs_with_keychains(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)?;
client.scan_with_keychain(keychain_spks, None, None, STOP_GAP, PARALLEL_REQUESTS)?;
let missing_heights = update_graph.missing_heights(wallet.local_chain());
let chain_update = client.update_local_chain(prev_tip, missing_heights)?;
let update = Update {
Expand Down

0 comments on commit c761103

Please sign in to comment.