Skip to content

Commit f665b78

Browse files
authored
feat: allow deconstruction of the journal (#116)
1 parent f3fff94 commit f665b78

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/journal/update.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ impl<'a> BlockUpdate<'a> {
4848
&self.journal
4949
}
5050

51+
/// Decompose the block update into its parts.
52+
pub fn into_parts(self) -> (u64, B256, BundleStateIndex<'a>) {
53+
(self.height, self.prev_journal_hash, self.journal)
54+
}
55+
5156
/// Serialize the block update.
5257
pub fn serialized(&self) -> &[u8] {
5358
self.serialized.get_or_init(|| JournalEncode::encoded(self)).as_ref()
@@ -74,10 +79,17 @@ impl JournalEncode for BlockUpdate<'_> {
7479
impl JournalDecode for BlockUpdate<'static> {
7580
fn decode(buf: &mut &[u8]) -> Result<Self, JournalDecodeError> {
7681
let original = *buf;
82+
let height = JournalDecode::decode(buf)?;
83+
let prev_journal_hash = JournalDecode::decode(buf)?;
84+
let journal = JournalDecode::decode(buf)?;
85+
86+
let bytes_read = original.len() - buf.len();
87+
let original = &original[..bytes_read];
88+
7789
Ok(Self {
78-
height: JournalDecode::decode(buf)?,
79-
prev_journal_hash: JournalDecode::decode(buf)?,
80-
journal: JournalDecode::decode(buf)?,
90+
height,
91+
prev_journal_hash,
92+
journal,
8193
serialized: OnceLock::from(Bytes::copy_from_slice(original)),
8294
hash: OnceLock::from(keccak256(original)),
8395
})

0 commit comments

Comments
 (0)