Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ async fn main() {
// Only scan blocks strictly after an anchor checkpoint
.anchor_checkpoint(checkpoint)
// The number of connections we would like to maintain
.num_required_peers(1)
.required_peers(1)
// Omit informational messages
.log_level(LogLevel::Warning)
// Create the node and client
.build_node()
.build()
.unwrap();

tokio::task::spawn(async move { node.run().await });
Expand Down
4 changes: 2 additions & 2 deletions example/rescan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async fn main() {
NETWORK,
))
// The number of connections we would like to maintain
.num_required_peers(1)
.build_node()
.required_peers(1)
.build()
.unwrap();
// Run the node and wait for the sync message;
tokio::task::spawn(async move { node.run().await });
Expand Down
4 changes: 2 additions & 2 deletions example/signet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ async fn main() {
// Only scan blocks strictly after an anchor checkpoint
.anchor_checkpoint(checkpoint)
// The number of connections we would like to maintain
.num_required_peers(2)
.required_peers(2)
// Create the node and client
.build_node()
.build()
.unwrap();
// Run the node on a separate task
tokio::task::spawn(async move { node.run().await });
Expand Down
4 changes: 2 additions & 2 deletions example/testnet4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ async fn main() {
// Store a limited number of peers
.peer_db_size(PeerStoreSizeConfig::Limit(256))
// The number of connections we would like to maintain
.num_required_peers(1)
.required_peers(1)
// Create the node and client
.build_node()
.build()
.unwrap();

// Run the node on a new task
Expand Down
6 changes: 3 additions & 3 deletions example/tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ async fn main() {
// Only scan blocks strictly after an anchor checkpoint
.anchor_checkpoint(anchor)
// The number of connections we would like to maintain
.num_required_peers(2)
.required_peers(2)
// We only maintain a list of 256 peers in memory
.peer_db_size(PeerStoreSizeConfig::Limit(256))
// Connect to peers over Tor
.set_connection_type(ConnectionType::Tor(tor))
.connection_type(ConnectionType::Tor(tor))
// Build without the default databases
.build_node()
.build()
.unwrap();
// Run the node
tokio::task::spawn(async move { node.run().await });
Expand Down
20 changes: 10 additions & 10 deletions src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MAX_PEERS: u8 = 15;
/// let builder = NodeBuilder::new(Network::Regtest);
/// let (node, client) = builder
/// .add_peers(vec![host.into()])
/// .build_node()
/// .build()
/// .unwrap();
/// ```
///
Expand Down Expand Up @@ -68,8 +68,8 @@ const MAX_PEERS: u8 = 15;
/// // Only scan blocks strictly after an anchor checkpoint
/// .anchor_checkpoint(checkpoint)
/// // The number of connections we would like to maintain
/// .num_required_peers(2)
/// .build_node()
/// .required_peers(2)
/// .build()
/// .unwrap();
/// ```
pub struct NodeBuilder {
Expand Down Expand Up @@ -110,7 +110,7 @@ impl NodeBuilder {

/// Add a path to the directory where data should be stored. If none is provided, the current
/// working directory will be used.
pub fn add_data_dir(mut self, path: impl Into<PathBuf>) -> Self {
pub fn data_dir(mut self, path: impl Into<PathBuf>) -> Self {
self.config.data_path = Some(path.into());
self
}
Expand All @@ -119,7 +119,7 @@ impl NodeBuilder {
/// Adding more connections increases the node's anonymity, but requires waiting for more responses,
/// higher bandwidth, and higher memory requirements. If none is provided, a single connection will be maintained.
/// The number of connections will be clamped to a range of 1 to 15.
pub fn num_required_peers(mut self, num_peers: u8) -> Self {
pub fn required_peers(mut self, num_peers: u8) -> Self {
self.config.required_peers = num_peers.clamp(MIN_PEERS, MAX_PEERS);
self
}
Expand Down Expand Up @@ -150,7 +150,7 @@ impl NodeBuilder {
}

/// Set the desired communication channel. Either directly over TCP or over the Tor network.
pub fn set_connection_type(mut self, connection_type: ConnectionType) -> Self {
pub fn connection_type(mut self, connection_type: ConnectionType) -> Self {
self.config.connection_type = connection_type;
self
}
Expand All @@ -164,7 +164,7 @@ impl NodeBuilder {
/// nodes may be slower to respond while processing blocks and transactions.
///
/// If none is provided, a timeout of 5 seconds will be used.
pub fn set_response_timeout(mut self, response_timeout: Duration) -> Self {
pub fn response_timeout(mut self, response_timeout: Duration) -> Self {
self.config.response_timeout = response_timeout;
self
}
Expand All @@ -176,10 +176,10 @@ impl NodeBuilder {
///
/// This value is configurable as some developers may be satisfied with a peer
/// as long as the peer responds promptly. Other implementations may value finding
/// new a reliable peers faster, so the maximum connection time may be shorter.
/// new and reliable peers faster, so the maximum connection time may be shorter.
///
/// If none is provided, a maximum connection time of two hours will be used.
pub fn set_maximum_connection_time(mut self, max_connection_time: Duration) -> Self {
pub fn maximum_connection_time(mut self, max_connection_time: Duration) -> Self {
self.config.max_connection_time = max_connection_time;
self
}
Expand Down Expand Up @@ -207,7 +207,7 @@ impl NodeBuilder {
///
/// Building a node and client will error if a database connection is denied or cannot be found.
#[cfg(feature = "database")]
pub fn build_node(&mut self) -> Result<(NodeDefault, Client), SqlInitializationError> {
pub fn build(&mut self) -> Result<(NodeDefault, Client), SqlInitializationError> {
let peer_store = SqlitePeerDb::new(self.network, self.config.data_path.clone())?;
let header_store = SqliteHeaderDb::new(self.network, self.config.data_path.clone())?;
Ok(Node::new(
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
//! // Create a new node builder
//! let builder = NodeBuilder::new(Network::Signet);
//! // Add node preferences and build the node/client
//! let (mut node, client) = builder
//! let (node, client) = builder
//! // The Bitcoin scripts to monitor
//! .add_scripts(addresses)
//! // Only scan blocks strictly after an anchor checkpoint
//! .anchor_checkpoint(checkpoint)
//! // The number of connections we would like to maintain
//! .num_required_peers(2)
//! .build_node()
//! .required_peers(2)
//! .build()
//! .unwrap();
//! // Run the node and wait for the sync message;
//! tokio::task::spawn(async move { node.run().await });
Expand Down
16 changes: 8 additions & 8 deletions tests/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn new_node_sql(
let (node, client) = builder
.add_peer(host)
.add_scripts(addrs)
.add_data_dir(tempdir_path)
.build_node()
.data_dir(tempdir_path)
.build()
.unwrap();
(node, client)
}
Expand All @@ -71,9 +71,9 @@ fn new_node_anchor_sql(
let (node, client) = builder
.add_peer(trusted)
.add_scripts(addrs)
.add_data_dir(tempdir_path)
.data_dir(tempdir_path)
.anchor_checkpoint(checkpoint)
.build_node()
.build()
.unwrap();
(node, client)
}
Expand Down Expand Up @@ -596,9 +596,9 @@ async fn halting_download_works() {
let (node, client) = builder
.add_peers(vec![host.into()])
.add_scripts(scripts)
.add_data_dir(tempdir)
.data_dir(tempdir)
.halt_filter_download()
.build_node()
.build()
.unwrap();

tokio::task::spawn(async move { node.run().await });
Expand Down Expand Up @@ -649,8 +649,8 @@ async fn signet_syncs() {
let (node, client) = builder
.add_peer(host)
.add_scripts(set)
.add_data_dir(tempdir)
.build_node()
.data_dir(tempdir)
.build()
.unwrap();
tokio::task::spawn(async move { node.run().await });
async fn print_and_sync(mut client: Client) {
Expand Down