diff --git a/example/rescan.rs b/example/rescan.rs index 1d00fa4..5a3ad97 100644 --- a/example/rescan.rs +++ b/example/rescan.rs @@ -16,8 +16,10 @@ async fn main() { let address = bitcoin::Address::from_str("tb1q9pvjqz5u5sdgpatg3wn0ce438u5cyv85lly0pc") .unwrap() .require_network(bitcoin::Network::Signet) - .unwrap(); - let addresses = vec![address]; + .unwrap() + .into(); + let mut addresses = HashSet::new(); + addresses.insert(address); // Add preferred peers to connect to let peer = IpAddr::V4(Ipv4Addr::new(95, 217, 198, 121)); let peer_2 = IpAddr::V4(Ipv4Addr::new(23, 137, 57, 100)); @@ -73,7 +75,6 @@ async fn main() { sender.add_scripts(new_scripts).await.unwrap(); // // Tell the node to look for these new scripts sender.rescan().await.unwrap(); - // Continually listen for events until the node has rescaned the filters. loop { if let Ok(message) = receiver.recv().await { match message { diff --git a/example/signet.rs b/example/signet.rs index 75c6372..1c7be67 100644 --- a/example/signet.rs +++ b/example/signet.rs @@ -1,6 +1,7 @@ use bitcoin::BlockHash; use kyoto::node::messages::NodeMessage; use kyoto::{chain::checkpoints::HeaderCheckpoint, node::builder::NodeBuilder}; +use std::collections::HashSet; use std::{ net::{IpAddr, Ipv4Addr}, str::FromStr, @@ -15,8 +16,10 @@ async fn main() { let address = bitcoin::Address::from_str("tb1q9pvjqz5u5sdgpatg3wn0ce438u5cyv85lly0pc") .unwrap() .require_network(bitcoin::Network::Signet) - .unwrap(); - let addresses = vec![address]; + .unwrap() + .into(); + let mut addresses = HashSet::new(); + addresses.insert(address); // Add preferred peers to connect to let peer = IpAddr::V4(Ipv4Addr::new(95, 217, 198, 121)); let peer_2 = IpAddr::V4(Ipv4Addr::new(23, 137, 57, 100)); diff --git a/src/node/builder.rs b/src/node/builder.rs index 3141372..26a982b 100644 --- a/src/node/builder.rs +++ b/src/node/builder.rs @@ -1,6 +1,6 @@ -use std::{net::IpAddr, path::PathBuf}; +use std::{collections::HashSet, net::IpAddr, path::PathBuf}; -use bitcoin::Network; +use bitcoin::{Network, ScriptBuf}; use crate::chain::checkpoints::HeaderCheckpoint; @@ -28,7 +28,7 @@ impl NodeBuilder { } /// Add Bitcoin scripts to monitor for. - pub fn add_scripts(mut self, addresses: Vec) -> Self { + pub fn add_scripts(mut self, addresses: HashSet) -> Self { self.config.addresses = addresses; self } diff --git a/src/node/config.rs b/src/node/config.rs index d147cf8..2ab30b6 100644 --- a/src/node/config.rs +++ b/src/node/config.rs @@ -1,11 +1,13 @@ -use std::{net::IpAddr, path::PathBuf}; +use std::{collections::HashSet, net::IpAddr, path::PathBuf}; + +use bitcoin::ScriptBuf; use crate::chain::checkpoints::HeaderCheckpoint; pub(crate) struct NodeConfig { pub required_peers: u8, pub white_list: Option>, - pub addresses: Vec, + pub addresses: HashSet, pub data_path: Option, pub header_checkpoint: Option, } diff --git a/src/node/node.rs b/src/node/node.rs index 56e24f6..e7f61df 100644 --- a/src/node/node.rs +++ b/src/node/node.rs @@ -83,7 +83,7 @@ impl Node { pub(crate) async fn new( network: Network, white_list: Whitelist, - addresses: Vec, + scripts: HashSet, data_path: Option, header_checkpoint: Option, required_peers: usize, @@ -105,9 +105,6 @@ impl Node { // Load the headers from storage let db = SqliteHeaderDb::new(network, checkpoint, data_path) .map_err(|_| NodeError::LoadError(PersistenceError::HeaderLoadError))?; - // Take the canonical Bitcoin addresses and map them to a script we can scan for - let mut scripts = HashSet::new(); - scripts.extend(addresses.iter().map(|address| address.script_pubkey())); // A structured way to talk to the client let mut dialog = Dialog::new(ntx); // Build the chain