pub enum Node {
    Inner(InnerNode),
    Leaf(LeafNode),
}
Expand description

An enum representing the types of nodes in the indexed Merkle Tree.

This enum allows for the differentiation between inner and leaf nodes in the tree, facilitating operations like traversal, insertion, and proof generation. It encapsulates either an InnerNode or a LeafNode, depending on the node’s position and role in the tree.

Variants:

  • Inner(InnerNode): An inner node of the tree, containing references to child nodes.
  • Leaf(LeafNode): A leaf node, containing the actual data (hash of its metadata).

Variants§

Implementations§

source§

impl Node

source

pub const EMPTY_HASH: &'static str = "0000000000000000000000000000000000000000000000000000000000000000"

A placeholder for label/value values in inactive (empty) leaf nodes in the indexed Merkle Tree. It’s also the fixed label of the first element in the indexed Merkle tree, because it’s the lowest possible number in with 256 output bits from sha256.

source

pub const TAIL: &'static str = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

This constant is used to designate the last element (because it’s the highest possible number in with 256 output bits from sha256) in the indexed Merkle tree. The next pointer from the largest label in the current tree, as well as the next pointer from inactive leaf nodes “point” to it.

source

pub fn get_hash(&self) -> String

Returns the hash of the node.

This function returns the hash of either an inner node or a leaf node, depending on the node type.

source

pub fn is_left_sibling(&self) -> bool

Determines if the node is a left sibling.

This function checks whether the node (either inner or leaf) is a left sibling in its parent node’s context. This information is important in the tree’s traversal and structure maintenance, ensuring the correct positioning and integrity of the nodes.

source

pub fn is_active(&self) -> bool

Determines if the node is active.

For inner nodes, this function always returns true. For leaf nodes, it checks the active flag. This method is important to understand the current state of a node within the tree, especially for insert operations to recognize the need for capacity duplication of the tree if necessary.

source

pub fn set_left_sibling_value(&mut self, is_left: bool)

Sets the left sibling status of the node.

This function updates whether the node (inner or leaf) is considered a left sibling. This is crucial for maintaining the structural integrity of the tree, especially when nodes are inserted or reorganized.

source

pub fn set_node_active(&mut self)

Activates a leaf node.

This function sets the active flag of a leaf node to true. It has no effect on inner nodes, because they are always active. Activating a leaf node can be an important operation when managing the data within the indexed Merkle Tree, especially in scenarios involving data updates or dynamic tree modifications.

source

pub fn initialize_leaf( active: bool, is_left: bool, label: String, value: String, next: String ) -> Self

Initializes a new leaf node with the specified properties.

This function creates a leaf node with above defined attributes. The hash is generated based on
its active status, label, value, and next pointer. Additionally, the node is marked as a left sibling or not.

Arguments
  • active - Boolean indicating if the leaf is active.
  • is_left - Boolean indicating if this is a left sibling.
  • label - Unique 256 bit identifier for the leaf.
  • value - 256 Bit data value of the leaf.
  • next - Reference to the next largest node (identified by the label value) in the sequence.
source

pub fn add_left(&mut self, left: Arc<Self>)

Attaches a node as the left child of an inner node.

This function sets the provided node as the left child of the current inner node.

Arguments
  • left - An Arc<Self> pointing to the node to be set as the left child.
source

pub fn add_right(&mut self, right: Arc<Self>)

Attaches a node as the right child of an inner node.

This function sets the provided node as the right child of the current inner node.

Arguments
  • right - An Arc<Self> pointing to the node to be set as the right child.
source

pub fn update_next_pointer(existing_node: &mut Self, new_node: &Self)

Updates the ‘next’ pointer of a leaf node.

This function is used to update the reference to the next node in the indexed Merkle Tree.

Arguments
  • existing_node - The leaf node to update.
  • new_node - The new node whose label will be used for the ‘next’ pointer.
source

pub fn generate_hash(&mut self)

Generates and updates the hash for the node.

This function computes the hash of a node based on its type and properties. For an inner node, the hash is generated from the concatenated hashes of its left and right children in form of: SHA256(left_child_hash || right_child_hash) For a leaf node, the hash is based on its active status, label, value, and the reference to the next node in the tree: SHA256(active || label || value || next)

Trait Implementations§

source§

impl Clone for Node

source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Node

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Node

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,