-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from rustaceanrob/testnet4-11-1
Testnet4 11 1
- Loading branch information
Showing
7 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use kyoto::core::messages::NodeMessage; | ||
use kyoto::{chain::checkpoints::HeaderCheckpoint, core::builder::NodeBuilder}; | ||
use kyoto::{Address, Network, TrustedPeer}; | ||
use std::collections::HashSet; | ||
use std::{net::Ipv4Addr, str::FromStr}; | ||
|
||
const NETWORK: Network = Network::Testnet4; | ||
const RECOVERY_HEIGHT: u32 = 0; | ||
|
||
// THE TESTNET4 DOES NOT CURRENTLY HAVE PEERS THAT SERVE COMPACT BLOCK FILTERS | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Add third-party logging | ||
let subscriber = tracing_subscriber::FmtSubscriber::new(); | ||
tracing::subscriber::set_global_default(subscriber).unwrap(); | ||
// Use a predefined checkpoint | ||
let checkpoint = HeaderCheckpoint::closest_checkpoint_below_height(RECOVERY_HEIGHT, NETWORK); | ||
// Add Bitcoin scripts to scan the blockchain for | ||
let address = Address::from_str("tb1qkqkt3ra8d44lt90t9thgy3lgucsjrtywwgq8yp") | ||
.unwrap() | ||
.require_network(NETWORK) | ||
.unwrap() | ||
.into(); | ||
let mut addresses = HashSet::new(); | ||
addresses.insert(address); | ||
// Add preferred peers to connect to | ||
let peer = TrustedPeer::from_ip(Ipv4Addr::new(18, 189, 156, 102)); | ||
// Create a new node builder | ||
let builder = NodeBuilder::new(NETWORK); | ||
// Add node preferences and build the node/client | ||
let (node, client) = builder | ||
// Add the peers | ||
.add_peer(peer) | ||
// 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(1) | ||
// Create the node and client | ||
.build_node() | ||
.unwrap(); | ||
|
||
// Run the node on a new task | ||
tokio::task::spawn(async move { node.run().await }); | ||
|
||
// Split the client into components that send messages and listen to messages. | ||
// With this construction, different parts of the program can take ownership of | ||
// specific tasks. | ||
let (sender, mut receiver) = client.split(); | ||
// Continually listen for events until the node is synced to its peers. | ||
loop { | ||
if let Ok(message) = receiver.recv().await { | ||
match message { | ||
NodeMessage::Dialog(d) => tracing::info!("{d}"), | ||
NodeMessage::Warning(e) => tracing::warn!("{e}"), | ||
NodeMessage::Block(b) => drop(b), | ||
NodeMessage::BlocksDisconnected(r) => { | ||
for dc in r { | ||
let warning = format!("Block disconnected {}", dc.height); | ||
tracing::warn!(warning); | ||
} | ||
} | ||
NodeMessage::Synced(update) => { | ||
tracing::info!("Synced chain up to block {}", update.tip.height); | ||
tracing::info!("Chain tip: {}", update.tip.hash); | ||
break; | ||
} | ||
NodeMessage::ConnectionsMet => { | ||
tracing::info!("Connected to all required peers"); | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
let _ = sender.shutdown().await; | ||
tracing::info!("Shutting down"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters