mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore: add helper for encoded (#12868)
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
use alloy_eips::eip2718::Encodable2718;
|
||||||
use alloy_primitives::Bytes;
|
use alloy_primitives::Bytes;
|
||||||
|
|
||||||
/// Generic wrapper with encoded Bytes, such as transaction data.
|
/// Generic wrapper with encoded Bytes, such as transaction data.
|
||||||
@ -17,8 +18,8 @@ impl<T> WithEncoded<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the encoded bytes
|
/// Get the encoded bytes
|
||||||
pub fn encoded_bytes(&self) -> Bytes {
|
pub const fn encoded_bytes(&self) -> &Bytes {
|
||||||
self.0.clone()
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the underlying value
|
/// Get the underlying value
|
||||||
@ -47,6 +48,13 @@ impl<T> WithEncoded<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Encodable2718> WithEncoded<T> {
|
||||||
|
/// Wraps the value with the [`Encodable2718::encoded_2718`] bytes.
|
||||||
|
pub fn from_2718_encodable(value: T) -> Self {
|
||||||
|
Self(value.encoded_2718().into(), value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> WithEncoded<Option<T>> {
|
impl<T> WithEncoded<Option<T>> {
|
||||||
/// returns `None` if the inner value is `None`, otherwise returns `Some(WithEncoded<T>)`.
|
/// returns `None` if the inner value is `None`, otherwise returns `Some(WithEncoded<T>)`.
|
||||||
pub fn transpose(self) -> Option<WithEncoded<T>> {
|
pub fn transpose(self) -> Option<WithEncoded<T>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user