From d74d9f59495c59eafb73585325a772090f5e5440 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Thu, 21 Dec 2023 11:22:15 -0600 Subject: [PATCH] feat(chain): add SyncRequest and FullScanRequest structures remove unneeded assert_debug in tx_graph feat(chain): add SyncRequest and FullScanRequest structures --- crates/chain/src/lib.rs | 3 +++ crates/chain/src/request.rs | 32 ++++++++++++++++++++++++++++++++ crates/chain/src/tx_graph.rs | 5 ----- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 crates/chain/src/request.rs diff --git a/crates/chain/src/lib.rs b/crates/chain/src/lib.rs index 2065669714..c2d85c64c1 100644 --- a/crates/chain/src/lib.rs +++ b/crates/chain/src/lib.rs @@ -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; diff --git a/crates/chain/src/request.rs b/crates/chain/src/request.rs new file mode 100644 index 0000000000..2e9da2f985 --- /dev/null +++ b/crates/chain/src/request.rs @@ -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, + /// Transactions with these txids. + pub txids: Vec, + /// Transactions with these outpoints or spend from these outpoints. + pub outpoints: Vec, + /// 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 { + /// Iterators of script pubkeys indexed by the keychain index. + pub spks_by_keychain: BTreeMap, + /// The local chain checkpoint. The scan process will return a new chain that extends this one. + pub checkpoint: CheckPoint, +} diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index d43c160d75..417edeb176 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -705,11 +705,6 @@ impl TxGraph { } !has_missing_height }); - #[cfg(feature = "std")] - debug_assert!({ - println!("txid={} skip={}", txid, skip); - true - }); !skip }) .filter_map(move |(a, _)| {