[][src]Crate nakamoto

Nakamoto is a high-assurance Bitcoin light-client library.

The project is broken down into the following crates:

  • client: the core light-client library
  • p2p: the protocol implementation
  • chain: the block store and fork selection logic
  • common: common functionality used by all crates

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, Network};
use nakamoto::client::error::Error;
use nakamoto::client::handle::Handle as _;

/// The network reactor we're going to use.
type Reactor = nakamoto::net::poll::Reactor<net::TcpStream>;

/// Run the light-client.
fn main() {
    let cfg = Config {
        network: Network::Testnet,
        ..Config::default()
    };
    // Create a client using the above network reactor.
    let client = Client::<Reactor>::new(cfg).unwrap();
    let handle = client.handle();

    // Run the client on a different thread, to not block the main thread.
    thread::spawn(|| client.run().unwrap());

    // Ask the client to terminate.
    handle.shutdown().unwrap()
}

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;

Modules

net