Skip to content

Commit

Permalink
Refactor: Add method to SMT node to set prefix (#70)
Browse files Browse the repository at this point in the history
* Minor SMT node refactor

* Undo assert change
  • Loading branch information
bvrooman authored Mar 1, 2022
1 parent 5b76431 commit e766cf6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fuel-merkle/src/sparse/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Node {
let buffer = Self::default_buffer();
let mut node = Self { buffer };
node.set_height(0);
node.set_bytes_prefix(&[LEAF]);
node.set_prefix(LEAF);
node.set_bytes_lo(key);
node.set_bytes_hi(&sum(data));
node
Expand All @@ -44,7 +44,7 @@ impl Node {
let buffer = Self::default_buffer();
let mut node = Self { buffer };
node.set_height(left_child.height() + 1);
node.set_bytes_prefix(&[NODE]);
node.set_prefix(NODE);
node.set_bytes_lo(&left_child.hash());
node.set_bytes_hi(&right_child.hash());
node
Expand Down Expand Up @@ -75,6 +75,11 @@ impl Node {
self.bytes_prefix()[0]
}

pub fn set_prefix(&mut self, prefix: u8) {
let bytes = prefix.to_be_bytes();
self.set_bytes_prefix(&bytes);
}

pub fn leaf_key(&self) -> &Bytes32 {
assert!(self.is_leaf());
self.bytes_lo().try_into().unwrap()
Expand Down

0 comments on commit e766cf6

Please sign in to comment.