Skip to content

Commit

Permalink
update: with formate and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Feb 6, 2024
1 parent 05295d3 commit 8a01f30
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use node::Node;

pub mod merkle_proof;
pub mod merkle_proof_check;
pub mod merkle_proof_mixed;
pub mod merkle_root;
pub mod node;
pub mod tree;
pub mod merkle_proof_mixed;
pub mod utils;


pub type Proof = Vec<Node>;
pub type Hash = [u8; 32];
pub type Leaf = [u8; 32];
Expand Down
2 changes: 1 addition & 1 deletion src/merkle_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Leaf, Proof};
pub fn merkle_proof(leaves: &[Leaf], leaf: Leaf) -> Proof {
let mut proof: Proof = Vec::new();

if is_power_of_two(leaves.len() as u32) == false {
if !is_power_of_two(leaves.len() as u32) {
return merkle_proof_mixed_tree(leaves, leaf);
}

Expand Down
4 changes: 2 additions & 2 deletions src/merkle_proof_check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::hash_function;
use crate::Proof;
use crate::{Leaf, Proof};

pub fn merkle_proof_check(proof: Proof, leaf: [u8; 32]) -> [u8; 32] {
pub fn merkle_proof_check(proof: Proof, leaf: Leaf) -> Leaf {
let mut current_hash = leaf;

for node in proof {
Expand Down
5 changes: 3 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::merkle_proof::merkle_proof;
use crate::merkle_proof_check::merkle_proof_check;
use crate::merkle_root::merkle_root;
use crate::node::Node;
use crate::{Leaf, Root};
use crate::{Leaf, Proof, Root};

/// # 🌳 Merkle Tree
/// - You can pass raw data
Expand All @@ -21,7 +22,7 @@ impl MerkleTree {
}

impl MerkleTree {
pub fn make_proof(self, leaf: Leaf) -> Vec<Node> {
pub fn make_proof(&self, leaf: Leaf) -> Vec<Node> {
merkle_proof(&self.leaves, leaf)
}
}
3 changes: 1 addition & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ pub fn is_power_of_two(number: u32) -> bool {
let left: bool = number & (number - 1) == 0;
let right: bool = number != 0;

let r = left && right;
r
left && right
}

0 comments on commit 8a01f30

Please sign in to comment.