Skip to content

Commit

Permalink
feat: add Bytecode::original_bytecode_slice to match BytecodeLocked
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Apr 9, 2024
1 parent 1edfeb6 commit d896e0e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Bytecode {
if self.is_empty() {
KECCAK_EMPTY
} else {
keccak256(&self.original_bytes())
keccak256(self.original_bytecode_slice())
}
}

Expand Down Expand Up @@ -130,7 +130,18 @@ impl Bytecode {
match self.state {
BytecodeState::Raw => self.bytecode.clone(),
BytecodeState::Checked { len } | BytecodeState::Analysed { len, .. } => {
self.bytecode.slice(0..len)
self.bytecode.slice(..len)
}
}
}

/// Returns the original bytecode as a byte slice.
#[inline]
pub fn original_bytecode_slice(&self) -> &[u8] {
match self.state {
BytecodeState::Raw => &self.bytecode,
BytecodeState::Checked { len } | BytecodeState::Analysed { len, .. } => {
&self.bytecode[..len]
}
}
}
Expand Down

0 comments on commit d896e0e

Please sign in to comment.