1use alloy_primitives::{B256, U256};
23/// Account storage entry.
4///
5/// `key` is the subkey when used as a value in the `StorageChangeSets` table.
6#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
9#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
10pub struct StorageEntry {
11/// Storage key.
12pub key: B256,
13/// Value on storage key.
14pub value: U256,
15}
1617impl StorageEntry {
18/// Create a new `StorageEntry` with given key and value.
19pub const fn new(key: B256, value: U256) -> Self {
20Self { key, value }
21 }
22}
2324impl From<(B256, U256)> for StorageEntry {
25fn from((key, value): (B256, U256)) -> Self {
26Self { key, value }
27 }
28}
2930// NOTE: Removing reth_codec and manually encode subkey
31// and compress second part of the value. If we have compression
32// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
33#[cfg(any(test, feature = "reth-codec"))]
34impl reth_codecs::Compact for StorageEntry {
35fn to_compact<B>(&self, buf: &mut B) -> usize36where
37B: bytes::BufMut + AsMut<[u8]>,
38 {
39// for now put full bytes and later compress it.
40buf.put_slice(&self.key[..]);
41self.value.to_compact(buf) + 32
42}
4344fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
45let key = B256::from_slice(&buf[..32]);
46let (value, out) = U256::from_compact(&buf[32..], len - 32);
47 (Self { key, value }, out)
48 }
49}