Struct sway_libs::merkle::sparse::InclusionProof
pub struct InclusionProof {
/// The underlying proof set.
proof_set: Vec<b256>,
}
Expand description
An Inclusion Proof for a Sparse Merkle Tree.
Fields
proof_set: Vec
The underlying proof set.
Implementations
pub fn new(proof_set: Vec<b256>) -> Self
pub fn new(proof_set: Vec<b256>) -> Self
Instantiates a new InclusionProof
from a ProofSet
.
Arguments
proof_set
: [ProofSet] - A rawProofSet
of hashes.
Returns
[InclusionProof] - A newly created InclusionProof
.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo() {
let proof_set = ProofSet::new()
let new_proof = InclusionProof::new(proof_set);
}
pub fn proof_set(self) -> Vec<b256>
pub fn proof_set(self) -> Vec<b256>
Returns the underlying ProofSet
of the InclusionProof
.
Returns
- [ProofSet] - The underlying proof set that defines the inclusion proof.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo() {
let new_proof_set = ProofSet::new()
let new_proof = InclusionProof::new(new_proof_set);
let result_proof_set = new_proof.proof_set();
assert(result_proof_set.len() == new_proof_set.len());
}
pub fn verify(
self,
root: MerkleRoot,
key: MerkleTreeKey,
leaf_data: Bytes,
) -> bool
pub fn verify(
self,
root: MerkleRoot,
key: MerkleTreeKey,
leaf_data: Bytes,
) -> bool
Verifies some data is included in a Sparse Merkle Tree against this inclusion proof.
Arguments
root
: [MerkleRoot] - The root of the Sparse Merkle Tree.key
: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.leaf_data
: [Bytes] - The raw data of the leaf.
Returns
- [bool] -
true
if the verification is successful, otherwise false.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo(proof: InclusionProof, root: MerkleRoot, key: MerkleTreeKey, leaf_data: Bytes) {
assert(proof.verify(root, key, leaf_data));
}
pub fn verify_hash(
self,
root: MerkleRoot,
key: MerkleTreeKey,
leaf_hash: b256,
) -> bool
pub fn verify_hash(
self,
root: MerkleRoot,
key: MerkleTreeKey,
leaf_hash: b256,
) -> bool
Verifies hashed data is included in a Sparse Merkle Tree against this inclusion proof.
Arguments
root
: [MerkleRoot] - The root of the Sparse Merkle Tree.key
: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.leaf_hash
: [b256] - The hashed data of the leaf.
Returns
- [bool] -
true
if the verification is successful, otherwise false.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo(proof: InclusionProof, root: MerkleRoot, key: MerkleTreeKey, leaf_hash: b256) {
assert(proof.verify(root, key, leaf_data));
}
pub fn root(self, key: MerkleTreeKey, leaf_data: Bytes) -> MerkleRoot
pub fn root(self, key: MerkleTreeKey, leaf_data: Bytes) -> MerkleRoot
Computes the root of a Sparse Merkle Tree from the proof and data.
Arguments
key
: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.leaf_data
: [Bytes] - The raw data of the leaf.
Returns
- [MerkleRoot] - The computed merkle root.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo(proof: InclusionProof, key: MerkleTreeKey, leaf_data: Bytes) {
assert(proof.root(root, key, leaf_data) != b256::zero());
}
pub fn root_from_hash(
self,
key: MerkleTreeKey,
leaf_data: b256,
) -> MerkleRoot
pub fn root_from_hash(
self,
key: MerkleTreeKey,
leaf_data: b256,
) -> MerkleRoot
Computes the root of a Sparse Merkle Tree from the proof and hashed data.
Arguments
key
: [MerkleTreeKey] - The key associated with the particular leaf in the Sparse Merkle Tree.leaf_hash
: [b256] - The hashed data of the leaf.
Returns
- [MerkleRoot] - The computed merkle root.
Examples
use sway_libs::merkle::sparse::InclusionProof;
fn foo(proof: InclusionProof, key: MerkleTreeKey, leaf_hash: b256) {
assert(proof.root(root, key, leaf_hash) != b256::zero());
}
Trait Implementations
impl AbiEncode for InclusionProof
impl AbiEncode for InclusionProof
pub fn abi_encode(self, buffer: Buffer) -> Buffer
impl AbiDecode for InclusionProof
impl AbiDecode for InclusionProof
pub fn abi_decode(refmut buffer: BufferReader) -> Self
impl PartialEq for InclusionProof
impl PartialEq for InclusionProof
pub fn eq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
pub fn neq(self, other: Self) -> bool
Evaluates if two values of the same type are not equal.
Additional Information
This function is inherited when eq()
is implemented.
Arguments
other
: [Self] - The value of the same type.
Returns
- [bool] -
true
if the two values are not equal, otherwisefalse
.
Examples
struct MyStruct {
val: u64,
}
impl PartialEq for MyStruct {
fn eq(self, other: Self) -> bool {
self.val == other.val
}
}
fn foo() {
let struct1 = MyStruct { val: 10 };
let struct2 = MyStruct { val: 2 };
let result = struct1 != struct2;
assert(result);
}