diff --git a/crates/core/src/spk_client.rs b/crates/core/src/spk_client.rs index 64fe3dd8c..366ec8f8c 100644 --- a/crates/core/src/spk_client.rs +++ b/crates/core/src/spk_client.rs @@ -383,14 +383,46 @@ impl SyncRequest { SyncIter::::new(self) } + /// Drain and iterate over [`Txid`]s contained in this request, consuming them. + pub fn drain_txids(&mut self) -> impl ExactSizeIterator + '_ { + SyncIter::::new(self) + } + + /// Drain and iterate over [`OutPoint`]s contained in this request, consuming them. + pub fn drain_outpoints(&mut self) -> impl ExactSizeIterator + '_ { + SyncIter::::new(self) + } + /// Iterate over [`Txid`]s contained in this request. + #[deprecated( + note = "use `drain_txids` for consuming iteration or `txids` for read-only iteration" + )] pub fn iter_txids(&mut self) -> impl ExactSizeIterator + '_ { - SyncIter::::new(self) + self.drain_txids() } /// Iterate over [`OutPoint`]s contained in this request. + #[deprecated( + note = "use `drain_outpoints` for consuming iteration or `outpoints` for read-only iteration" + )] pub fn iter_outpoints(&mut self) -> impl ExactSizeIterator + '_ { - SyncIter::::new(self) + self.drain_outpoints() + } + + /// Iterate over script pubkeys (with indexes) contained in this request, without + /// consuming them. + pub fn spks(&self) -> impl ExactSizeIterator + '_ { + self.spks.iter() + } + + /// Iterate over [`Txid`]s contained in this request, without consuming them. + pub fn txids(&self) -> impl ExactSizeIterator + '_ { + self.txids.iter() + } + + /// Iterate over [`OutPoint`]s contained in this request, without consuming them. + pub fn outpoints(&self) -> impl ExactSizeIterator + '_ { + self.outpoints.iter() } fn _call_inspect(&mut self, item: SyncItem) { diff --git a/crates/electrum/src/bdk_electrum_client.rs b/crates/electrum/src/bdk_electrum_client.rs index a7c943150..3e8aba193 100644 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@ -238,13 +238,13 @@ impl BdkElectrumClient { self.populate_with_txids( start_time, &mut tx_update, - request.iter_txids(), + request.drain_txids(), &mut pending_anchors, )?; self.populate_with_outpoints( start_time, &mut tx_update, - request.iter_outpoints(), + request.drain_outpoints(), &mut pending_anchors, )?; diff --git a/crates/esplora/src/async_ext.rs b/crates/esplora/src/async_ext.rs index 2b3828952..311c8d6a8 100644 --- a/crates/esplora/src/async_ext.rs +++ b/crates/esplora/src/async_ext.rs @@ -145,7 +145,7 @@ where self, start_time, &mut inserted_txs, - request.iter_txids(), + request.drain_txids(), parallel_requests, ) .await?, @@ -155,7 +155,7 @@ where self, start_time, &mut inserted_txs, - request.iter_outpoints(), + request.drain_outpoints(), parallel_requests, ) .await?, diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 225b574ea..4e4a85ae0 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -133,14 +133,14 @@ impl EsploraExt for esplora_client::BlockingClient { self, start_time, &mut inserted_txs, - request.iter_txids(), + request.drain_txids(), parallel_requests, )?); tx_update.extend(fetch_txs_with_outpoints( self, start_time, &mut inserted_txs, - request.iter_outpoints(), + request.drain_outpoints(), parallel_requests, )?);