Skip to content

Commit

Permalink
feat: RlpNode::as_hash (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Oct 15, 2024
1 parent 8c47a17 commit 8a118b6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/nodes/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ impl RlpNode {
pub fn as_slice(&self) -> &[u8] {
&self.0
}

/// Returns hash if this is an RLP-encoded hash
#[inline]
pub fn as_hash(&self) -> Option<B256> {
if self.len() == B256::len_bytes() + 1 {
Some(B256::from_slice(&self.0[1..]))
} else {
None
}
}
}

#[cfg(feature = "arbitrary")]
Expand Down

0 comments on commit 8a118b6

Please sign in to comment.