diff --git a/crates/primitives/src/transaction/tx_value.rs b/crates/primitives/src/transaction/tx_value.rs index 26da7d55817f..da1c133d0c0e 100644 --- a/crates/primitives/src/transaction/tx_value.rs +++ b/crates/primitives/src/transaction/tx_value.rs @@ -1,5 +1,5 @@ use crate::{ruint::UintTryFrom, U256}; -use alloy_rlp::{Decodable, Encodable, Error}; +use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs::{add_arbitrary_tests, Compact}; use serde::{Deserialize, Serialize}; @@ -8,7 +8,19 @@ use serde::{Deserialize, Serialize}; /// While the field is 256 bits, for many chains it's not possible for the field to use /// this full precision, hence we use a wrapper type to allow for overriding of encoding. #[add_arbitrary_tests(compact, rlp)] -#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] +#[derive( + Default, + Debug, + Copy, + Clone, + Hash, + PartialEq, + Eq, + Serialize, + Deserialize, + RlpEncodableWrapper, + RlpDecodableWrapper, +)] pub struct TxValue(U256); impl From for U256 { @@ -29,32 +41,6 @@ where } } -impl Encodable for TxValue { - #[inline] - fn encode(&self, out: &mut dyn bytes::BufMut) { - self.0.encode(out) - } - - #[inline] - fn length(&self) -> usize { - self.0.length() - } -} - -impl Decodable for TxValue { - #[inline] - fn decode(buf: &mut &[u8]) -> Result { - #[cfg(feature = "optimism")] - { - U256::decode(buf).map(Self) - } - #[cfg(not(feature = "optimism"))] - { - u128::decode(buf).map(Self::from) - } - } -} - /// As ethereum circulation on mainnet is around 120mil eth as of 2022 that is around /// 120000000000000000000000000 wei we are safe to use u128 for TxValue's encoding /// as its max number is 340282366920938463463374607431768211455.