Skip to content

Commit

Permalink
reinstate serde traits
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser999 committed Sep 30, 2024
1 parent d16b193 commit 3c47298
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
30 changes: 30 additions & 0 deletions crates/astria-core/src/primitive/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,31 @@ pub struct Address<T = Bech32m> {
format: PhantomData<T>,
}

// The serde impls need to be manually implemented for Address because they
// only work for Address<Bech32m> which cannot be expressed using serde
// attributes.
#[cfg(feature = "serde")]
mod _serde_impls {
use serde::de::Error as _;
impl serde::Serialize for super::Address<super::Bech32m> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.to_raw().serialize(serializer)
}
}
impl<'de> serde::Deserialize<'de> for super::Address<super::Bech32m> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
super::raw::Address::deserialize(deserializer)
.and_then(|raw| raw.try_into().map_err(D::Error::custom))
}
}
}

impl<TFormat> Clone for Address<TFormat> {
fn clone(&self) -> Self {
*self
Expand Down Expand Up @@ -657,6 +682,11 @@ where
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(try_from = "raw::TransactionId", into = "raw::TransactionId")
)]
pub struct TransactionId {
inner: [u8; TRANSACTION_ID_LEN],
}
Expand Down
24 changes: 5 additions & 19 deletions crates/astria-core/src/sequencerblock/v1alpha1/block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use std::{
collections::HashMap,
fmt::{
Display,
Formatter,
},
vec::IntoIter,
};

Expand Down Expand Up @@ -1362,6 +1358,11 @@ impl FilteredSequencerBlockError {
/// A [`Deposit`] is constructed whenever a [`BridgeLockAction`] is executed
/// and stored as part of the block's events.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(
feature = "serde",
serde(into = "crate::generated::sequencerblock::v1alpha1::Deposit")
)]
pub struct Deposit {
// the address on the sequencer to which the funds were sent to.
pub bridge_address: Address,
Expand Down Expand Up @@ -1450,21 +1451,6 @@ impl Deposit {
}
}

impl Display for Deposit {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
write!(
formatter,
"Deposit[bridge address: {}, rollup id: {}, amount: {}, asset: {}, destination chain \
address: {}]",
self.bridge_address,
self.rollup_id,
self.amount,
self.asset,
self.destination_chain_address,
)
}
}

impl From<Deposit> for crate::generated::sequencerblock::v1alpha1::Deposit {
fn from(deposit: Deposit) -> Self {
deposit.into_raw()
Expand Down
1 change: 1 addition & 0 deletions crates/astria-merkle/src/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ impl UncheckedProof {
/// The proof is the concatenation of all sibling hashes required to reconstruct
/// the Merkle tree from a leaf. This is also called the audit path.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Proof {
pub(super) audit_path: Vec<u8>,
pub(super) leaf_index: usize,
Expand Down
8 changes: 1 addition & 7 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use cnidarium::{
StateRead,
Storage,
};
use itertools::Itertools as _;
use prost::Message as _;
use sha2::{
Digest as _,
Expand Down Expand Up @@ -883,12 +882,7 @@ impl App {
let mut state_tx = StateDelta::new(self.state.clone());
let deposits_in_this_block = self.state.get_cached_block_deposits();
debug!(
deposits = %deposits_in_this_block
.iter()
.map(|(rollup_id, deposits)| {
format!("[rollup {}: {}]", rollup_id, deposits.iter().join(", "))
})
.join(", "),
deposits = %telemetry::display::json(&deposits_in_this_block),
"got block deposits from state"
);
state_tx
Expand Down

0 comments on commit 3c47298

Please sign in to comment.