From d4b0ebc618a214872c4dd5f7b75f446edf97622f Mon Sep 17 00:00:00 2001 From: rakita Date: Sun, 12 May 2024 14:36:13 +0300 Subject: [PATCH] feat: Add bytes to Bytecode (#1396) * fix(eip2935): Preload blockchash storage address * chore: add bytes fn --- crates/primitives/src/bytecode.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/primitives/src/bytecode.rs b/crates/primitives/src/bytecode.rs index 2e44672659..232d61f66d 100644 --- a/crates/primitives/src/bytecode.rs +++ b/crates/primitives/src/bytecode.rs @@ -110,6 +110,26 @@ impl Bytecode { !matches!(self, Self::LegacyRaw(_)) } + /// Returns bytes + #[inline] + pub fn bytes(&self) -> Bytes { + match self { + Self::LegacyRaw(bytes) => bytes.clone(), + Self::LegacyAnalyzed(analyzed) => analyzed.bytecode().clone(), + Self::Eof(eof) => eof.raw().clone(), + } + } + + /// Returns bytes slice + #[inline] + pub fn bytes_slice(&self) -> &[u8] { + match self { + Self::LegacyRaw(bytes) => bytes, + Self::LegacyAnalyzed(analyzed) => analyzed.bytecode(), + Self::Eof(eof) => eof.raw(), + } + } + /// Returns a reference to the original bytecode. #[inline] pub fn original_bytes(&self) -> Bytes {