Skip to content

Commit

Permalink
Merge pull request #356 from chainbound/lore/chore/fmt
Browse files Browse the repository at this point in the history
fix(sidecar): Debug for blob transactions so it's not noisy
  • Loading branch information
thedevbirb authored Nov 5, 2024
2 parents d4bc8a8 + ee32464 commit db13a6b
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions bolt-sidecar/src/primitives/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::fmt::Debug;
use std::{borrow::Cow, fmt};

use alloy::primitives::{Address, U256};
use reth_primitives::{BlobTransactionSidecar, Bytes, PooledTransactionsElement, TxKind, TxType};
Expand Down Expand Up @@ -111,7 +112,7 @@ pub const fn tx_type_str(tx_type: TxType) -> &'static str {
}

/// A wrapper type for a full, complete transaction (i.e. with blob sidecars attached).
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub struct FullTransaction {
pub tx: PooledTransactionsElement,
pub sender: Option<Address>,
Expand All @@ -123,6 +124,35 @@ impl From<PooledTransactionsElement> for FullTransaction {
}
}

impl fmt::Debug for FullTransaction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut debug_struct = f.debug_struct("FullTransaction");

match &self.tx {
PooledTransactionsElement::BlobTransaction(blob_tx) => {
let shortened_blobs: Vec<String> =
// Use alternative `Display` to print trimmed blob
blob_tx.sidecar.blobs.iter().map(|blob| format!("{blob:#}")).collect();

debug_struct.field("tx", &"BlobTransaction");
debug_struct.field("hash", &blob_tx.hash);
debug_struct.field("transaction", &blob_tx.transaction);
debug_struct.field("signature", &blob_tx.signature);

debug_struct.field("sidecar_blobs", &shortened_blobs);
debug_struct.field("sidecar_commitments", &blob_tx.sidecar.commitments);
debug_struct.field("sidecar_proofs", &blob_tx.sidecar.proofs);
}
other => {
debug_struct.field("tx", other);
}
}

debug_struct.field("sender", &self.sender);
debug_struct.finish()
}
}

impl std::ops::Deref for FullTransaction {
type Target = PooledTransactionsElement;

Expand Down

0 comments on commit db13a6b

Please sign in to comment.