Implement redesigned versions of EsploraExt and EsploraAsyncExt

All associated examples are also updated.
This commit is contained in:
志宇
2023-05-18 14:04:48 +08:00
parent 2952341e52
commit 5860704b2d
9 changed files with 704 additions and 177 deletions

View File

@@ -19,7 +19,6 @@ use crate::map_confirmation_time;
///
/// [`EsploraExt`]: crate::EsploraExt
/// [crate-level documentation]: crate
#[cfg(feature = "async")]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait EsploraAsyncExt {
@@ -84,7 +83,6 @@ pub trait EsploraAsyncExt {
}
}
#[cfg(feature = "async")]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl EsploraAsyncExt for esplora_client::AsyncClient {
@@ -103,7 +101,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
) -> Result<KeychainScan<K, ConfirmationTime>, Error> {
let txids = txids.into_iter();
let outpoints = outpoints.into_iter();
let parallel_requests = parallel_requests.max(1);
let parallel_requests = Ord::max(parallel_requests, 1);
let mut scan = KeychainScan::default();
let update = &mut scan.update;
let last_active_indices = &mut scan.last_active_indices;
@@ -285,7 +283,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
}
let reorg_occurred = {
if let Some(checkpoint) = update.chain().latest_checkpoint() {
if let Some(checkpoint) = ChainGraph::chain(update).latest_checkpoint() {
self.get_block_hash(checkpoint.height).await? != checkpoint.hash
} else {
false
@@ -295,8 +293,7 @@ impl EsploraAsyncExt for esplora_client::AsyncClient {
if reorg_occurred {
// A reorg occurred, so let's find out where all the txids we found are in the chain now.
// XXX: collect required because of weird type naming issues
let txids_found = update
.chain()
let txids_found = ChainGraph::chain(update)
.txids()
.map(|(_, txid)| *txid)
.collect::<Vec<_>>();