Skip to content

Commit

Permalink
feat(chain): add SyncRequest and FullScanRequest structures
Browse files Browse the repository at this point in the history
remove unneeded assert_debug in tx_graph

feat(chain): add SyncRequest and FullScanRequest structures
  • Loading branch information
notmandatory committed Jan 18, 2024
1 parent 0a2a570 commit d74d9f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions crates/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ mod spk_iter;
#[cfg(feature = "miniscript")]
pub use spk_iter::*;

/// Structures for requesting data needed to sync or full scan the blockchain for chain related data.
pub mod request;

#[allow(unused_imports)]
#[macro_use]
extern crate alloc;
Expand Down
32 changes: 32 additions & 0 deletions crates/chain/src/request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::collections::BTreeMap;
use crate::local_chain::CheckPoint;
use alloc::vec::Vec;
use bitcoin::{OutPoint, ScriptBuf, Txid};

/// Data required to perform a spk-based blockchain client sync.
///
/// A client sync fetches relevant chain data for a known list of scripts, transaction ids and
/// outpoints. The sync process also extends the given local chain [`CheckPoint`].
pub struct SyncRequest {
/// Transactions that spend from or to these script pubkeys.
pub spks: Vec<ScriptBuf>,
/// Transactions with these txids.
pub txids: Vec<Txid>,
/// Transactions with these outpoints or spend from these outpoints.
pub outpoints: Vec<OutPoint>,
/// The local chain checkpoint. The sync process will return a new chain that extends this one.
pub checkpoint: CheckPoint,
}

/// Data required to perform a spk-based blockchain client full scan.
///
/// A client full scan iterates through all the scripts for the given keychains, fetching relevant
/// data until some stop gap number of scripts is found that have no data. This operation is
/// generally only used when importing or restoring previously used keychains in which the list of
/// used scripts is not known. The full scan process also extends the given local chain [`CheckPoint`].
pub struct FullScanRequest<K, I> {
/// Iterators of script pubkeys indexed by the keychain index.
pub spks_by_keychain: BTreeMap<K, I>,
/// The local chain checkpoint. The scan process will return a new chain that extends this one.
pub checkpoint: CheckPoint,
}
5 changes: 0 additions & 5 deletions crates/chain/src/tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,6 @@ impl<A: Anchor> TxGraph<A> {
}
!has_missing_height
});
#[cfg(feature = "std")]
debug_assert!({
println!("txid={} skip={}", txid, skip);
true
});
!skip
})
.filter_map(move |(a, _)| {
Expand Down

0 comments on commit d74d9f5

Please sign in to comment.