diff --git a/crates/primitives-traits/src/encoded.rs b/crates/primitives-traits/src/encoded.rs index b162fc933..885031af1 100644 --- a/crates/primitives-traits/src/encoded.rs +++ b/crates/primitives-traits/src/encoded.rs @@ -1,3 +1,4 @@ +use alloy_eips::eip2718::Encodable2718; use alloy_primitives::Bytes; /// Generic wrapper with encoded Bytes, such as transaction data. @@ -17,8 +18,8 @@ impl WithEncoded { } /// Get the encoded bytes - pub fn encoded_bytes(&self) -> Bytes { - self.0.clone() + pub const fn encoded_bytes(&self) -> &Bytes { + &self.0 } /// Get the underlying value @@ -47,6 +48,13 @@ impl WithEncoded { } } +impl WithEncoded { + /// Wraps the value with the [`Encodable2718::encoded_2718`] bytes. + pub fn from_2718_encodable(value: T) -> Self { + Self(value.encoded_2718().into(), value) + } +} + impl WithEncoded> { /// returns `None` if the inner value is `None`, otherwise returns `Some(WithEncoded)`. pub fn transpose(self) -> Option> {