pub struct Node { /* private fields */ }Expand description
A node in the DAG containing a transaction or consensus message
§Examples
use qudag_dag::{Node, NodeState};
// Create a new node with payload and no parents (genesis node)
let payload = b"Hello, DAG!".to_vec();
let node = Node::new(payload.clone(), vec![]);
assert_eq!(node.payload(), &payload);
assert_eq!(node.state(), NodeState::Pending);
assert!(node.parents().is_empty());
// Hash is computed deterministically
let hash = node.hash();
assert_eq!(hash.as_bytes().len(), 32);Implementations§
Source§impl Node
impl Node
Sourcepub fn new(payload: Vec<u8>, parents: Vec<Hash>) -> Self
pub fn new(payload: Vec<u8>, parents: Vec<Hash>) -> Self
Creates a new node with the given payload and parents
§Examples
use qudag_dag::Node;
// Create a genesis node (no parents)
let payload = b"Genesis block".to_vec();
let node = Node::new(payload, vec![]);
// Create a child node
let parent_hash = node.hash();
let child_payload = b"Child block".to_vec();
let child_node = Node::new(child_payload, vec![parent_hash]);Sourcepub fn update_state(&mut self, new_state: NodeState) -> Result<()>
pub fn update_state(&mut self, new_state: NodeState) -> Result<()>
Updates node state if transition is valid
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Node
impl<'de> Deserialize<'de> for Node
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more