Skip to content

Commit

Permalink
client: switch to ScriptBuf api
Browse files Browse the repository at this point in the history
  • Loading branch information
rustaceanrob committed Jun 14, 2024
1 parent c974121 commit 3162b3e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions example/rescan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions example/signet.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/node/builder.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -28,7 +28,7 @@ impl NodeBuilder {
}

/// Add Bitcoin scripts to monitor for.
pub fn add_scripts(mut self, addresses: Vec<bitcoin::Address>) -> Self {
pub fn add_scripts(mut self, addresses: HashSet<ScriptBuf>) -> Self {
self.config.addresses = addresses;
self
}
Expand Down
6 changes: 4 additions & 2 deletions src/node/config.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<(IpAddr, u16)>>,
pub addresses: Vec<bitcoin::Address>,
pub addresses: HashSet<ScriptBuf>,
pub data_path: Option<PathBuf>,
pub header_checkpoint: Option<HeaderCheckpoint>,
}
Expand Down
5 changes: 1 addition & 4 deletions src/node/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Node {
pub(crate) async fn new(
network: Network,
white_list: Whitelist,
addresses: Vec<bitcoin::Address>,
scripts: HashSet<ScriptBuf>,
data_path: Option<PathBuf>,
header_checkpoint: Option<HeaderCheckpoint>,
required_peers: usize,
Expand All @@ -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
Expand Down

0 comments on commit 3162b3e

Please sign in to comment.