Skip to content

Commit

Permalink
transaction-view debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Aug 30, 2024
1 parent 4ca1fee commit 38daec4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
9 changes: 9 additions & 0 deletions transaction-view/src/address_table_lookup_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
},
result::{Result, TransactionViewError},
},
core::fmt::{Debug, Formatter},
solana_sdk::{hash::Hash, packet::PACKET_DATA_SIZE, pubkey::Pubkey, signature::Signature},
solana_svm_transaction::message_address_table_lookup::SVMMessageAddressTableLookup,
};
Expand Down Expand Up @@ -128,6 +129,7 @@ impl AddressTableLookupMeta {
}
}

#[derive(Clone)]
pub struct AddressTableLookupIterator<'a> {
pub(crate) bytes: &'a [u8],
pub(crate) offset: usize,
Expand Down Expand Up @@ -201,6 +203,13 @@ impl ExactSizeIterator for AddressTableLookupIterator<'_> {
}
}

impl Debug for AddressTableLookupIterator<'_> {
#[cold]
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}

#[cfg(test)]
mod tests {
use {
Expand Down
9 changes: 9 additions & 0 deletions transaction-view/src/instructions_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
},
result::Result,
},
core::fmt::{Debug, Formatter},
solana_svm_transaction::instruction::SVMInstruction,
};

Expand Down Expand Up @@ -71,6 +72,7 @@ impl InstructionsMeta {
}
}

#[derive(Clone)]
pub struct InstructionsIterator<'a> {
pub(crate) bytes: &'a [u8],
pub(crate) offset: usize,
Expand Down Expand Up @@ -138,6 +140,13 @@ impl ExactSizeIterator for InstructionsIterator<'_> {
}
}

impl Debug for InstructionsIterator<'_> {
#[cold]
fn fmt(&self, f: &mut Formatter) -> core::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}

#[cfg(test)]
mod tests {
use {
Expand Down
17 changes: 9 additions & 8 deletions transaction-view/src/resolved_transaction_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use {

/// A parsed and sanitized transaction view that has had all address lookups
/// resolved.
#[derive(Debug)]
pub struct ResolvedTransactionView<D: TransactionData> {
/// The parsed and sanitized transction view.
view: TransactionView<true, D>,
Expand All @@ -37,14 +38,6 @@ impl<D: TransactionData> Deref for ResolvedTransactionView<D> {
}
}

impl<D: TransactionData> Debug for ResolvedTransactionView<D> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ResolvedTransactionView")
.field("view", &self.view)
.finish()
}
}

impl<D: TransactionData> ResolvedTransactionView<D> {
/// Given a parsed and sanitized transaction view, and a set of resolved
/// addresses, create a resolved transaction view.
Expand Down Expand Up @@ -239,6 +232,14 @@ impl<D: TransactionData> SVMMessage for ResolvedTransactionView<D> {
}
}

impl<D: TransactionData> Debug for ResolvedTransactionView<D> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ResolvedTransactionView")
.field("view", &self.view)
.finish()
}
}

#[cfg(test)]
mod tests {
use {
Expand Down
24 changes: 16 additions & 8 deletions transaction-view/src/transaction_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ pub struct TransactionView<const SANITIZED: bool, D: TransactionData> {
meta: TransactionMeta,
}

impl<const SANITIZED: bool, D: TransactionData> Debug for TransactionView<SANITIZED, D> {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("TransactionView")
.field("meta", &self.meta)
.finish()
}
}

impl<D: TransactionData> TransactionView<false, D> {
/// Creates a new `TransactionView` without running sanitization checks.
pub fn try_new_unsanitized(data: D) -> Result<Self> {
Expand Down Expand Up @@ -185,6 +177,22 @@ impl<D: TransactionData> TransactionView<true, D> {
}
}

// Manual implementation of `Debug` - avoids bound on `D`.
// Prints nicely formatted struct-ish fields even for the iterator fields.
impl<const SANITIZED: bool, D: TransactionData> Debug for TransactionView<SANITIZED, D> {
#[cold]
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("TransactionView")
.field("meta", &self.meta)
.field("signatures", &self.signatures())
.field("static_account_keys", &self.static_account_keys())
.field("recent_blockhash", &self.recent_blockhash())
.field("instructions", &self.instructions_iter())
.field("address_table_lookups", &self.address_table_lookup_iter())
.finish()
}
}

#[cfg(test)]
mod tests {
use {
Expand Down

0 comments on commit 38daec4

Please sign in to comment.