diff --git a/example/bitcoin.rs b/example/bitcoin.rs index b98439ed..5688fec5 100644 --- a/example/bitcoin.rs +++ b/example/bitcoin.rs @@ -3,8 +3,8 @@ use bip157::builder::Builder; use bip157::chain::{BlockHeaderChanges, ChainState}; -use bip157::{lookup_host, Client, Event, HeaderCheckpoint, Network, ScriptBuf}; -use std::collections::HashSet; +use bip157::{Client, Event, FilterType, HeaderCheckpoint, Network}; +use std::net::{IpAddr, Ipv4Addr}; use tokio::time::Instant; const NETWORK: Network = Network::Bitcoin; @@ -15,23 +15,23 @@ async fn main() { let subscriber = tracing_subscriber::FmtSubscriber::new(); tracing::subscriber::set_global_default(subscriber).unwrap(); let now = Instant::now(); - // Add Bitcoin scripts to scan the blockchain for - let address = ScriptBuf::new_op_return(b"Kyoto light client"); - let mut addresses = HashSet::new(); - addresses.insert(address); - let seeds = lookup_host("seed.bitcoin.sipa.be").await; + // let seeds = lookup_host("seed.bitcoin.sipa.be").await; // Create a new node builder let builder = Builder::new(NETWORK); // Add node preferences and build the node/client let (node, client) = builder // The number of connections we would like to maintain - .required_peers(2) + .required_peers(1) // Only scan for taproot scripts - .chain_state(ChainState::Checkpoint( - HeaderCheckpoint::taproot_activation(), - )) + .chain_state(ChainState::Checkpoint(HeaderCheckpoint { + height: 927516, + hash: "00000000000000000001849ec8caa64852aa2299002629269ee90424c765c617" + .parse() + .unwrap(), + })) + .filter_type(FilterType::Taproot) // Add some initial peers - .add_peers(seeds.into_iter().map(From::from)) + .add_peer(IpAddr::V4(Ipv4Addr::new(65, 109, 109, 117))) // Create the node and client .build(); // Run the node on a separate task @@ -45,6 +45,7 @@ async fn main() { mut warn_rx, mut event_rx, } = client; + let mut total_bytes = 0; // Continually listen for events until the node is synced to its peers. loop { tokio::select! { @@ -60,8 +61,13 @@ async fn main() { tracing::info!("Total sync time: {sync_time} seconds"); let avg_fee_rate = requester.average_fee_rate(update.tip().hash).await.unwrap(); tracing::info!("Last block average fee rate: {:#}", avg_fee_rate); + tracing::info!("Total bytes downloaded {}", total_bytes); break; }, + Event::IndexedFilter(filter) => { + let byte_vec = filter.into_contents(); + total_bytes += byte_vec.len(); + }, Event::ChainUpdate(BlockHeaderChanges::Connected(header)) => { tracing::info!("New best tip {}", header.height); }, diff --git a/src/lib.rs b/src/lib.rs index 2e670f15..3db70170 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,12 +117,15 @@ pub enum FilterType { #[default] /// A golomb coded compact sketch based on siphash. Contains all spendable script types. Basic, + /// GCS filter only containing P2TR outputs. + Taproot, } impl From for u8 { fn from(value: FilterType) -> Self { match value { FilterType::Basic => 0x00, + FilterType::Taproot => 0x01, } } }