Struct MerkleTree

Source
#[repr(C)]
pub struct MerkleTree<H, C>
where H: Hasher, C: MerkleTreeConfig,
{ pub height: u64, pub filled_subtrees: [[u8; 32]; 18], pub roots: [[u8; 32]; 20], pub next_index: u64, pub current_root_index: u64, /* private fields */ }

Fields§

§height: u64

Height of the Merkle tree.

§filled_subtrees: [[u8; 32]; 18]

Subtree hashes.

§roots: [[u8; 32]; 20]

Full history of roots of the Merkle tree (the last one is the current one).

§next_index: u64

Next index to insert a leaf.

§current_root_index: u64

Current index of the root.

Implementations§

Source§

impl<H, C> MerkleTree<H, C>
where H: Hasher, C: MerkleTreeConfig,

Source

pub fn new(height: usize) -> Self

Create a new Merkle tree with the given height.

Source

pub fn hash(&mut self, leaf1: [u8; 32], leaf2: [u8; 32]) -> Hash

Source

pub fn insert(&mut self, leaf1: [u8; 32], leaf2: [u8; 32])

Source

pub fn is_known_root(&self, root: [u8; 32]) -> bool

Source

pub fn last_root(&self) -> [u8; 32]

Trait Implementations§

Source§

impl<H, C> Clone for MerkleTree<H, C>

Source§

fn clone(&self) -> MerkleTree<H, C>

Returns a duplicate 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<H, C> Debug for MerkleTree<H, C>

Source§

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

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

impl<H, C> PartialEq for MerkleTree<H, C>

Source§

fn eq(&self, other: &MerkleTree<H, C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<H, C> Zeroable for MerkleTree<H, C>
where H: Hasher, C: MerkleTreeConfig,

The Zeroable trait is used under the hood by the zero_copy attribute macro and is required for usage in zero-copy Solana accounts.

SAFETY: Generic parameters are used only as PhantomData and they don’t affect the layout of the struct nor its size or padding. The only reason why we can’t #[derive(Zeroable)] is because bytemuck is not aware of that and it doesn’t allow to derive Zeroable for structs with generic parameters. Would be nice to fix that upstream: https://github.com/Lokathor/bytemuck/issues/191

Source§

fn zeroed() -> Self

Source§

impl<H, C> Copy for MerkleTree<H, C>
where H: Hasher + Copy, C: MerkleTreeConfig + Copy,

Source§

impl<H, C> Eq for MerkleTree<H, C>
where H: Hasher + Eq, C: MerkleTreeConfig + Eq,

Source§

impl<H, C> Pod for MerkleTree<H, C>
where H: Hasher + Copy + 'static, C: MerkleTreeConfig + Copy + 'static,

The Pod trait is used under the hood by the zero_copy attribute macro and is required for usage in zero-copy Solana accounts.

SAFETY: Generic parameters are used only as PhantomData and they don’t affect the layout of the struct nor its size or padding. The only reason why we can’t #[derive(Pod)] is because bytemuck is not aware of that and it doesn’t allow to derive Pod for structs with generic parameters. Would be nice to fix that upstream: https://github.com/Lokathor/bytemuck/issues/191

Source§

impl<H, C> StructuralPartialEq for MerkleTree<H, C>
where H: Hasher, C: MerkleTreeConfig,

Auto Trait Implementations§

§

impl<H, C> Freeze for MerkleTree<H, C>

§

impl<H, C> RefUnwindSafe for MerkleTree<H, C>

§

impl<H, C> Send for MerkleTree<H, C>
where H: Send, C: Send,

§

impl<H, C> Sync for MerkleTree<H, C>
where H: Sync, C: Sync,

§

impl<H, C> Unpin for MerkleTree<H, C>
where H: Unpin, C: Unpin,

§

impl<H, C> UnwindSafe for MerkleTree<H, C>
where H: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AbiExample for T

Source§

default fn example() -> T

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,