Node

Struct Node 

Source
pub struct Node {
    pub peers: Vec<Arc<RwLock<Peer>>>,
    pub blockchain: Blockchain,
    pub mempool: MemPool,
    pub last_seen_block: Hash,
    pub reserved_ips: Vec<IpAddr>,
    pub is_syncing: bool,
    pub target_peers: usize,
    pub port: u16,
}
Expand description

Handles incoming connections and outbound peers

Fields§

§peers: Vec<Arc<RwLock<Peer>>>§blockchain: Blockchain§mempool: MemPool§last_seen_block: Hash§reserved_ips: Vec<IpAddr>§is_syncing: bool§target_peers: usize§port: u16

Implementations§

Source§

impl Node

Source

pub fn new( node_path: &str, port: u16, reserved_ips: Vec<IpAddr>, ) -> Arc<RwLock<Self>>

Create a new blockchain (load / create) with default 12 nodes target WARNING: Only one instance of this struct can exist in one program

Source

pub async fn connect_peer( node: Arc<RwLock<Node>>, address: SocketAddr, ) -> Result<(Arc<RwLock<Peer>>, JoinHandle<Result<(), PeerError>>), NodeError>

Connect to a specified peer

Source

pub async fn init( node: Arc<RwLock<Node>>, seed_nodes: Vec<SocketAddr>, ) -> Result<JoinHandle<Result<(), ServerError>>, NodeError>

Initialize this node, with a array of seed nodes which this node will use to connect to Starts all handlers WARNING: Can only be called once

Source

pub async fn send_to_peers(node: Arc<RwLock<Node>>, message: Message)

Send some message to all peers

Source

pub async fn submit_block( node: Arc<RwLock<Node>>, new_block: Block, ) -> Result<(), BlockchainError>

Submit a new block to the network

Source

pub async fn submit_transaction( node: Arc<RwLock<Node>>, new_transaction: Transaction, ) -> Result<(), BlockchainError>

Submit a new transaction to the network to be mined

Source

pub fn log(msg: String)

Log a message to the node log

Source

pub fn get_last_log() -> String

Get last logged line

Source

pub fn pop_last_line() -> Option<String>

Get last popped line

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V