[][src]Trait nakamoto_node::handle::Handle

pub trait Handle {
    type Event;
    type Message;
    fn get_tip(&self) -> Result<BlockHeader, Error>;
fn get_block(&self, hash: &BlockHash) -> Result<Block, Error>;
fn connect(&self, addr: SocketAddr) -> Result<Link, Error>;
fn submit_transaction(&self, tx: Transaction) -> Result<(), Error>;
fn import_headers(
        &self,
        headers: Vec<BlockHeader>
    ) -> Result<Result<ImportResult, Error>, Error>;
fn receive(&self, from: SocketAddr, msg: Self::Message) -> Result<(), Error>;
fn wait<F: Fn(Self::Event) -> Option<T>, T>(&self, f: F) -> Result<T, Error>;
fn wait_for_peers(&self, count: usize) -> Result<(), Error>;
fn wait_for_ready(&self) -> Result<(), Error>;
fn wait_for_height(&self, h: Height) -> Result<BlockHash, Error>;
fn shutdown(self) -> Result<(), Error>; }

A handle for communicating with a node process.

Associated Types

type Event

Node event generated during protocol operation.

type Message

The message payload exchanged between nodes in the network.

Loading content...

Required methods

fn get_tip(&self) -> Result<BlockHeader, Error>

Get the tip of the chain.

fn get_block(&self, hash: &BlockHash) -> Result<Block, Error>

Get a full block from the network.

fn connect(&self, addr: SocketAddr) -> Result<Link, Error>

Connect to the designated peer address.

fn submit_transaction(&self, tx: Transaction) -> Result<(), Error>

Submit a transaction to the network.

fn import_headers(
    &self,
    headers: Vec<BlockHeader>
) -> Result<Result<ImportResult, Error>, Error>

Import block headers into the node. This may cause the node to broadcast header or inventory messages to its peers.

fn receive(&self, from: SocketAddr, msg: Self::Message) -> Result<(), Error>

Have the node receive a message as if it was coming from the given peer in the network. If the peer is not connected, the message is ignored.

fn wait<F: Fn(Self::Event) -> Option<T>, T>(&self, f: F) -> Result<T, Error>

Wait for the given predicate to be fulfilled.

fn wait_for_peers(&self, count: usize) -> Result<(), Error>

Wait for a given number of peers to be connected.

fn wait_for_ready(&self) -> Result<(), Error>

Wait for the node to be ready and in sync with the blockchain.

fn wait_for_height(&self, h: Height) -> Result<BlockHash, Error>

Wait for the node's active chain to reach a certain height. The hash at that height is returned.

fn shutdown(self) -> Result<(), Error>

Shutdown the node process.

Loading content...

Implementors

impl Handle for NodeHandle[src]

type Message = NetworkMessage

type Event = Event<NetworkMessage>

fn wait<F, T>(&self, f: F) -> Result<T, Error> where
    F: Fn(Event<NetworkMessage>) -> Option<T>, 
[src]

Subscribe to the event feed, and wait for the given function to return something, or timeout if the specified amount of time has elapsed.

Loading content...