Remove stop_gap param from Blockchain trait setup and sync functions
This commit is contained in:
parent
7e986fd904
commit
a5919f4ab0
@ -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`.
|
- 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]
|
## [v0.9.0] - [v0.8.0]
|
||||||
|
|
||||||
### Wallet
|
### Wallet
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
//!
|
//!
|
||||||
//! # #[cfg(feature = "esplora")]
|
//! # #[cfg(feature = "esplora")]
|
||||||
//! # {
|
//! # {
|
||||||
//! let esplora_blockchain = EsploraBlockchain::new("...", None);
|
//! let esplora_blockchain = EsploraBlockchain::new("...", None, 20);
|
||||||
//! let wallet_esplora: Wallet<AnyBlockchain, _> = Wallet::new(
|
//! let wallet_esplora: Wallet<AnyBlockchain, _> = Wallet::new(
|
||||||
//! "...",
|
//! "...",
|
||||||
//! None,
|
//! None,
|
||||||
@ -126,31 +126,17 @@ impl Blockchain for AnyBlockchain {
|
|||||||
|
|
||||||
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
maybe_await!(impl_inner_method!(
|
maybe_await!(impl_inner_method!(self, setup, database, progress_update))
|
||||||
self,
|
|
||||||
setup,
|
|
||||||
stop_gap,
|
|
||||||
database,
|
|
||||||
progress_update
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
maybe_await!(impl_inner_method!(
|
maybe_await!(impl_inner_method!(self, sync, database, progress_update))
|
||||||
self,
|
|
||||||
sync,
|
|
||||||
stop_gap,
|
|
||||||
database,
|
|
||||||
progress_update
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
|
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
|
||||||
|
@ -229,7 +229,6 @@ impl Blockchain for CompactFiltersBlockchain {
|
|||||||
#[allow(clippy::mutex_atomic)] // Mutex is easier to understand than a CAS loop.
|
#[allow(clippy::mutex_atomic)] // Mutex is easier to understand than a CAS loop.
|
||||||
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
_stop_gap: Option<usize>, // TODO: move to electrum and esplora only
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -70,12 +70,11 @@ impl Blockchain for ElectrumBlockchain {
|
|||||||
|
|
||||||
fn setup<D: BatchDatabase, P: Progress>(
|
fn setup<D: BatchDatabase, P: Progress>(
|
||||||
&self,
|
&self,
|
||||||
_stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
self.client
|
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> {
|
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! # use bdk::blockchain::esplora::EsploraBlockchain;
|
//! # 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>(())
|
//! # Ok::<(), bdk::Error>(())
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
@ -102,13 +102,12 @@ impl Blockchain for EsploraBlockchain {
|
|||||||
|
|
||||||
fn setup<D: BatchDatabase, P: Progress>(
|
fn setup<D: BatchDatabase, P: Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
maybe_await!(self
|
maybe_await!(self
|
||||||
.url_client
|
.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> {
|
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")]
|
#[cfg(feature = "test-esplora")]
|
||||||
crate::bdk_blockchain_tests! {
|
crate::bdk_blockchain_tests! {
|
||||||
fn test_instance(test_client: &TestClient) -> EsploraBlockchain {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,6 @@ pub trait Blockchain {
|
|||||||
/// [`Blockchain::sync`] defaults to calling this internally if not overridden.
|
/// [`Blockchain::sync`] defaults to calling this internally if not overridden.
|
||||||
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
@ -118,11 +117,10 @@ pub trait Blockchain {
|
|||||||
/// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo
|
/// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo
|
||||||
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> 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
|
/// 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>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> 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>(
|
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> 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> {
|
fn get_tx(&self, txid: &Txid) -> Result<Option<Transaction>, Error> {
|
||||||
|
@ -106,7 +106,6 @@ impl Blockchain for RpcBlockchain {
|
|||||||
|
|
||||||
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
|
||||||
database: &mut D,
|
database: &mut D,
|
||||||
progress_update: P,
|
progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -150,12 +149,11 @@ impl Blockchain for RpcBlockchain {
|
|||||||
|
|
||||||
self.set_node_synced_height(current_height)?;
|
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>(
|
fn sync<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
_stop_gap: Option<usize>,
|
|
||||||
db: &mut D,
|
db: &mut D,
|
||||||
_progress_update: P,
|
_progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -53,7 +53,7 @@ pub trait ElectrumLikeSync {
|
|||||||
|
|
||||||
fn electrum_like_setup<D: BatchDatabase, P: Progress>(
|
fn electrum_like_setup<D: BatchDatabase, P: Progress>(
|
||||||
&self,
|
&self,
|
||||||
stop_gap: Option<usize>,
|
stop_gap: usize,
|
||||||
db: &mut D,
|
db: &mut D,
|
||||||
_progress_update: P,
|
_progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
@ -61,7 +61,6 @@ pub trait ElectrumLikeSync {
|
|||||||
let start = Instant::new();
|
let start = Instant::new();
|
||||||
debug!("start setup");
|
debug!("start setup");
|
||||||
|
|
||||||
let stop_gap = stop_gap.unwrap_or(20);
|
|
||||||
let chunk_size = stop_gap;
|
let chunk_size = stop_gap;
|
||||||
|
|
||||||
let mut history_txs_id = HashSet::new();
|
let mut history_txs_id = HashSet::new();
|
||||||
|
@ -1500,17 +1500,13 @@ where
|
|||||||
// TODO: what if i generate an address first and cache some addresses?
|
// 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
|
// TODO: we should sync if generating an address triggers a new batch to be stored
|
||||||
if run_setup {
|
if run_setup {
|
||||||
maybe_await!(self.client.setup(
|
maybe_await!(self
|
||||||
None,
|
.client
|
||||||
self.database.borrow_mut().deref_mut(),
|
.setup(self.database.borrow_mut().deref_mut(), progress_update,))?;
|
||||||
progress_update,
|
|
||||||
))?;
|
|
||||||
} else {
|
} else {
|
||||||
maybe_await!(self.client.sync(
|
maybe_await!(self
|
||||||
None,
|
.client
|
||||||
self.database.borrow_mut().deref_mut(),
|
.sync(self.database.borrow_mut().deref_mut(), progress_update,))?;
|
||||||
progress_update,
|
|
||||||
))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "verify")]
|
#[cfg(feature = "verify")]
|
||||||
|
@ -124,7 +124,6 @@ mod test {
|
|||||||
}
|
}
|
||||||
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
fn setup<D: BatchDatabase, P: 'static + Progress>(
|
||||||
&self,
|
&self,
|
||||||
_stop_gap: Option<usize>,
|
|
||||||
_database: &mut D,
|
_database: &mut D,
|
||||||
_progress_update: P,
|
_progress_update: P,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user