reth_db_models/
accounts.rsuse reth_codecs::{add_arbitrary_tests, Compact};
use serde::Serialize;
use alloy_primitives::{bytes::Buf, Address};
use reth_primitives_traits::Account;
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary, serde::Deserialize))]
#[add_arbitrary_tests(compact)]
pub struct AccountBeforeTx {
pub address: Address,
pub info: Option<Account>,
}
impl Compact for AccountBeforeTx {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
buf.put_slice(self.address.as_slice());
let mut acc_len = 0;
if let Some(account) = self.info {
acc_len = account.to_compact(buf);
}
acc_len + 20
}
fn from_compact(mut buf: &[u8], len: usize) -> (Self, &[u8]) {
let address = Address::from_slice(&buf[..20]);
buf.advance(20);
let info = (len - 20 > 0).then(|| {
let (acc, advanced_buf) = Account::from_compact(buf, len - 20);
buf = advanced_buf;
acc
});
(Self { address, info }, buf)
}
}