Expand description
Nakamoto is a high-assurance Bitcoin light-client library.
The project is broken down into the following crates:
client
: the core light-client libraryp2p
: the protocol implementationchain
: the block store and fork selection logiccommon
: common functionality used by all cratesnet
: networking backend
The client
crate is intended to be the entry point for most users of the
library, and is a good place to start, to see how everything fits together.
use std::{net, thread};
use nakamoto::client::{Client, Config, Error};
use nakamoto::client::network::{Network, Services};
use nakamoto::client::traits::Handle as _;
/// The network reactor we're going to use.
type Reactor = nakamoto::net::poll::Reactor<net::TcpStream>;
/// Run the light-client.
fn main() -> Result<(), Error> {
let cfg = Config::new(Network::Testnet);
// Create a client using the above network reactor.
let client = Client::<Reactor>::new()?;
let handle = client.handle();
// Run the client on a different thread, to not block the main thread.
thread::spawn(|| client.run(cfg).unwrap());
// Wait for the client to be connected to a peer.
handle.wait_for_peers(1, Services::default())?;
// Ask the client to terminate.
handle.shutdown()?;
Ok(())
}
Re-exports
pub use nakamoto_chain as chain;
pub use nakamoto_client as client;
pub use nakamoto_common as common;
pub use nakamoto_p2p as p2p;