]> Untitled Git - bdk/commitdiff
Remove stop_gap param from Blockchain trait setup and sync functions
authorSteve Myers <steve@notmandatory.org>
Thu, 15 Jul 2021 19:04:03 +0000 (12:04 -0700)
committerSteve Myers <steve@notmandatory.org>
Fri, 16 Jul 2021 15:52:41 +0000 (08:52 -0700)
CHANGELOG.md
src/blockchain/any.rs
src/blockchain/compact_filters/mod.rs
src/blockchain/electrum.rs
src/blockchain/esplora.rs
src/blockchain/mod.rs
src/blockchain/rpc.rs
src/blockchain/utils.rs
src/wallet/mod.rs
src/wallet/verify.rs

index 02f66d0b933ccb1421ab8a355657a6b4e49df59e..fbe0c6972a0a956407e26b2bd6121b1f0d9270b2 100644 (file)
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Removed and replaced `set_single_recipient` with more general `drain_to` and replaced `maintain_single_recipient` with `allow_shrinking`.
 
+### Blockchain
+
+- Removed `stop_gap` from `Blockchain` trait and added it to only `ElectrumBlockchain` and `EsploraBlockchain` structs  
+
 ## [v0.9.0] - [v0.8.0]
 
 ### Wallet
index 9ab538619bef689b70110117f97aa319be89e9ed..d88c3b8c483c6ce433164b25be0b62c1b0ae822f 100644 (file)
@@ -39,7 +39,7 @@
 //!
 //! # #[cfg(feature = "esplora")]
 //! # {
-//! let esplora_blockchain = EsploraBlockchain::new("...", None);
+//! let esplora_blockchain = EsploraBlockchain::new("...", None, 20);
 //! let wallet_esplora: Wallet<AnyBlockchain, _> = Wallet::new(
 //!     "...",
 //!     None,
@@ -126,31 +126,17 @@ impl Blockchain for AnyBlockchain {
 
     fn setup<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
-        maybe_await!(impl_inner_method!(
-            self,
-            setup,
-            stop_gap,
-            database,
-            progress_update
-        ))
+        maybe_await!(impl_inner_method!(self, setup, database, progress_update))
     }
     fn sync<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
-        maybe_await!(impl_inner_method!(
-            self,
-            sync,
-            stop_gap,
-            database,
-            progress_update
-        ))
+        maybe_await!(impl_inner_method!(self, sync, database, progress_update))
     }
 
     fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
index d3819d08544d8a711121fb9f544a3e3626665c38..e057d162193bce2fd6bd1e19716d6066428d4a9e 100644 (file)
@@ -229,7 +229,6 @@ impl Blockchain for CompactFiltersBlockchain {
     #[allow(clippy::mutex_atomic)] // Mutex is easier to understand than a CAS loop.
     fn setup<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        _stop_gap: Option<usize>, // TODO: move to electrum and esplora only
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
index df9e72b13f21a43d60128561fcb2fa67c0d37732..53d4dabb92b40bc6f2ed66bde5b3de90df50a539 100644 (file)
@@ -70,12 +70,11 @@ impl Blockchain for ElectrumBlockchain {
 
     fn setup<D: BatchDatabase, P: Progress>(
         &self,
-        _stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
         self.client
-            .electrum_like_setup(Some(self.stop_gap), database, progress_update)
+            .electrum_like_setup(self.stop_gap, database, progress_update)
     }
 
     fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
index 7de7ad8c62f70646805561c39d71aada76b3e4cc..c0a5fc560c4fbbff82f993f1c540fd86556748a5 100644 (file)
@@ -18,7 +18,7 @@
 //!
 //! ```no_run
 //! # use bdk::blockchain::esplora::EsploraBlockchain;
-//! let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/api", None);
+//! let blockchain = EsploraBlockchain::new("https://blockstream.info/testnet/api", None, 20);
 //! # Ok::<(), bdk::Error>(())
 //! ```
 
@@ -102,13 +102,12 @@ impl Blockchain for EsploraBlockchain {
 
     fn setup<D: BatchDatabase, P: Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
         maybe_await!(self
             .url_client
-            .electrum_like_setup(stop_gap, database, progress_update))
+            .electrum_like_setup(self.stop_gap, database, progress_update))
     }
 
     fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
@@ -429,6 +428,6 @@ impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError);
 #[cfg(feature = "test-esplora")]
 crate::bdk_blockchain_tests! {
     fn test_instance(test_client: &TestClient) -> EsploraBlockchain {
-        EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), None)
+        EsploraBlockchain::new(&format!("http://{}",test_client.electrsd.esplora_url.as_ref().unwrap()), None, 20)
     }
 }
index ecd9e6cd62b183446bcc274b08d5981ab6518a39..6a382b9a0fdb3bd3aa3a37cab364c9534e7b2c21 100644 (file)
@@ -93,7 +93,6 @@ pub trait Blockchain {
     /// [`Blockchain::sync`] defaults to calling this internally if not overridden.
     fn setup<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error>;
@@ -118,11 +117,10 @@ pub trait Blockchain {
     /// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo
     fn sync<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
-        maybe_await!(self.setup(stop_gap, database, progress_update))
+        maybe_await!(self.setup(database, progress_update))
     }
 
     /// Fetch a transaction from the blockchain given its txid
@@ -218,20 +216,18 @@ impl<T: Blockchain> Blockchain for Arc<T> {
 
     fn setup<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
-        maybe_await!(self.deref().setup(stop_gap, database, progress_update))
+        maybe_await!(self.deref().setup(database, progress_update))
     }
 
     fn sync<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
-        maybe_await!(self.deref().sync(stop_gap, database, progress_update))
+        maybe_await!(self.deref().sync(database, progress_update))
     }
 
     fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
index 673d14e7c4fb98fe5a95ac987830f2e22053a27b..30f8cf348ce4b0c593e35c8809027ed4bc1cc35b 100644 (file)
@@ -106,7 +106,6 @@ impl Blockchain for RpcBlockchain {
 
     fn setup<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        stop_gap: Option<usize>,
         database: &mut D,
         progress_update: P,
     ) -> Result<(), Error> {
@@ -150,12 +149,11 @@ impl Blockchain for RpcBlockchain {
 
         self.set_node_synced_height(current_height)?;
 
-        self.sync(stop_gap, database, progress_update)
+        self.sync(database, progress_update)
     }
 
     fn sync<D: BatchDatabase, P: 'static + Progress>(
         &self,
-        _stop_gap: Option<usize>,
         db: &mut D,
         _progress_update: P,
     ) -> Result<(), Error> {
index 6258a9d32c8d9523436819867a1b5da8df3bd853..25778cace014d13531da8b0eb2e49b1c77836331 100644 (file)
@@ -53,7 +53,7 @@ pub trait ElectrumLikeSync {
 
     fn electrum_like_setup<D: BatchDatabase, P: Progress>(
         &self,
-        stop_gap: Option<usize>,
+        stop_gap: usize,
         db: &mut D,
         _progress_update: P,
     ) -> Result<(), Error> {
@@ -61,7 +61,6 @@ pub trait ElectrumLikeSync {
         let start = Instant::new();
         debug!("start setup");
 
-        let stop_gap = stop_gap.unwrap_or(20);
         let chunk_size = stop_gap;
 
         let mut history_txs_id = HashSet::new();
index ba0ab8e034248506055bde8678d94d77472af26c..1f29239fc0c178f077d306102cdb572f7ae190d6 100644 (file)
@@ -1500,17 +1500,13 @@ where
         // TODO: what if i generate an address first and cache some addresses?
         // TODO: we should sync if generating an address triggers a new batch to be stored
         if run_setup {
-            maybe_await!(self.client.setup(
-                None,
-                self.database.borrow_mut().deref_mut(),
-                progress_update,
-            ))?;
+            maybe_await!(self
+                .client
+                .setup(self.database.borrow_mut().deref_mut(), progress_update,))?;
         } else {
-            maybe_await!(self.client.sync(
-                None,
-                self.database.borrow_mut().deref_mut(),
-                progress_update,
-            ))?;
+            maybe_await!(self
+                .client
+                .sync(self.database.borrow_mut().deref_mut(), progress_update,))?;
         }
 
         #[cfg(feature = "verify")]
index ef92eae7e7d7b7964c102141b4743cbd8065d657..9b56333986fb9f869e98ff82d0be9b4e90106f73 100644 (file)
@@ -124,7 +124,6 @@ mod test {
         }
         fn setup<D: BatchDatabase, P: 'static + Progress>(
             &self,
-            _stop_gap: Option<usize>,
             _database: &mut D,
             _progress_update: P,
         ) -> Result<(), Error> {