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: u16Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
node_path: &str,
port: u16,
reserved_ips: Vec<IpAddr>,
) -> Arc<RwLock<Self>>
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
Sourcepub async fn connect_peer(
node: Arc<RwLock<Node>>,
address: SocketAddr,
) -> Result<(Arc<RwLock<Peer>>, JoinHandle<Result<(), PeerError>>), NodeError>
pub async fn connect_peer( node: Arc<RwLock<Node>>, address: SocketAddr, ) -> Result<(Arc<RwLock<Peer>>, JoinHandle<Result<(), PeerError>>), NodeError>
Connect to a specified peer
Sourcepub async fn init(
node: Arc<RwLock<Node>>,
seed_nodes: Vec<SocketAddr>,
) -> Result<JoinHandle<Result<(), ServerError>>, NodeError>
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
Sourcepub async fn send_to_peers(node: Arc<RwLock<Node>>, message: Message)
pub async fn send_to_peers(node: Arc<RwLock<Node>>, message: Message)
Send some message to all peers
Sourcepub async fn submit_block(
node: Arc<RwLock<Node>>,
new_block: Block,
) -> Result<(), BlockchainError>
pub async fn submit_block( node: Arc<RwLock<Node>>, new_block: Block, ) -> Result<(), BlockchainError>
Submit a new block to the network
Sourcepub async fn submit_transaction(
node: Arc<RwLock<Node>>,
new_transaction: Transaction,
) -> Result<(), BlockchainError>
pub async fn submit_transaction( node: Arc<RwLock<Node>>, new_transaction: Transaction, ) -> Result<(), BlockchainError>
Submit a new transaction to the network to be mined
Sourcepub fn get_last_log() -> String
pub fn get_last_log() -> String
Get last logged line
Sourcepub fn pop_last_line() -> Option<String>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more