diff --git a/transaction-view/src/address_table_lookup_meta.rs b/transaction-view/src/address_table_lookup_meta.rs index 7757841d79f9eb..e35802c4380852 100644 --- a/transaction-view/src/address_table_lookup_meta.rs +++ b/transaction-view/src/address_table_lookup_meta.rs @@ -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, }; @@ -128,6 +129,7 @@ impl AddressTableLookupMeta { } } +#[derive(Clone)] pub struct AddressTableLookupIterator<'a> { pub(crate) bytes: &'a [u8], pub(crate) offset: usize, @@ -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 { diff --git a/transaction-view/src/instructions_meta.rs b/transaction-view/src/instructions_meta.rs index a3f3131c7fe5b5..8b08379e890af4 100644 --- a/transaction-view/src/instructions_meta.rs +++ b/transaction-view/src/instructions_meta.rs @@ -6,6 +6,7 @@ use { }, result::Result, }, + core::fmt::{Debug, Formatter}, solana_svm_transaction::instruction::SVMInstruction, }; @@ -71,6 +72,7 @@ impl InstructionsMeta { } } +#[derive(Clone)] pub struct InstructionsIterator<'a> { pub(crate) bytes: &'a [u8], pub(crate) offset: usize, @@ -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 { diff --git a/transaction-view/src/resolved_transaction_view.rs b/transaction-view/src/resolved_transaction_view.rs index b7e61fcd10f4bd..bef0224375f539 100644 --- a/transaction-view/src/resolved_transaction_view.rs +++ b/transaction-view/src/resolved_transaction_view.rs @@ -20,6 +20,7 @@ use { /// A parsed and sanitized transaction view that has had all address lookups /// resolved. +#[derive(Debug)] pub struct ResolvedTransactionView { /// The parsed and sanitized transction view. view: TransactionView, @@ -37,14 +38,6 @@ impl Deref for ResolvedTransactionView { } } -impl Debug for ResolvedTransactionView { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - f.debug_struct("ResolvedTransactionView") - .field("view", &self.view) - .finish() - } -} - impl ResolvedTransactionView { /// Given a parsed and sanitized transaction view, and a set of resolved /// addresses, create a resolved transaction view. @@ -239,6 +232,14 @@ impl SVMMessage for ResolvedTransactionView { } } +impl Debug for ResolvedTransactionView { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ResolvedTransactionView") + .field("view", &self.view) + .finish() + } +} + #[cfg(test)] mod tests { use { diff --git a/transaction-view/src/transaction_view.rs b/transaction-view/src/transaction_view.rs index fd4872a9c12d88..77524722f65d1c 100644 --- a/transaction-view/src/transaction_view.rs +++ b/transaction-view/src/transaction_view.rs @@ -26,14 +26,6 @@ pub struct TransactionView { meta: TransactionMeta, } -impl Debug for TransactionView { - fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - f.debug_struct("TransactionView") - .field("meta", &self.meta) - .finish() - } -} - impl TransactionView { /// Creates a new `TransactionView` without running sanitization checks. pub fn try_new_unsanitized(data: D) -> Result { @@ -185,6 +177,22 @@ impl TransactionView { } } +// Manual implementation of `Debug` - avoids bound on `D`. +// Prints nicely formatted struct-ish fields even for the iterator fields. +impl Debug for TransactionView { + #[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 {