[][src]Struct starling::merkle_bit::MerkleBIT

pub struct MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    DatabaseType: Database<ArrayType, NodeType = NodeType>,
    BranchType: Branch<ArrayType>,
    LeafType: Leaf<ArrayType>,
    DataType: Data,
    NodeType: Node<BranchType, LeafType, DataType, ArrayType>,
    HasherType: Hasher<ArrayType>,
    ArrayType: Array,
    ValueType: Decode + Encode
{ /* fields omitted */ }

The MerkleBIT structure relies on many specified types:

Required Type Annotations

  • DatabaseType: The type to use for database-like operations. DatabaseType must implement the Database trait.
  • BranchType: The type used for representing branches in the tree. BranchType must implement the Branch trait.
  • LeafType: The type used for representing leaves in the tree. LeafType must implement the Leaf trait.
  • DataType: The type used for representing data nodes in the tree. DataType must implement the Data trait.
  • NodeType: The type used for the outer node that can be either a branch, leaf, or data. NodeType must implement the Node trait.
  • HasherType: The type of hasher to use for hashing locations on the tree. HasherType must implement the Hasher trait.
  • ValueType: The type to return from a get. ValueType must implement the Encode and Decode traits.
  • ArrayType: The type that stores the keys and hash results. ArrayType must implement the Array trait.

Properties

  • db: The database to store and retrieve values.
  • depth: The maximum permitted depth of the tree.

Implementations

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    DatabaseType: Database<ArrayType, NodeType = NodeType>,
    BranchType: Branch<ArrayType>,
    LeafType: Leaf<ArrayType>,
    DataType: Data,
    NodeType: Node<BranchType, LeafType, DataType, ArrayType>,
    HasherType: Hasher<ArrayType, HashType = HasherType>,
    ValueType: Decode + Encode,
    ArrayType: Array
[src]

pub fn new(path: &PathBuf, depth: usize) -> BinaryMerkleTreeResult<Self>[src]

Create a new MerkleBIT from a saved database

Errors

Exception generated if the open fails.

pub fn from_db(db: DatabaseType, depth: usize) -> BinaryMerkleTreeResult<Self>[src]

Create a new MerkleBIT from an already opened database

Errors

None.

pub fn get(
    &self,
    root_hash: &ArrayType,
    keys: &mut [ArrayType]
) -> BinaryMerkleTreeResult<HashMap<ArrayType, Option<ValueType>>>
[src]

Get items from the MerkleBIT. Returns a map of Options which may include the corresponding values.

Errors

Exception generated when an invalid state is encountered during tree traversal.

pub fn insert(
    &mut self,
    previous_root: Option<&ArrayType>,
    keys: &mut [ArrayType],
    values: &[ValueType]
) -> BinaryMerkleTreeResult<ArrayType>
[src]

Insert items into the MerkleBIT. Keys must be sorted. Returns a new root hash for the MerkleBIT.

Errors

Exception generated if an invalid state is encountered during tree traversal.

pub fn remove(&mut self, root_hash: &ArrayType) -> BinaryMerkleTreeResult<()>[src]

Remove all items with less than 1 reference under the given root.

Errors

Exception generated when an invalid state is encountered during tree traversal.

pub fn generate_inclusion_proof(
    &self,
    root: &ArrayType,
    key: ArrayType
) -> BinaryMerkleTreeResult<Vec<(ArrayType, bool)>>
[src]

Generates an inclusion proof. The proof consists of a list of hashes beginning with the key/value pair and traveling up the tree until the level below the root is reached.

Errors

Exception generated when an invalid state is encountered during tree traversal.

pub fn verify_inclusion_proof(
    root: &ArrayType,
    key: ArrayType,
    value: &ValueType,
    proof: &[(ArrayType, bool)]
) -> BinaryMerkleTreeResult<()>
[src]

Verifies an inclusion proof.

Errors

Exception generated when the given proof is invalid.

pub fn get_one(
    &self,
    root: &ArrayType,
    key: &ArrayType
) -> BinaryMerkleTreeResult<Option<ValueType>>
[src]

Gets a single key from the tree.

Errors

Exception generated from encountering an invalid state during tree traversal.

pub fn insert_one(
    &mut self,
    previous_root: Option<&ArrayType>,
    key: &ArrayType,
    value: &ValueType
) -> BinaryMerkleTreeResult<ArrayType>
[src]

Inserts a single value into a tree.

Errors

Exception generated if an invalid state is encountered during tree traversal.

Auto Trait Implementations

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> RefUnwindSafe for MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    ArrayType: RefUnwindSafe,
    BranchType: RefUnwindSafe,
    DataType: RefUnwindSafe,
    DatabaseType: RefUnwindSafe,
    HasherType: RefUnwindSafe,
    LeafType: RefUnwindSafe,
    NodeType: RefUnwindSafe,
    ValueType: RefUnwindSafe

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> Send for MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    ArrayType: Send,
    BranchType: Send,
    DataType: Send,
    DatabaseType: Send,
    HasherType: Send,
    LeafType: Send,
    NodeType: Send,
    ValueType: Send

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> Sync for MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    ArrayType: Sync,
    BranchType: Sync,
    DataType: Sync,
    DatabaseType: Sync,
    HasherType: Sync,
    LeafType: Sync,
    NodeType: Sync,
    ValueType: Sync

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> Unpin for MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    ArrayType: Unpin,
    BranchType: Unpin,
    DataType: Unpin,
    DatabaseType: Unpin,
    HasherType: Unpin,
    LeafType: Unpin,
    NodeType: Unpin,
    ValueType: Unpin

impl<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> UnwindSafe for MerkleBIT<DatabaseType, BranchType, LeafType, DataType, NodeType, HasherType, ValueType, ArrayType> where
    ArrayType: UnwindSafe,
    BranchType: UnwindSafe,
    DataType: UnwindSafe,
    DatabaseType: UnwindSafe,
    HasherType: UnwindSafe,
    LeafType: UnwindSafe,
    NodeType: UnwindSafe,
    ValueType: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.