From 556bb15d2da2de5a30302cea90950ad5caa9b3d4 Mon Sep 17 00:00:00 2001 From: Richard Janis Goldschmidt Date: Tue, 7 Jan 2025 15:35:10 +0100 Subject: [PATCH] feat(core): add Protobuf for FilteredSequencerBlock this is non-breaking, because FilteredSequencerBlock retains its inherent methods and only gets an additional trait impl. --- .../src/sequencerblock/v1/block.rs | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/crates/astria-core/src/sequencerblock/v1/block.rs b/crates/astria-core/src/sequencerblock/v1/block.rs index 7ec3422f4..f084aa380 100644 --- a/crates/astria-core/src/sequencerblock/v1/block.rs +++ b/crates/astria-core/src/sequencerblock/v1/block.rs @@ -9,8 +9,8 @@ use bytes::Bytes; use indexmap::IndexMap; use sha2::Sha256; use tendermint::{ - account, Time, + account, }; use super::{ @@ -24,22 +24,22 @@ use super::{ raw, }; use crate::{ + Protobuf, primitive::v1::{ - asset, - derive_merkle_tree_from_rollup_txs, Address, AddressError, IncorrectRollupIdLength, RollupId, TransactionId, TransactionIdError, + asset, + derive_merkle_tree_from_rollup_txs, }, protocol::transaction::v1::{ - action, Transaction, TransactionError, + action, }, - Protobuf as _, }; #[derive(Debug, thiserror::Error)] @@ -938,14 +938,11 @@ impl SequencerBlock { let proof = rollup_transaction_tree .construct_proof(i) .expect("the proof must exist because the tree was derived with the same leaf"); - rollup_transactions.insert( + rollup_transactions.insert(rollup_id, RollupTransactions { rollup_id, - RollupTransactions { - rollup_id, - transactions: data, // TODO: rename this field? - proof, - }, - ); + transactions: data, // TODO: rename this field? + proof, + }); } rollup_transactions.sort_unstable_keys(); @@ -1368,6 +1365,27 @@ impl FilteredSequencerBlock { } } +impl Protobuf for FilteredSequencerBlock { + type Error = FilteredSequencerBlockError; + type Raw = raw::FilteredSequencerBlock; + + fn try_from_raw_ref(raw: &Self::Raw) -> Result { + Self::try_from_raw(raw.clone()) + } + + fn to_raw(&self) -> Self::Raw { + self.clone().into_raw() + } + + fn try_from_raw(raw: Self::Raw) -> Result { + Self::try_from_raw(raw) + } + + fn into_raw(self) -> Self::Raw { + self.into_raw() + } +} + #[derive(Debug, thiserror::Error)] #[error(transparent)] pub struct FilteredSequencerBlockError(FilteredSequencerBlockErrorKind);