Skip to main content

foundry_common_fmt/
ui.rs

1//! Helper trait and functions to format Ethereum types.
2
3use alloy_consensus::{
4    BlockHeader, Eip658Value, Signed, Transaction as TxTrait, TxEip1559, TxEip2930, TxEip4844,
5    TxEip4844Variant, TxEip7702, TxEnvelope, TxLegacy, TxReceipt, Typed2718,
6    transaction::TxHashRef,
7};
8use alloy_eips::eip7702::SignedAuthorization;
9use alloy_network::{
10    AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTransactionReceipt, AnyTxEnvelope,
11    BlockResponse, Network, ReceiptResponse, primitives::HeaderResponse,
12};
13use alloy_primitives::{
14    Address, Bloom, Bytes, FixedBytes, I256, Signature, U8, U64, U256, Uint, hex,
15};
16use alloy_rpc_types::{
17    AccessListItem, Block, BlockTransactions, Header, Log, Transaction, TransactionReceipt,
18};
19use alloy_serde::{OtherFields, WithOtherFields};
20use serde::{Deserialize, Serialize};
21use std::num::NonZeroU64;
22use tempo_alloy::{
23    primitives::{
24        AASigned, TempoSignature, TempoTransaction, TempoTxEnvelope,
25        transaction::{Call, PrimitiveSignature},
26    },
27    rpc::{TempoHeaderResponse, TempoTransactionReceipt},
28};
29
30#[cfg(feature = "base")]
31use base_common_consensus::{
32    BaseReceipt, BaseTxEnvelope, Eip8130Signed, TxDeposit as BaseTxDeposit,
33};
34#[cfg(feature = "base")]
35use base_common_rpc_types::{BaseTransactionReceipt, Transaction as BaseRpcTransaction};
36
37#[cfg(feature = "optimism")]
38use op_alloy_consensus::{OpTxEnvelope, TxDeposit, TxPostExec};
39
40/// length of the name column for pretty formatting `{:>20}{value}`
41const NAME_COLUMN_LEN: usize = 20usize;
42
43/// Helper trait to format Ethereum types.
44///
45/// # Examples
46///
47/// ```
48/// use foundry_common_fmt::UIfmt;
49///
50/// let boolean: bool = true;
51/// let string = boolean.pretty();
52/// ```
53pub trait UIfmt {
54    /// Return a prettified string version of the value
55    fn pretty(&self) -> String;
56}
57
58impl<T: UIfmt> UIfmt for &T {
59    fn pretty(&self) -> String {
60        (*self).pretty()
61    }
62}
63
64impl<T: UIfmt> UIfmt for Option<T> {
65    fn pretty(&self) -> String {
66        if let Some(inner) = self { inner.pretty() } else { String::new() }
67    }
68}
69
70impl<T: UIfmt> UIfmt for [T] {
71    fn pretty(&self) -> String {
72        if self.is_empty() {
73            "[]".to_string()
74        } else {
75            let mut s = String::with_capacity(self.len() * 64);
76            s.push_str("[\n");
77            for item in self {
78                for line in item.pretty().lines() {
79                    s.push('\t');
80                    s.push_str(line);
81                    s.push('\n');
82                }
83            }
84            s.push(']');
85            s
86        }
87    }
88}
89
90impl UIfmt for String {
91    fn pretty(&self) -> String {
92        self.clone()
93    }
94}
95
96impl UIfmt for u64 {
97    fn pretty(&self) -> String {
98        self.to_string()
99    }
100}
101
102impl UIfmt for NonZeroU64 {
103    fn pretty(&self) -> String {
104        self.get().pretty()
105    }
106}
107
108impl UIfmt for u128 {
109    fn pretty(&self) -> String {
110        self.to_string()
111    }
112}
113
114impl UIfmt for bool {
115    fn pretty(&self) -> String {
116        self.to_string()
117    }
118}
119
120impl<const BITS: usize, const LIMBS: usize> UIfmt for Uint<BITS, LIMBS> {
121    fn pretty(&self) -> String {
122        self.to_string()
123    }
124}
125
126impl UIfmt for I256 {
127    fn pretty(&self) -> String {
128        self.to_string()
129    }
130}
131
132impl UIfmt for Address {
133    fn pretty(&self) -> String {
134        self.to_string()
135    }
136}
137
138impl UIfmt for Bloom {
139    fn pretty(&self) -> String {
140        self.to_string()
141    }
142}
143
144impl UIfmt for Vec<u8> {
145    fn pretty(&self) -> String {
146        self[..].pretty()
147    }
148}
149
150impl UIfmt for Bytes {
151    fn pretty(&self) -> String {
152        self[..].pretty()
153    }
154}
155
156impl<const N: usize> UIfmt for [u8; N] {
157    fn pretty(&self) -> String {
158        self[..].pretty()
159    }
160}
161
162impl<const N: usize> UIfmt for FixedBytes<N> {
163    fn pretty(&self) -> String {
164        self[..].pretty()
165    }
166}
167
168impl UIfmt for [u8] {
169    fn pretty(&self) -> String {
170        hex::encode_prefixed(self)
171    }
172}
173
174impl UIfmt for Eip658Value {
175    fn pretty(&self) -> String {
176        match self {
177            Self::Eip658(status) => if *status { "1 (success)" } else { "0 (failed)" }.to_string(),
178            Self::PostState(state) => state.pretty(),
179        }
180    }
181}
182
183impl UIfmt for Signature {
184    fn pretty(&self) -> String {
185        format!("[r: {}, s: {}, y_parity: {}]", self.r(), self.s(), self.v())
186    }
187}
188
189/// Pretty-prints the common fields of any `TransactionReceipt<T>`.
190fn pretty_receipt<T: TxReceipt>(receipt: &TransactionReceipt<T>, tx_type: u8) -> String
191where
192    T::Log: Serialize,
193{
194    let mut pretty = format!(
195        "
196blockHash            {}
197blockNumber          {}
198contractAddress      {}
199cumulativeGasUsed    {}
200effectiveGasPrice    {}
201from                 {}
202gasUsed              {}
203logs                 {}
204logsBloom            {}
205root                 {}
206status               {}
207transactionHash      {}
208transactionIndex     {}
209type                 {}
210blobGasPrice         {}
211blobGasUsed          {}",
212        receipt.block_hash.pretty(),
213        receipt.block_number.pretty(),
214        receipt.contract_address.pretty(),
215        receipt.inner.cumulative_gas_used().pretty(),
216        receipt.effective_gas_price.pretty(),
217        receipt.from.pretty(),
218        receipt.gas_used.pretty(),
219        serde_json::to_string(receipt.inner.logs()).unwrap(),
220        receipt.inner.bloom().pretty(),
221        receipt.inner.status_or_post_state().as_post_state().pretty(),
222        receipt.inner.status_or_post_state().pretty(),
223        receipt.transaction_hash.pretty(),
224        receipt.transaction_index.pretty(),
225        tx_type,
226        receipt.blob_gas_price.pretty(),
227        receipt.blob_gas_used.pretty()
228    );
229
230    if let Some(to) = receipt.to {
231        pretty.push_str(&format!("\nto                   {}", to.pretty()));
232    }
233
234    pretty
235}
236
237impl UIfmt for TransactionReceipt {
238    fn pretty(&self) -> String {
239        pretty_receipt(self, self.transaction_type() as u8)
240    }
241}
242
243#[cfg(feature = "base")]
244impl UIfmt for BaseTransactionReceipt {
245    fn pretty(&self) -> String {
246        let (deposit_nonce, deposit_receipt_version) = match &self.inner.inner.receipt {
247            BaseReceipt::Deposit(receipt) => {
248                (receipt.deposit_nonce, receipt.deposit_receipt_version)
249            }
250            _ => (None, None),
251        };
252        format!(
253            "{}
254l1GasPrice           {}
255l1GasUsed            {}
256l1Fee                {}
257l1FeeScalar          {}
258l1BaseFeeScalar      {}
259l1BlobBaseFee        {}
260l1BlobBaseFeeScalar  {}
261operatorFeeScalar    {}
262operatorFeeConstant  {}
263daFootprintGasScalar {}
264depositNonce         {}
265depositReceiptVersion {}
266payer                {}
267phaseStatuses        {}
268metadata             {}",
269            pretty_receipt(&self.inner, self.inner.inner.receipt.tx_type() as u8).trim_end(),
270            self.l1_block_info.l1_gas_price.pretty(),
271            self.l1_block_info.l1_gas_used.pretty(),
272            self.l1_block_info.l1_fee.pretty(),
273            self.l1_block_info.l1_fee_scalar.map(|value| value.to_string()).unwrap_or_default(),
274            self.l1_block_info.l1_base_fee_scalar.pretty(),
275            self.l1_block_info.l1_blob_base_fee.pretty(),
276            self.l1_block_info.l1_blob_base_fee_scalar.pretty(),
277            self.l1_block_info.operator_fee_scalar.pretty(),
278            self.l1_block_info.operator_fee_constant.pretty(),
279            self.l1_block_info
280                .da_footprint_gas_scalar
281                .map(|value| value.to_string())
282                .unwrap_or_default(),
283            deposit_nonce.pretty(),
284            deposit_receipt_version.pretty(),
285            self.payer.pretty(),
286            self.phase_statuses.pretty(),
287            self.metadata.pretty(),
288        )
289    }
290}
291
292impl UIfmt for AnyTransactionReceipt {
293    fn pretty(&self) -> String {
294        let mut pretty = pretty_receipt(&self.inner, self.inner.inner.r#type);
295        pretty.push_str(&self.other.pretty());
296        pretty
297    }
298}
299
300impl UIfmt for Log {
301    fn pretty(&self) -> String {
302        format!(
303            "
304address: {}
305blockHash: {}
306blockNumber: {}
307data: {}
308logIndex: {}
309removed: {}
310topics: {}
311transactionHash: {}
312transactionIndex: {}",
313            self.address().pretty(),
314            self.block_hash.pretty(),
315            self.block_number.pretty(),
316            self.data().data.pretty(),
317            self.log_index.pretty(),
318            self.removed.pretty(),
319            self.topics().pretty(),
320            self.transaction_hash.pretty(),
321            self.transaction_index.pretty(),
322        )
323    }
324}
325
326impl<T: UIfmt, H: HeaderResponse + UIfmtHeaderExt> UIfmt for Block<T, H> {
327    fn pretty(&self) -> String {
328        format!(
329            "
330{}
331transactions:        {}",
332            pretty_generic_header_response(&self.header),
333            self.transactions.pretty()
334        )
335    }
336}
337
338impl<T: UIfmt> UIfmt for BlockTransactions<T> {
339    fn pretty(&self) -> String {
340        match self {
341            Self::Hashes(hashes) => hashes.pretty(),
342            Self::Full(transactions) => transactions.pretty(),
343            Self::Uncle => String::new(),
344        }
345    }
346}
347
348impl UIfmt for OtherFields {
349    fn pretty(&self) -> String {
350        let mut s = String::with_capacity(self.len() * 30);
351        if !self.is_empty() {
352            s.push('\n');
353        }
354        for (key, value) in self {
355            let val = EthValue::from(value.clone()).pretty();
356            let offset = NAME_COLUMN_LEN.saturating_sub(key.len());
357            s.push_str(key);
358            s.extend(std::iter::repeat_n(' ', offset + 1));
359            s.push_str(&val);
360            s.push('\n');
361        }
362        s
363    }
364}
365
366impl UIfmt for AccessListItem {
367    fn pretty(&self) -> String {
368        let mut s = String::with_capacity(42 + self.storage_keys.len() * 66);
369        s.push_str(self.address.pretty().as_str());
370        s.push_str(" => ");
371        s.push_str(self.storage_keys.pretty().as_str());
372        s
373    }
374}
375
376impl UIfmt for TxLegacy {
377    fn pretty(&self) -> String {
378        format!(
379            "
380chainId              {}
381nonce                {}
382gasPrice             {}
383gasLimit             {}
384to                   {}
385value                {}
386input                {}",
387            self.chain_id.pretty(),
388            self.nonce.pretty(),
389            self.gas_price.pretty(),
390            self.gas_limit.pretty(),
391            self.to().pretty(),
392            self.value.pretty(),
393            self.input.pretty(),
394        )
395    }
396}
397
398impl UIfmt for TxEip2930 {
399    fn pretty(&self) -> String {
400        format!(
401            "
402chainId              {}
403nonce                {}
404gasPrice             {}
405gasLimit             {}
406to                   {}
407value                {}
408accessList           {}
409input                {}",
410            self.chain_id.pretty(),
411            self.nonce.pretty(),
412            self.gas_price.pretty(),
413            self.gas_limit.pretty(),
414            self.to().pretty(),
415            self.value.pretty(),
416            self.access_list.pretty(),
417            self.input.pretty(),
418        )
419    }
420}
421
422impl UIfmt for TxEip1559 {
423    fn pretty(&self) -> String {
424        format!(
425            "
426chainId              {}
427nonce                {}
428gasLimit             {}
429maxFeePerGas         {}
430maxPriorityFeePerGas {}
431to                   {}
432value                {}
433accessList           {}
434input                {}",
435            self.chain_id.pretty(),
436            self.nonce.pretty(),
437            self.gas_limit.pretty(),
438            self.max_fee_per_gas.pretty(),
439            self.max_priority_fee_per_gas.pretty(),
440            self.to().pretty(),
441            self.value.pretty(),
442            self.access_list.pretty(),
443            self.input.pretty(),
444        )
445    }
446}
447
448impl UIfmt for TxEip4844Variant {
449    fn pretty(&self) -> String {
450        let tx: &TxEip4844 = match self {
451            Self::TxEip4844(tx) => tx,
452            Self::TxEip4844WithSidecar(tx) => tx.tx(),
453        };
454        format!(
455            "
456chainId              {}
457nonce                {}
458gasLimit             {}
459maxFeePerGas         {}
460maxPriorityFeePerGas {}
461to                   {}
462value                {}
463accessList           {}
464blobVersionedHashes  {}
465maxFeePerBlobGas     {}
466input                {}",
467            tx.chain_id.pretty(),
468            tx.nonce.pretty(),
469            tx.gas_limit.pretty(),
470            tx.max_fee_per_gas.pretty(),
471            tx.max_priority_fee_per_gas.pretty(),
472            tx.to.pretty(),
473            tx.value.pretty(),
474            tx.access_list.pretty(),
475            tx.blob_versioned_hashes.pretty(),
476            tx.max_fee_per_blob_gas.pretty(),
477            tx.input.pretty(),
478        )
479    }
480}
481
482impl UIfmt for TxEip7702 {
483    fn pretty(&self) -> String {
484        format!(
485            "
486chainId              {}
487nonce                {}
488gasLimit             {}
489maxFeePerGas         {}
490maxPriorityFeePerGas {}
491to                   {}
492value                {}
493accessList           {}
494authorizationList    {}
495input                {}",
496            self.chain_id.pretty(),
497            self.nonce.pretty(),
498            self.gas_limit.pretty(),
499            self.max_fee_per_gas.pretty(),
500            self.max_priority_fee_per_gas.pretty(),
501            self.to.pretty(),
502            self.value.pretty(),
503            self.access_list.pretty(),
504            self.authorization_list.pretty(),
505            self.input.pretty(),
506        )
507    }
508}
509
510#[cfg(feature = "optimism")]
511impl UIfmt for TxDeposit {
512    fn pretty(&self) -> String {
513        format!(
514            "
515sourceHash           {}
516from                 {}
517to                   {}
518mint                 {}
519value                {}
520gasLimit             {}
521isSystemTransaction  {}
522input                {}",
523            self.source_hash.pretty(),
524            self.from.pretty(),
525            self.to().pretty(),
526            self.mint.pretty(),
527            self.value.pretty(),
528            self.gas_limit.pretty(),
529            self.is_system_transaction,
530            self.input.pretty(),
531        )
532    }
533}
534
535#[cfg(feature = "base")]
536impl UIfmt for BaseTxDeposit {
537    fn pretty(&self) -> String {
538        format!(
539            "
540sourceHash           {}
541from                 {}
542to                   {}
543mint                 {}
544value                {}
545gasLimit             {}
546isSystemTransaction  {}
547input                {}",
548            self.source_hash.pretty(),
549            self.from.pretty(),
550            self.to().pretty(),
551            self.mint.pretty(),
552            self.value.pretty(),
553            self.gas_limit.pretty(),
554            self.is_system_transaction,
555            self.input.pretty(),
556        )
557    }
558}
559
560#[cfg(feature = "base")]
561impl UIfmt for Eip8130Signed {
562    fn pretty(&self) -> String {
563        let tx = self.tx();
564        // `calls` is grouped into phases, and `accountChanges` can be long, so both are summarized
565        // by count rather than dumped inline.
566        format!(
567            "
568chainId              {}
569sender               {}
570payer                {}
571nonceKey             {}
572nonceSequence        {}
573validAfter           {}
574validBefore          {}
575maxFeePerGas         {}
576maxPriorityFeePerGas {}
577gasLimit             {}
578accountChanges       {}
579callPhases           {}
580calls                {}
581metadata             {}
582senderAuth           {}
583payerAuth            {}",
584            tx.chain_id.pretty(),
585            tx.sender.pretty(),
586            tx.payer.pretty(),
587            tx.nonce_key.pretty(),
588            tx.nonce_sequence.pretty(),
589            tx.valid_after.pretty(),
590            tx.valid_before.pretty(),
591            tx.max_fee_per_gas.pretty(),
592            tx.max_priority_fee_per_gas.pretty(),
593            tx.gas_limit.pretty(),
594            tx.account_changes.len(),
595            tx.calls.len(),
596            tx.calls.iter().map(Vec::len).sum::<usize>(),
597            tx.metadata.pretty(),
598            self.sender_auth().pretty(),
599            self.payer_auth().pretty(),
600        )
601    }
602}
603
604#[cfg(feature = "optimism")]
605impl UIfmt for TxPostExec {
606    fn pretty(&self) -> String {
607        format!(
608            "
609blockNumber          {}
610gasRefundEntries     {:?}
611input                {}",
612            self.payload.block_number.pretty(),
613            self.payload.gas_refund_entries,
614            self.input.pretty(),
615        )
616    }
617}
618
619impl UIfmt for Call {
620    fn pretty(&self) -> String {
621        format!(
622            "to: {}, value: {}, input: {}",
623            self.to.into_to().pretty(),
624            self.value.pretty(),
625            self.input.pretty(),
626        )
627    }
628}
629
630impl UIfmt for TempoTransaction {
631    fn pretty(&self) -> String {
632        format!(
633            "
634chainId              {}
635feeToken             {}
636maxPriorityFeePerGas {}
637maxFeePerGas         {}
638gasLimit             {}
639calls                {}
640accessList           {}
641nonceKey             {}
642nonce                {}
643feePayerSignature    {}
644validBefore          {}
645validAfter           {}",
646            self.chain_id.pretty(),
647            self.fee_token.pretty(),
648            self.max_priority_fee_per_gas.pretty(),
649            self.max_fee_per_gas.pretty(),
650            self.gas_limit.pretty(),
651            self.calls.pretty(),
652            self.access_list.pretty(),
653            self.nonce_key.pretty(),
654            self.nonce.pretty(),
655            self.fee_payer_signature.pretty(),
656            self.valid_before.pretty(),
657            self.valid_after.pretty(),
658        )
659    }
660}
661
662impl UIfmt for TempoSignature {
663    fn pretty(&self) -> String {
664        serde_json::to_string(self).unwrap_or_default()
665    }
666}
667
668impl UIfmt for AASigned {
669    fn pretty(&self) -> String {
670        format!(
671            "
672hash                 {}
673type                 {}
674{}
675tempoSignature       {}",
676            self.hash().pretty(),
677            self.tx().ty(),
678            self.tx().pretty().trim_start(),
679            self.signature().pretty(),
680        )
681    }
682}
683
684impl<T: UIfmt + Typed2718> UIfmt for Signed<T>
685where
686    Self: TxHashRef,
687{
688    fn pretty(&self) -> String {
689        format!(
690            "
691hash                 {}
692type                 {}
693{}
694r                    {}
695s                    {}
696yParity              {}",
697            self.tx_hash().pretty(),
698            self.ty(),
699            self.tx().pretty().trim_start(),
700            FixedBytes::from(self.signature().r()).pretty(),
701            FixedBytes::from(self.signature().s()).pretty(),
702            (if self.signature().v() { 1u64 } else { 0 }).pretty(),
703        )
704    }
705}
706
707impl UIfmt for TxEnvelope {
708    fn pretty(&self) -> String {
709        match self {
710            Self::Legacy(tx) => tx.pretty(),
711            Self::Eip2930(tx) => tx.pretty(),
712            Self::Eip1559(tx) => tx.pretty(),
713            Self::Eip4844(tx) => tx.pretty(),
714            Self::Eip7702(tx) => tx.pretty(),
715        }
716    }
717}
718
719#[cfg(feature = "base")]
720impl UIfmt for BaseTxEnvelope {
721    fn pretty(&self) -> String {
722        match self {
723            Self::Legacy(tx) => tx.pretty(),
724            Self::Eip2930(tx) => tx.pretty(),
725            Self::Eip1559(tx) => tx.pretty(),
726            Self::Eip7702(tx) => tx.pretty(),
727            Self::Deposit(tx) => tx.inner().pretty(),
728            Self::Eip8130(tx) => tx.pretty(),
729        }
730    }
731}
732
733impl UIfmt for AnyTxEnvelope {
734    fn pretty(&self) -> String {
735        match self {
736            Self::Ethereum(envelop) => envelop.pretty(),
737            Self::Unknown(tx) => {
738                format!(
739                    "
740hash                 {}
741type               {:#x}
742{}
743                    ",
744                    tx.hash.pretty(),
745                    tx.ty(),
746                    tx.inner.fields.pretty().trim_start(),
747                )
748            }
749        }
750    }
751}
752
753#[cfg(feature = "optimism")]
754impl UIfmt for OpTxEnvelope {
755    fn pretty(&self) -> String {
756        match self {
757            Self::Legacy(tx) => tx.pretty(),
758            Self::Eip2930(tx) => tx.pretty(),
759            Self::Eip1559(tx) => tx.pretty(),
760            Self::Eip7702(tx) => tx.pretty(),
761            Self::Deposit(tx) => tx.pretty(),
762            Self::PostExec(tx) => tx.pretty(),
763        }
764    }
765}
766
767impl UIfmt for TempoTxEnvelope {
768    fn pretty(&self) -> String {
769        match self {
770            Self::Legacy(tx) => tx.pretty(),
771            Self::Eip2930(tx) => tx.pretty(),
772            Self::Eip1559(tx) => tx.pretty(),
773            Self::Eip7702(tx) => tx.pretty(),
774            Self::AA(tx) => tx.pretty(),
775        }
776    }
777}
778
779impl<T: UIfmt> UIfmt for Transaction<T> {
780    fn pretty(&self) -> String {
781        format!(
782            "
783blockHash            {}
784blockNumber          {}
785from                 {}
786transactionIndex     {}
787effectiveGasPrice    {}
788{}",
789            self.block_hash.pretty(),
790            self.block_number.pretty(),
791            self.inner.signer().pretty(),
792            self.transaction_index.pretty(),
793            self.effective_gas_price.pretty(),
794            self.inner.inner().pretty().trim_start(),
795        )
796    }
797}
798
799#[cfg(feature = "base")]
800impl UIfmt for BaseRpcTransaction {
801    fn pretty(&self) -> String {
802        format!(
803            "
804depositNonce         {}
805depositReceiptVersion {}
806{}",
807            self.deposit_nonce.pretty(),
808            self.deposit_receipt_version.pretty(),
809            self.inner.pretty().trim_start(),
810        )
811    }
812}
813
814#[cfg(feature = "optimism")]
815impl<T: UIfmt> UIfmt for op_alloy_rpc_types::Transaction<T> {
816    fn pretty(&self) -> String {
817        format!(
818            "
819depositNonce         {}
820depositReceiptVersion {}
821{}",
822            self.deposit_nonce.pretty(),
823            self.deposit_receipt_version.pretty(),
824            self.inner.pretty().trim_start(),
825        )
826    }
827}
828
829impl UIfmt for AnyRpcBlock {
830    fn pretty(&self) -> String {
831        self.0.pretty()
832    }
833}
834
835impl UIfmt for AnyRpcTransaction {
836    fn pretty(&self) -> String {
837        self.0.pretty()
838    }
839}
840
841impl<T: UIfmt> UIfmt for WithOtherFields<T> {
842    fn pretty(&self) -> String {
843        format!("{}{}", self.inner.pretty(), self.other.pretty())
844    }
845}
846
847/// Various numerical ethereum types used for pretty printing
848#[derive(Clone, Debug, Deserialize)]
849#[serde(untagged)]
850#[expect(missing_docs)]
851pub enum EthValue {
852    U64(U64),
853    Address(Address),
854    U256(U256),
855    U64Array(Vec<U64>),
856    U256Array(Vec<U256>),
857    Other(serde_json::Value),
858}
859
860impl From<serde_json::Value> for EthValue {
861    fn from(val: serde_json::Value) -> Self {
862        serde_json::from_value(val).expect("infallible")
863    }
864}
865
866impl UIfmt for EthValue {
867    fn pretty(&self) -> String {
868        match self {
869            Self::U64(num) => num.pretty(),
870            Self::U256(num) => num.pretty(),
871            Self::Address(addr) => addr.pretty(),
872            Self::U64Array(arr) => arr.pretty(),
873            Self::U256Array(arr) => arr.pretty(),
874            Self::Other(val) => val.to_string().trim_matches('"').to_string(),
875        }
876    }
877}
878
879impl UIfmt for SignedAuthorization {
880    fn pretty(&self) -> String {
881        let signed_authorization = serde_json::to_string(self).unwrap_or("<invalid>".to_string());
882
883        match self.recover_authority() {
884            Ok(authority) => format!(
885                "{{recoveredAuthority: {authority}, signedAuthority: {signed_authorization}}}",
886            ),
887            Err(e) => format!(
888                "{{recoveredAuthority: <error: {e}>, signedAuthority: {signed_authorization}}}",
889            ),
890        }
891    }
892}
893
894pub trait UIfmtHeaderExt {
895    fn size_pretty(&self) -> String;
896    fn total_difficulty_pretty(&self) -> String;
897}
898
899impl UIfmtHeaderExt for Header {
900    fn size_pretty(&self) -> String {
901        self.size.pretty()
902    }
903
904    fn total_difficulty_pretty(&self) -> String {
905        self.total_difficulty.unwrap_or_else(|| self.difficulty()).pretty()
906    }
907}
908
909impl UIfmtHeaderExt for AnyRpcHeader {
910    fn size_pretty(&self) -> String {
911        self.size.pretty()
912    }
913
914    fn total_difficulty_pretty(&self) -> String {
915        self.total_difficulty.unwrap_or_else(|| self.difficulty()).pretty()
916    }
917}
918
919impl UIfmtHeaderExt for TempoHeaderResponse {
920    fn size_pretty(&self) -> String {
921        self.inner.size.pretty()
922    }
923
924    fn total_difficulty_pretty(&self) -> String {
925        self.inner.total_difficulty.unwrap_or_else(|| self.inner.difficulty()).pretty()
926    }
927}
928
929pub trait UIfmtSignatureExt {
930    fn signature_pretty(&self) -> Option<(String, String, String)>;
931}
932
933impl UIfmtSignatureExt for TxEnvelope {
934    fn signature_pretty(&self) -> Option<(String, String, String)> {
935        Some(pretty_signature_fields(self.signature()))
936    }
937}
938
939impl UIfmtSignatureExt for AnyTxEnvelope {
940    fn signature_pretty(&self) -> Option<(String, String, String)> {
941        self.as_envelope().and_then(|envelope| envelope.signature_pretty())
942    }
943}
944
945#[cfg(feature = "base")]
946impl UIfmtSignatureExt for BaseTxEnvelope {
947    fn signature_pretty(&self) -> Option<(String, String, String)> {
948        self.signature().map(pretty_signature_fields)
949    }
950}
951
952#[cfg(feature = "optimism")]
953impl UIfmtSignatureExt for OpTxEnvelope {
954    fn signature_pretty(&self) -> Option<(String, String, String)> {
955        self.signature().map(pretty_signature_fields)
956    }
957}
958
959impl UIfmtSignatureExt for TempoTxEnvelope {
960    fn signature_pretty(&self) -> Option<(String, String, String)> {
961        let sig = match self {
962            Self::Legacy(tx) => Some(tx.signature()),
963            Self::Eip2930(tx) => Some(tx.signature()),
964            Self::Eip1559(tx) => Some(tx.signature()),
965            Self::Eip7702(tx) => Some(tx.signature()),
966            Self::AA(tempo_tx) => {
967                if let TempoSignature::Primitive(PrimitiveSignature::Secp256k1(sig)) =
968                    tempo_tx.signature()
969                {
970                    Some(sig)
971                } else {
972                    None
973                }
974            }
975        }?;
976        Some(pretty_signature_fields(sig))
977    }
978}
979
980fn pretty_signature_fields(signature: &Signature) -> (String, String, String) {
981    (
982        FixedBytes::from(signature.r()).pretty(),
983        FixedBytes::from(signature.s()).pretty(),
984        U8::from_le_slice(&signature.as_bytes()[64..]).pretty(),
985    )
986}
987
988pub trait UIfmtReceiptExt {
989    fn logs_pretty(&self) -> String;
990    fn logs_bloom_pretty(&self) -> String;
991    fn tx_type_pretty(&self) -> String;
992}
993
994fn receipt_logs_pretty<T: TxReceipt>(receipt: &TransactionReceipt<T>) -> String
995where
996    T::Log: Serialize,
997{
998    serde_json::to_string(receipt.inner.logs()).unwrap_or_default()
999}
1000
1001fn receipt_logs_bloom_pretty<T: TxReceipt>(receipt: &TransactionReceipt<T>) -> String {
1002    receipt.inner.bloom().pretty()
1003}
1004
1005impl UIfmtReceiptExt for TransactionReceipt {
1006    fn logs_pretty(&self) -> String {
1007        receipt_logs_pretty(self)
1008    }
1009
1010    fn logs_bloom_pretty(&self) -> String {
1011        receipt_logs_bloom_pretty(self)
1012    }
1013
1014    fn tx_type_pretty(&self) -> String {
1015        self.transaction_type().to_string()
1016    }
1017}
1018
1019#[cfg(feature = "base")]
1020impl UIfmtReceiptExt for BaseTransactionReceipt {
1021    fn logs_pretty(&self) -> String {
1022        receipt_logs_pretty(&self.inner)
1023    }
1024
1025    fn logs_bloom_pretty(&self) -> String {
1026        receipt_logs_bloom_pretty(&self.inner)
1027    }
1028
1029    fn tx_type_pretty(&self) -> String {
1030        self.inner.inner.receipt.tx_type().to_string()
1031    }
1032}
1033
1034impl UIfmtReceiptExt for AnyTransactionReceipt {
1035    fn logs_pretty(&self) -> String {
1036        receipt_logs_pretty(&self.inner)
1037    }
1038
1039    fn logs_bloom_pretty(&self) -> String {
1040        receipt_logs_bloom_pretty(&self.inner)
1041    }
1042
1043    fn tx_type_pretty(&self) -> String {
1044        self.inner.inner.r#type.to_string()
1045    }
1046}
1047
1048impl UIfmt for TempoTransactionReceipt {
1049    fn pretty(&self) -> String {
1050        let receipt = &self.inner;
1051
1052        let mut pretty = format!(
1053            "
1054blockHash            {}
1055blockNumber          {}
1056contractAddress      {}
1057cumulativeGasUsed    {}
1058effectiveGasPrice    {}
1059from                 {}
1060gasUsed              {}
1061logs                 {}
1062logsBloom            {}
1063root                 {}
1064status               {}
1065transactionHash      {}
1066transactionIndex     {}
1067type                 {}
1068feePayer             {}
1069feeToken             {}",
1070            receipt.block_hash().pretty(),
1071            receipt.block_number().pretty(),
1072            receipt.contract_address().pretty(),
1073            receipt.cumulative_gas_used().pretty(),
1074            receipt.effective_gas_price().pretty(),
1075            receipt.from().pretty(),
1076            receipt.gas_used().pretty(),
1077            serde_json::to_string(receipt.inner.logs()).unwrap(),
1078            receipt.inner.logs_bloom.pretty(),
1079            self.state_root().pretty(),
1080            receipt.status().pretty(),
1081            receipt.transaction_hash().pretty(),
1082            receipt.transaction_index().pretty(),
1083            receipt.inner.receipt.tx_type as u8,
1084            self.fee_payer.pretty(),
1085            self.fee_token.pretty(),
1086        );
1087
1088        if let Some(to) = receipt.to() {
1089            pretty.push_str(&format!("\nto                   {}", to.pretty()));
1090        }
1091
1092        pretty
1093    }
1094}
1095
1096impl UIfmtReceiptExt for TempoTransactionReceipt {
1097    fn logs_pretty(&self) -> String {
1098        receipt_logs_pretty(&self.inner)
1099    }
1100
1101    fn logs_bloom_pretty(&self) -> String {
1102        self.inner.inner.logs_bloom.pretty()
1103    }
1104
1105    fn tx_type_pretty(&self) -> String {
1106        (self.inner.inner.receipt.tx_type as u8).to_string()
1107    }
1108}
1109
1110/// Returns the `UiFmt::pretty()` formatted attribute of the transactions
1111pub fn get_pretty_tx_attr<N>(transaction: &N::TransactionResponse, attr: &str) -> Option<String>
1112where
1113    N: Network,
1114    N::TxEnvelope: UIfmtSignatureExt,
1115{
1116    let (r, s, v) = transaction.as_ref().signature_pretty().unwrap_or_default();
1117    match attr {
1118        "blockHash" | "block_hash" => {
1119            Some(alloy_network::TransactionResponse::block_hash(transaction).pretty())
1120        }
1121        "blockNumber" | "block_number" => {
1122            Some(alloy_network::TransactionResponse::block_number(transaction).pretty())
1123        }
1124        "from" => Some(alloy_network::TransactionResponse::from(transaction).pretty()),
1125        "gas" => Some(TxTrait::gas_limit(transaction).pretty()),
1126        "gasPrice" | "gas_price" => Some(TxTrait::max_fee_per_gas(transaction).pretty()),
1127        "hash" => Some(alloy_network::TransactionResponse::tx_hash(transaction).pretty()),
1128        "input" => Some(TxTrait::input(transaction).pretty()),
1129        "nonce" => Some(TxTrait::nonce(transaction).to_string()),
1130        "s" => Some(s),
1131        "r" => Some(r),
1132        "to" => Some(TxTrait::to(transaction).pretty()),
1133        "transactionIndex" | "transaction_index" => {
1134            Some(alloy_network::TransactionResponse::transaction_index(transaction).pretty())
1135        }
1136        "v" => Some(v),
1137        "value" => Some(TxTrait::value(transaction).pretty()),
1138        _ => None,
1139    }
1140}
1141
1142pub fn get_pretty_block_attr<N>(block: &N::BlockResponse, attr: &str) -> Option<String>
1143where
1144    N: Network,
1145    N::BlockResponse: BlockResponse<Header = N::HeaderResponse>,
1146    N::HeaderResponse: UIfmtHeaderExt,
1147{
1148    match attr {
1149        "baseFeePerGas" | "base_fee_per_gas" => Some(block.header().base_fee_per_gas().pretty()),
1150        "difficulty" => Some(block.header().difficulty().pretty()),
1151        "extraData" | "extra_data" => Some(block.header().extra_data().pretty()),
1152        "gasLimit" | "gas_limit" => Some(block.header().gas_limit().pretty()),
1153        "gasUsed" | "gas_used" => Some(block.header().gas_used().pretty()),
1154        "hash" => Some(block.header().hash().pretty()),
1155        "logsBloom" | "logs_bloom" => Some(block.header().logs_bloom().pretty()),
1156        "miner" | "author" => Some(block.header().beneficiary().pretty()),
1157        "mixHash" | "mix_hash" => Some(block.header().mix_hash().pretty()),
1158        "nonce" => Some(block.header().nonce().pretty()),
1159        "number" => Some(block.header().number().pretty()),
1160        "parentHash" | "parent_hash" => Some(block.header().parent_hash().pretty()),
1161        "transactionsRoot" | "transactions_root" => {
1162            Some(block.header().transactions_root().pretty())
1163        }
1164        "receiptsRoot" | "receipts_root" => Some(block.header().receipts_root().pretty()),
1165        "sha3Uncles" | "sha_3_uncles" => Some(block.header().ommers_hash().pretty()),
1166        "size" => Some(block.header().size_pretty()),
1167        "stateRoot" | "state_root" => Some(block.header().state_root().pretty()),
1168        "timestamp" => Some(block.header().timestamp().pretty()),
1169        "totalDifficulty" | "total_difficulty" => Some(block.header().total_difficulty_pretty()),
1170        "blobGasUsed" | "blob_gas_used" => Some(block.header().blob_gas_used().pretty()),
1171        "excessBlobGas" | "excess_blob_gas" => Some(block.header().excess_blob_gas().pretty()),
1172        "requestsHash" | "requests_hash" => Some(block.header().requests_hash().pretty()),
1173        other => {
1174            if let Some(value) = block.other_fields().and_then(|fields| fields.get(other)) {
1175                let val = EthValue::from(value.clone());
1176                return Some(val.pretty());
1177            }
1178            None
1179        }
1180    }
1181}
1182
1183pub fn get_pretty_receipt_attr<N>(receipt: &N::ReceiptResponse, attr: &str) -> Option<String>
1184where
1185    N: Network,
1186    N::ReceiptResponse: ReceiptResponse + UIfmtReceiptExt,
1187{
1188    match attr {
1189        "blockHash" | "block_hash" => Some(receipt.block_hash().pretty()),
1190        "blockNumber" | "block_number" => Some(receipt.block_number().pretty()),
1191        "contractAddress" | "contract_address" => Some(receipt.contract_address().pretty()),
1192        "cumulativeGasUsed" | "cumulative_gas_used" => Some(receipt.cumulative_gas_used().pretty()),
1193        "effectiveGasPrice" | "effective_gas_price" => Some(receipt.effective_gas_price().pretty()),
1194        "from" => Some(receipt.from().pretty()),
1195        "gasUsed" | "gas_used" => Some(receipt.gas_used().pretty()),
1196        "logs" => Some(receipt.logs_pretty()),
1197        "logsBloom" | "logs_bloom" => Some(receipt.logs_bloom_pretty()),
1198        "root" | "stateRoot" | "state_root" => Some(receipt.state_root().pretty()),
1199        "status" | "statusCode" | "status_code" => Some(receipt.status().pretty()),
1200        "transactionHash" | "transaction_hash" => Some(receipt.transaction_hash().pretty()),
1201        "transactionIndex" | "transaction_index" => Some(receipt.transaction_index().pretty()),
1202        "to" => Some(receipt.to().pretty()),
1203        "type" | "transaction_type" => Some(receipt.tx_type_pretty()),
1204        "blobGasPrice" | "blob_gas_price" => Some(receipt.blob_gas_price().pretty()),
1205        "blobGasUsed" | "blob_gas_used" => Some(receipt.blob_gas_used().pretty()),
1206        _ => None,
1207    }
1208}
1209
1210fn pretty_generic_header_response<H: HeaderResponse + UIfmtHeaderExt>(header: &H) -> String {
1211    format!(
1212        "
1213baseFeePerGas        {}
1214difficulty           {}
1215extraData            {}
1216gasLimit             {}
1217gasUsed              {}
1218hash                 {}
1219logsBloom            {}
1220miner                {}
1221mixHash              {}
1222nonce                {}
1223number               {}
1224parentHash           {}
1225parentBeaconRoot     {}
1226transactionsRoot     {}
1227receiptsRoot         {}
1228sha3Uncles           {}
1229size                 {}
1230stateRoot            {}
1231timestamp            {} ({})
1232withdrawalsRoot      {}
1233totalDifficulty      {}
1234blobGasUsed          {}
1235excessBlobGas        {}
1236requestsHash         {}",
1237        header.base_fee_per_gas().pretty(),
1238        header.difficulty().pretty(),
1239        header.extra_data().pretty(),
1240        header.gas_limit().pretty(),
1241        header.gas_used().pretty(),
1242        header.hash().pretty(),
1243        header.logs_bloom().pretty(),
1244        header.beneficiary().pretty(),
1245        header.mix_hash().pretty(),
1246        header.nonce().pretty(),
1247        header.number().pretty(),
1248        header.parent_hash().pretty(),
1249        header.parent_beacon_block_root().pretty(),
1250        header.transactions_root().pretty(),
1251        header.receipts_root().pretty(),
1252        header.ommers_hash().pretty(),
1253        header.size_pretty(),
1254        header.state_root().pretty(),
1255        header.timestamp().pretty(),
1256        fmt_timestamp(header.timestamp()),
1257        header.withdrawals_root().pretty(),
1258        header.total_difficulty_pretty(),
1259        header.blob_gas_used().pretty(),
1260        header.excess_blob_gas().pretty(),
1261        header.requests_hash().pretty(),
1262    )
1263}
1264
1265/// Formats the timestamp to string
1266///
1267/// Assumes timestamp is seconds, but handles millis if it is too large
1268fn fmt_timestamp(timestamp: u64) -> String {
1269    // Tue Jan 19 2038 03:14:07 GMT+0000
1270    if timestamp > 2147483647 {
1271        // assume this is in millis, incorrectly set to millis by a node
1272        chrono::DateTime::from_timestamp_millis(timestamp as i64)
1273            .expect("block timestamp in range")
1274            .to_rfc3339()
1275    } else {
1276        // assume this is still in seconds
1277        chrono::DateTime::from_timestamp(timestamp as i64, 0)
1278            .expect("block timestamp in range")
1279            .to_rfc2822()
1280    }
1281}
1282
1283#[cfg(test)]
1284mod tests {
1285
1286    use super::*;
1287    use alloy_network::Ethereum;
1288    use alloy_primitives::{B256, address, bytes};
1289    use alloy_rpc_types::Authorization;
1290    use similar_asserts::assert_eq;
1291
1292    #[cfg(feature = "base")]
1293    use base_common_consensus::{Call as BaseCall, TxEip8130};
1294
1295    #[test]
1296    fn format_date_time() {
1297        // Fri Aug 29 2025 08:05:38 GMT+0000
1298        let timestamp = 1756454738u64;
1299
1300        let datetime = fmt_timestamp(timestamp);
1301        assert_eq!(datetime, "Fri, 29 Aug 2025 08:05:38 +0000");
1302        let datetime = fmt_timestamp(timestamp * 1000);
1303        assert_eq!(datetime, "2025-08-29T08:05:38+00:00");
1304    }
1305
1306    #[test]
1307    fn can_format_bytes32() {
1308        let val = hex::decode("7465737400000000000000000000000000000000000000000000000000000000")
1309            .unwrap();
1310        let mut b32 = [0u8; 32];
1311        b32.copy_from_slice(&val);
1312
1313        assert_eq!(
1314            b32.pretty(),
1315            "0x7465737400000000000000000000000000000000000000000000000000000000"
1316        );
1317        let b: Bytes = val.into();
1318        assert_eq!(b.pretty(), b32.pretty());
1319    }
1320
1321    #[cfg(feature = "base")]
1322    #[test]
1323    fn can_pretty_print_eip8130_transaction() {
1324        let base_call = BaseCall { to: Address::ZERO, data: Bytes::new() };
1325        let tx = TxEip8130 {
1326            chain_id: 8453,
1327            sender: Some(Address::with_last_byte(0x11)),
1328            payer: Some(Address::with_last_byte(0x22)),
1329            nonce_key: U256::from(7),
1330            nonce_sequence: 3,
1331            valid_after: 100,
1332            valid_before: 200,
1333            max_fee_per_gas: 1_000,
1334            max_priority_fee_per_gas: 10,
1335            gas_limit: 21_000,
1336            metadata: Bytes::from_static(&[0xab]),
1337            calls: vec![vec![base_call.clone(), base_call.clone()], vec![base_call]],
1338            ..Default::default()
1339        };
1340        let signed =
1341            Eip8130Signed::new(tx, Bytes::from_static(&[0x01]), Bytes::from_static(&[0x02]));
1342
1343        assert_eq!(
1344            signed.pretty().trim(),
1345            r"chainId              8453
1346sender               0x0000000000000000000000000000000000000011
1347payer                0x0000000000000000000000000000000000000022
1348nonceKey             7
1349nonceSequence        3
1350validAfter           100
1351validBefore          200
1352maxFeePerGas         1000
1353maxPriorityFeePerGas 10
1354gasLimit             21000
1355accountChanges       0
1356callPhases           2
1357calls                3
1358metadata             0xab
1359senderAuth           0x01
1360payerAuth            0x02"
1361        );
1362    }
1363
1364    #[cfg(feature = "base")]
1365    #[test]
1366    fn can_pretty_print_base_deposit_receipt_fields() {
1367        let receipt: BaseTransactionReceipt = serde_json::from_value(serde_json::json!({
1368            "blockHash": "0x9e6a0fb7e22159d943d760608cc36a0fb596d1ab3c997146f5b7c55c8c718c67",
1369            "blockNumber": "0x6cfef89",
1370            "contractAddress": null,
1371            "cumulativeGasUsed": "0xfa0d",
1372            "depositNonce": "0x8a2d11",
1373            "depositReceiptVersion": "0x1",
1374            "effectiveGasPrice": "0x0",
1375            "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001",
1376            "gasUsed": "0xfa0d",
1377            "logs": [{
1378                "address": "0x4200000000000000000000000000000000000015",
1379                "topics": [],
1380                "data": "0x",
1381                "removed": false,
1382                "blockTimestampMs": "0x18bcfe568c8",
1383                "blockNumber": "0x6cfef89",
1384                "blockHash": null,
1385                "transactionHash": null,
1386                "transactionIndex": null,
1387                "logIndex": null
1388            }],
1389            "logsBloom": format!("0x{}", "00".repeat(256)),
1390            "status": "0x1",
1391            "to": "0x4200000000000000000000000000000000000015",
1392            "transactionHash": "0xb7c74afdeb7c89fb9de2c312f49b38cb7a850ba36e064734c5223a477e83fdc9",
1393            "transactionIndex": "0x0",
1394            "type": "0x7e",
1395            "l1GasPrice": "0x3ef12787",
1396            "l1GasUsed": "0x1177",
1397            "l1Fee": "0x5bf1ab43d",
1398            "l1BaseFeeScalar": "0x1",
1399            "l1BlobBaseFee": "0x600ab8f05e64",
1400            "l1BlobBaseFeeScalar": "0x1",
1401            "operatorFeeScalar": "0x1",
1402            "operatorFeeConstant": "0x1",
1403            "daFootprintGasScalar": "0x1"
1404        }))
1405        .unwrap();
1406
1407        let pretty = receipt.pretty();
1408        let logs = receipt.logs_pretty();
1409        assert_eq!(
1410            serde_json::from_str::<serde_json::Value>(&logs).unwrap()[0]["blockTimestampMs"],
1411            "0x18bcfe568c8"
1412        );
1413        assert!(pretty.contains(&format!("logs                 {logs}")), "{pretty}");
1414        assert_eq!(receipt.logs_bloom_pretty(), receipt_logs_bloom_pretty(&receipt.inner));
1415        assert!(pretty.contains("l1Fee                24681034813"), "{pretty}");
1416        assert!(pretty.contains("operatorFeeScalar    1"), "{pretty}");
1417        assert!(pretty.contains("depositNonce         9055505"), "{pretty}");
1418        assert!(pretty.contains("depositReceiptVersion 1"), "{pretty}");
1419    }
1420
1421    #[cfg(feature = "optimism")]
1422    #[test]
1423    fn can_pretty_print_optimism_tx() {
1424        let s = r#"
1425        {
1426        "blockHash": "0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae",
1427        "blockNumber": "0x1b4",
1428        "from": "0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6",
1429        "gas": "0x11cbbdc",
1430        "gasPrice": "0x0",
1431        "hash": "0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f",
1432        "input": "0xd294f093",
1433        "nonce": "0xa2",
1434        "to": "0x4a16A42407AA491564643E1dfc1fd50af29794eF",
1435        "transactionIndex": "0x0",
1436        "value": "0x0",
1437        "v": "0x38",
1438        "r": "0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee",
1439        "s": "0xe804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583",
1440        "depositNonce": "",
1441        "depositReceiptVersion": "0x1"
1442    }
1443        "#;
1444
1445        let tx: op_alloy_rpc_types::Transaction<OpTxEnvelope> = serde_json::from_str(s).unwrap();
1446        assert_eq!(
1447            tx.pretty().trim(),
1448            r"
1449depositNonce         
1450depositReceiptVersion 1
1451blockHash            0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae
1452blockNumber          436
1453from                 0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6
1454transactionIndex     0
1455effectiveGasPrice    0
1456hash                 0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f
1457type                 0
1458chainId              10
1459nonce                162
1460gasPrice             0
1461gasLimit             18660316
1462to                   0x4a16A42407AA491564643E1dfc1fd50af29794eF
1463value                0
1464input                0xd294f093
1465r                    0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee
1466s                    0x0e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1467yParity              1
1468"
1469            .trim()
1470        );
1471    }
1472
1473    #[cfg(feature = "optimism")]
1474    #[test]
1475    fn can_pretty_print_optimism_tx_through_any() {
1476        let s = r#"
1477        {
1478        "blockHash": "0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae",
1479        "blockNumber": "0x1b4",
1480        "from": "0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6",
1481        "gas": "0x11cbbdc",
1482        "gasPrice": "0x0",
1483        "hash": "0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f",
1484        "input": "0xd294f093",
1485        "nonce": "0xa2",
1486        "to": "0x4a16A42407AA491564643E1dfc1fd50af29794eF",
1487        "transactionIndex": "0x0",
1488        "value": "0x0",
1489        "v": "0x38",
1490        "r": "0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee",
1491        "s": "0xe804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583",
1492        "queueOrigin": "sequencer",
1493        "txType": "",
1494        "l1TxOrigin": null,
1495        "l1BlockNumber": "0xc1a65c",
1496        "l1Timestamp": "0x60d34b60",
1497        "index": "0x1b3",
1498        "queueIndex": null,
1499        "rawTransaction": "0xf86681a28084011cbbdc944a16a42407aa491564643e1dfc1fd50af29794ef8084d294f09338a06fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2beea00e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583"
1500    }
1501        "#;
1502
1503        let tx: WithOtherFields<Transaction<AnyTxEnvelope>> = serde_json::from_str(s).unwrap();
1504        assert_eq!(tx.pretty().trim(),
1505                   r"
1506blockHash            0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae
1507blockNumber          436
1508from                 0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6
1509transactionIndex     0
1510effectiveGasPrice    0
1511hash                 0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f
1512type                 0
1513chainId              10
1514nonce                162
1515gasPrice             0
1516gasLimit             18660316
1517to                   0x4a16A42407AA491564643E1dfc1fd50af29794eF
1518value                0
1519input                0xd294f093
1520r                    0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee
1521s                    0x0e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1522yParity              1
1523index                435
1524l1BlockNumber        12691036
1525l1Timestamp          1624460128
1526l1TxOrigin           null
1527queueIndex           null
1528queueOrigin          sequencer
1529rawTransaction       0xf86681a28084011cbbdc944a16a42407aa491564643e1dfc1fd50af29794ef8084d294f09338a06fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2beea00e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1530txType               0
1531".trim()
1532        );
1533    }
1534
1535    #[test]
1536    fn can_pretty_print_eip2930() {
1537        let s = r#"{
1538        "type": "0x1",
1539        "blockHash": "0x2b27fe2bbc8ce01ac7ae8bf74f793a197cf7edbe82727588811fa9a2c4776f81",
1540        "blockNumber": "0x12b1d",
1541        "from": "0x2b371c0262ceab27face32fbb5270ddc6aa01ba4",
1542        "gas": "0x6bdf",
1543        "gasPrice": "0x3b9aca00",
1544        "hash": "0xbddbb685774d8a3df036ed9fb920b48f876090a57e9e90ee60921e0510ef7090",
1545        "input": "0x9c0e3f7a0000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000002a",
1546        "nonce": "0x1c",
1547        "to": "0x8e730df7c70d33118d9e5f79ab81aed0be6f6635",
1548        "transactionIndex": "0x2",
1549        "value": "0x0",
1550        "v": "0x1",
1551        "r": "0x2a98c51c2782f664d3ce571fef0491b48f5ebbc5845fa513192e6e6b24ecdaa1",
1552        "s": "0x29b8e0c67aa9c11327e16556c591dc84a7aac2f6fc57c7f93901be8ee867aebc",
1553        "chainId": "0x66a",
1554        "accessList": [
1555            { "address": "0x2b371c0262ceab27face32fbb5270ddc6aa01ba4", "storageKeys": ["0x1122334455667788990011223344556677889900112233445566778899001122", "0x0000000000000000000000000000000000000000000000000000000000000000"] },
1556            { "address": "0x8e730df7c70d33118d9e5f79ab81aed0be6f6635", "storageKeys": [] }
1557        ]
1558      }
1559        "#;
1560        let tx: Transaction = serde_json::from_str(s).unwrap();
1561        assert_eq!(tx.pretty().trim(),
1562                   r"
1563blockHash            0x2b27fe2bbc8ce01ac7ae8bf74f793a197cf7edbe82727588811fa9a2c4776f81
1564blockNumber          76573
1565from                 0x2b371c0262CEAb27fAcE32FBB5270dDc6Aa01ba4
1566transactionIndex     2
1567effectiveGasPrice    1000000000
1568hash                 0xbddbb685774d8a3df036ed9fb920b48f876090a57e9e90ee60921e0510ef7090
1569type                 1
1570chainId              1642
1571nonce                28
1572gasPrice             1000000000
1573gasLimit             27615
1574to                   0x8E730Df7C70D33118D9e5F79ab81aEd0bE6F6635
1575value                0
1576accessList           [
1577	0x2b371c0262CEAb27fAcE32FBB5270dDc6Aa01ba4 => [
1578		0x1122334455667788990011223344556677889900112233445566778899001122
1579		0x0000000000000000000000000000000000000000000000000000000000000000
1580	]
1581	0x8E730Df7C70D33118D9e5F79ab81aEd0bE6F6635 => []
1582]
1583input                0x9c0e3f7a0000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000002a
1584r                    0x2a98c51c2782f664d3ce571fef0491b48f5ebbc5845fa513192e6e6b24ecdaa1
1585s                    0x29b8e0c67aa9c11327e16556c591dc84a7aac2f6fc57c7f93901be8ee867aebc
1586yParity              1
1587".trim()
1588        );
1589    }
1590
1591    #[test]
1592    fn can_pretty_print_eip1559() {
1593        let s = r#"{
1594        "type": "0x2",
1595        "blockHash": "0x61abbe5e22738de0462046f5a5d6c4cd6bc1f3a6398e4457d5e293590e721125",
1596        "blockNumber": "0x7647",
1597        "from": "0xbaadf00d42264eeb3fafe6799d0b56cf55df0f00",
1598        "gas": "0x186a0",
1599        "hash": "0xa7231d4da0576fade5d3b9481f4cd52459ec59b9bbdbf4f60d6cd726b2a3a244",
1600        "input": "0x48600055323160015500",
1601        "nonce": "0x12c",
1602        "to": null,
1603        "transactionIndex": "0x41",
1604        "value": "0x0",
1605        "v": "0x1",
1606        "yParity": "0x1",
1607        "r": "0x396864e5f9132327defdb1449504252e1fa6bce73feb8cd6f348a342b198af34",
1608        "s": "0x44dbba72e6d3304104848277143252ee43627c82f02d1ef8e404e1bf97c70158",
1609        "gasPrice": "0x4a817c800",
1610        "maxFeePerGas": "0x4a817c800",
1611        "maxPriorityFeePerGas": "0x4a817c800",
1612        "chainId": "0x66a",
1613        "accessList": [
1614          {
1615            "address": "0xc141a9a7463e6c4716d9fc0c056c054f46bb2993",
1616            "storageKeys": [
1617              "0x0000000000000000000000000000000000000000000000000000000000000000"
1618            ]
1619          }
1620        ]
1621      }
1622"#;
1623        let tx: Transaction = serde_json::from_str(s).unwrap();
1624        assert_eq!(
1625            tx.pretty().trim(),
1626            r"
1627blockHash            0x61abbe5e22738de0462046f5a5d6c4cd6bc1f3a6398e4457d5e293590e721125
1628blockNumber          30279
1629from                 0xBaaDF00d42264eEb3FAFe6799d0b56cf55DF0F00
1630transactionIndex     65
1631effectiveGasPrice    20000000000
1632hash                 0xa7231d4da0576fade5d3b9481f4cd52459ec59b9bbdbf4f60d6cd726b2a3a244
1633type                 2
1634chainId              1642
1635nonce                300
1636gasLimit             100000
1637maxFeePerGas         20000000000
1638maxPriorityFeePerGas 20000000000
1639to                   
1640value                0
1641accessList           [
1642	0xC141a9A7463e6C4716d9FC0C056C054F46Bb2993 => [
1643		0x0000000000000000000000000000000000000000000000000000000000000000
1644	]
1645]
1646input                0x48600055323160015500
1647r                    0x396864e5f9132327defdb1449504252e1fa6bce73feb8cd6f348a342b198af34
1648s                    0x44dbba72e6d3304104848277143252ee43627c82f02d1ef8e404e1bf97c70158
1649yParity              1
1650"
1651            .trim()
1652        );
1653    }
1654
1655    #[test]
1656    fn can_pretty_print_eip4884() {
1657        let s = r#"{
1658        "blockHash": "0xfc2715ff196e23ae613ed6f837abd9035329a720a1f4e8dce3b0694c867ba052",
1659        "blockNumber": "0x2a1cb",
1660        "from": "0xad01b55d7c3448b8899862eb335fbb17075d8de2",
1661        "gas": "0x5208",
1662        "gasPrice": "0x1d1a94a201c",
1663        "maxFeePerGas": "0x1d1a94a201c",
1664        "maxPriorityFeePerGas": "0x1d1a94a201c",
1665        "maxFeePerBlobGas": "0x3e8",
1666        "hash": "0x5ceec39b631763ae0b45a8fb55c373f38b8fab308336ca1dc90ecd2b3cf06d00",
1667        "input": "0x",
1668        "nonce": "0x1b483",
1669        "to": "0x000000000000000000000000000000000000f1c1",
1670        "transactionIndex": "0x0",
1671        "value": "0x0",
1672        "type": "0x3",
1673        "accessList": [],
1674        "chainId": "0x1a1f0ff42",
1675        "blobVersionedHashes": [
1676          "0x01a128c46fc61395706686d6284f83c6c86dfc15769b9363171ea9d8566e6e76"
1677        ],
1678        "v": "0x0",
1679        "r": "0x343c6239323a81ef61293cb4a4d37b6df47fbf68114adb5dd41581151a077da1",
1680        "s": "0x48c21f6872feaf181d37cc4f9bbb356d3f10b352ceb38d1c3b190d749f95a11b",
1681        "yParity": "0x0"
1682      }
1683"#;
1684        let tx: Transaction = serde_json::from_str(s).unwrap();
1685        assert_eq!(
1686            tx.pretty().trim(),
1687            r"
1688blockHash            0xfc2715ff196e23ae613ed6f837abd9035329a720a1f4e8dce3b0694c867ba052
1689blockNumber          172491
1690from                 0xAD01b55d7c3448B8899862eb335FBb17075d8DE2
1691transactionIndex     0
1692effectiveGasPrice    2000000000028
1693hash                 0x5ceec39b631763ae0b45a8fb55c373f38b8fab308336ca1dc90ecd2b3cf06d00
1694type                 3
1695chainId              7011893058
1696nonce                111747
1697gasLimit             21000
1698maxFeePerGas         2000000000028
1699maxPriorityFeePerGas 2000000000028
1700to                   0x000000000000000000000000000000000000f1C1
1701value                0
1702accessList           []
1703blobVersionedHashes  [
1704	0x01a128c46fc61395706686d6284f83c6c86dfc15769b9363171ea9d8566e6e76
1705]
1706maxFeePerBlobGas     1000
1707input                0x
1708r                    0x343c6239323a81ef61293cb4a4d37b6df47fbf68114adb5dd41581151a077da1
1709s                    0x48c21f6872feaf181d37cc4f9bbb356d3f10b352ceb38d1c3b190d749f95a11b
1710yParity              0
1711"
1712            .trim()
1713        );
1714    }
1715
1716    #[test]
1717    fn print_block_w_txs() {
1718        let block = r#"{"number":"0x3","hash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","parentHash":"0x689c70c080ca22bc0e681694fa803c1aba16a69c8b6368fed5311d279eb9de90","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x7270c1c4440180f2bd5215809ee3d545df042b67329499e1ab97eb759d31610d","stateRoot":"0x29f32984517a7d25607da485b23cefabfd443751422ca7e603395e1de9bc8a4b","receiptsRoot":"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2","miner":"0x0000000000000000000000000000000000000000","difficulty":"0x0","totalDifficulty":"0x0","extraData":"0x","size":"0x3e8","gasLimit":"0x6691b7","gasUsed":"0x5208","timestamp":"0x5ecedbb9","transactions":[{"hash":"0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067","nonce":"0x2","blockHash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","blockNumber":"0x3","transactionIndex":"0x0","from":"0xfdcedc3bfca10ecb0890337fbdd1977aba84807a","to":"0xdca8ce283150ab773bcbeb8d38289bdb5661de1e","value":"0x0","gas":"0x15f90","gasPrice":"0x4a817c800","input":"0x","v":"0x25","r":"0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88","s":"0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e"}],"uncles":[]}"#;
1719        let block: Block = serde_json::from_str(block).unwrap();
1720        let output = "
1721blockHash            0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972
1722blockNumber          3
1723from                 0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a
1724transactionIndex     0
1725effectiveGasPrice    20000000000
1726hash                 0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067
1727type                 0
1728chainId              1
1729nonce                2
1730gasPrice             20000000000
1731gasLimit             90000
1732to                   0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e
1733value                0
1734input                0x
1735r                    0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88
1736s                    0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e
1737yParity              0"
1738            .to_string();
1739        let txs = match block.transactions() {
1740            BlockTransactions::Full(txs) => txs,
1741            _ => panic!("not full transactions"),
1742        };
1743        let generated = txs[0].pretty();
1744        assert_eq!(generated.as_str(), output.as_str());
1745    }
1746
1747    #[test]
1748    fn uifmt_option_u64() {
1749        assert_eq!(None::<U64>.pretty(), "");
1750        assert_eq!(U64::from(100).pretty(), "100");
1751        assert_eq!(Some(U64::from(100)).pretty(), "100");
1752    }
1753
1754    #[test]
1755    fn uifmt_option_h64() {
1756        assert_eq!(None::<B256>.pretty(), "");
1757        assert_eq!(
1758            B256::with_last_byte(100).pretty(),
1759            "0x0000000000000000000000000000000000000000000000000000000000000064",
1760        );
1761        assert_eq!(
1762            Some(B256::with_last_byte(100)).pretty(),
1763            "0x0000000000000000000000000000000000000000000000000000000000000064",
1764        );
1765    }
1766
1767    #[test]
1768    fn uifmt_option_bytes() {
1769        assert_eq!(None::<Bytes>.pretty(), "");
1770        assert_eq!(
1771            bytes!("0x0000000000000000000000000000000000000000000000000000000000000064").pretty(),
1772            "0x0000000000000000000000000000000000000000000000000000000000000064",
1773        );
1774        assert_eq!(
1775            Some(bytes!("0x0000000000000000000000000000000000000000000000000000000000000064"))
1776                .pretty(),
1777            "0x0000000000000000000000000000000000000000000000000000000000000064",
1778        );
1779    }
1780
1781    #[test]
1782    fn test_pretty_tx_attr() {
1783        let block = r#"{"number":"0x3","hash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","parentHash":"0x689c70c080ca22bc0e681694fa803c1aba16a69c8b6368fed5311d279eb9de90","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x7270c1c4440180f2bd5215809ee3d545df042b67329499e1ab97eb759d31610d","stateRoot":"0x29f32984517a7d25607da485b23cefabfd443751422ca7e603395e1de9bc8a4b","receiptsRoot":"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2","miner":"0x0000000000000000000000000000000000000000","difficulty":"0x0","totalDifficulty":"0x0","extraData":"0x","size":"0x3e8","gasLimit":"0x6691b7","gasUsed":"0x5208","timestamp":"0x5ecedbb9","transactions":[{"hash":"0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067","nonce":"0x2","blockHash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","blockNumber":"0x3","transactionIndex":"0x0","from":"0xfdcedc3bfca10ecb0890337fbdd1977aba84807a","to":"0xdca8ce283150ab773bcbeb8d38289bdb5661de1e","value":"0x0","gas":"0x15f90","gasPrice":"0x4a817c800","input":"0x","v":"0x25","r":"0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88","s":"0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e"}],"uncles":[]}"#;
1784        let block: Block = serde_json::from_str(block).unwrap();
1785        let txs = match block.transactions() {
1786            BlockTransactions::Full(txes) => txes,
1787            _ => panic!("not full transactions"),
1788        };
1789
1790        assert_eq!(None, get_pretty_tx_attr::<Ethereum>(&txs[0], ""));
1791        assert_eq!(Some("3".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "blockNumber"));
1792        assert_eq!(
1793            Some("0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a".to_string()),
1794            get_pretty_tx_attr::<Ethereum>(&txs[0], "from")
1795        );
1796        assert_eq!(Some("90000".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "gas"));
1797        assert_eq!(
1798            Some("20000000000".to_string()),
1799            get_pretty_tx_attr::<Ethereum>(&txs[0], "gasPrice")
1800        );
1801        assert_eq!(
1802            Some("0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067".to_string()),
1803            get_pretty_tx_attr::<Ethereum>(&txs[0], "hash")
1804        );
1805        assert_eq!(Some("0x".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "input"));
1806        assert_eq!(Some("2".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "nonce"));
1807        assert_eq!(
1808            Some("0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88".to_string()),
1809            get_pretty_tx_attr::<Ethereum>(&txs[0], "r")
1810        );
1811        assert_eq!(
1812            Some("0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e".to_string()),
1813            get_pretty_tx_attr::<Ethereum>(&txs[0], "s")
1814        );
1815        assert_eq!(
1816            Some("0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e".into()),
1817            get_pretty_tx_attr::<Ethereum>(&txs[0], "to")
1818        );
1819        assert_eq!(
1820            Some("0".to_string()),
1821            get_pretty_tx_attr::<Ethereum>(&txs[0], "transactionIndex")
1822        );
1823        assert_eq!(Some("27".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "v"));
1824        assert_eq!(Some("0".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "value"));
1825    }
1826
1827    #[test]
1828    fn test_pretty_block_attr() {
1829        let json = serde_json::json!(
1830        {
1831            "baseFeePerGas": "0x7",
1832            "miner": "0x0000000000000000000000000000000000000001",
1833            "number": "0x1b4",
1834            "hash": "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
1835            "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
1836            "mixHash": "0x1010101010101010101010101010101010101010101010101010101010101010",
1837            "nonce": "0x0000000000000000",
1838            "sealFields": [
1839              "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
1840              "0x0000000000000042"
1841            ],
1842            "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
1843            "logsBloom":  "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
1844            "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1845            "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1846            "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
1847            "difficulty": "0x1",
1848            "totalDifficulty": "0x27f07",
1849            "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
1850            "size": "0x27f07",
1851            "gasLimit": "0x9f759",
1852            "minGasPrice": "0x9f759",
1853            "gasUsed": "0x9f759",
1854            "timestamp": "0x54e34e8e",
1855            "transactions": [],
1856            "uncles": [],
1857          }
1858        );
1859
1860        let block: Block = serde_json::from_value(json).unwrap();
1861
1862        assert_eq!(None, get_pretty_block_attr::<Ethereum>(&block, ""));
1863        assert_eq!(
1864            Some("7".to_string()),
1865            get_pretty_block_attr::<Ethereum>(&block, "baseFeePerGas")
1866        );
1867        assert_eq!(Some("1".to_string()), get_pretty_block_attr::<Ethereum>(&block, "difficulty"));
1868        assert_eq!(
1869            Some("0x0000000000000000000000000000000000000000000000000000000000000000".to_string()),
1870            get_pretty_block_attr::<Ethereum>(&block, "extraData")
1871        );
1872        assert_eq!(
1873            Some("653145".to_string()),
1874            get_pretty_block_attr::<Ethereum>(&block, "gasLimit")
1875        );
1876        assert_eq!(
1877            Some("653145".to_string()),
1878            get_pretty_block_attr::<Ethereum>(&block, "gasUsed")
1879        );
1880        assert_eq!(
1881            Some("0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_string()),
1882            get_pretty_block_attr::<Ethereum>(&block, "hash")
1883        );
1884        assert_eq!(Some("0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_string()), get_pretty_block_attr::<Ethereum>(&block, "logsBloom"));
1885        assert_eq!(
1886            Some("0x0000000000000000000000000000000000000001".to_string()),
1887            get_pretty_block_attr::<Ethereum>(&block, "miner")
1888        );
1889        assert_eq!(
1890            Some("0x1010101010101010101010101010101010101010101010101010101010101010".to_string()),
1891            get_pretty_block_attr::<Ethereum>(&block, "mixHash")
1892        );
1893        assert_eq!(
1894            Some("0x0000000000000000".to_string()),
1895            get_pretty_block_attr::<Ethereum>(&block, "nonce")
1896        );
1897        assert_eq!(Some("436".to_string()), get_pretty_block_attr::<Ethereum>(&block, "number"));
1898        assert_eq!(
1899            Some("0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5".to_string()),
1900            get_pretty_block_attr::<Ethereum>(&block, "parentHash")
1901        );
1902        assert_eq!(
1903            Some("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_string()),
1904            get_pretty_block_attr::<Ethereum>(&block, "transactionsRoot")
1905        );
1906        assert_eq!(
1907            Some("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_string()),
1908            get_pretty_block_attr::<Ethereum>(&block, "receiptsRoot")
1909        );
1910        assert_eq!(
1911            Some("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_string()),
1912            get_pretty_block_attr::<Ethereum>(&block, "sha3Uncles")
1913        );
1914        assert_eq!(Some("163591".to_string()), get_pretty_block_attr::<Ethereum>(&block, "size"));
1915        assert_eq!(
1916            Some("0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff".to_string()),
1917            get_pretty_block_attr::<Ethereum>(&block, "stateRoot")
1918        );
1919        assert_eq!(
1920            Some("1424182926".to_string()),
1921            get_pretty_block_attr::<Ethereum>(&block, "timestamp")
1922        );
1923        assert_eq!(
1924            Some("163591".to_string()),
1925            get_pretty_block_attr::<Ethereum>(&block, "totalDifficulty")
1926        );
1927
1928        let pretty = pretty_generic_header_response(block.header());
1929        assert!(pretty.contains("difficulty           1"), "{pretty}");
1930        assert!(pretty.contains("totalDifficulty      163591"), "{pretty}");
1931    }
1932
1933    #[test]
1934    fn test_receipt_other_fields_alignment() {
1935        let receipt_json = serde_json::json!(
1936        {
1937          "status": "0x1",
1938          "cumulativeGasUsed": "0x74e483",
1939          "logs": [],
1940          "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1941          "type": "0x2",
1942          "transactionHash": "0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d",
1943          "transactionIndex": "0x10",
1944          "blockHash": "0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d",
1945          "blockNumber": "0x7b1ab93",
1946          "gasUsed": "0xc222",
1947          "effectiveGasPrice": "0x18961",
1948          "from": "0x2d815240a61731c75fa01b2793e1d3ed09f289d0",
1949          "to": "0x4200000000000000000000000000000000000000",
1950          "contractAddress": null,
1951          "l1BaseFeeScalar": "0x146b",
1952          "l1BlobBaseFee": "0x6a83078",
1953          "l1BlobBaseFeeScalar": "0xf79c5",
1954          "l1Fee": "0x51a9af7fd3",
1955          "l1GasPrice": "0x972fe4acc",
1956          "l1GasUsed": "0x640"
1957        });
1958
1959        let receipt: AnyTransactionReceipt = serde_json::from_value(receipt_json).unwrap();
1960        let formatted = receipt.pretty();
1961
1962        let expected = r#"
1963blockHash            0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d
1964blockNumber          129084307
1965contractAddress      
1966cumulativeGasUsed    7660675
1967effectiveGasPrice    100705
1968from                 0x2D815240A61731c75Fa01b2793E1D3eD09F289d0
1969gasUsed              49698
1970logs                 []
1971logsBloom            0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1972root                 
1973status               1 (success)
1974transactionHash      0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d
1975transactionIndex     16
1976type                 2
1977blobGasPrice         
1978blobGasUsed          
1979to                   0x4200000000000000000000000000000000000000
1980l1BaseFeeScalar      5227
1981l1BlobBaseFee        111685752
1982l1BlobBaseFeeScalar  1014213
1983l1Fee                350739202003
1984l1GasPrice           40583973580
1985l1GasUsed            1600
1986"#;
1987
1988        assert_eq!(formatted.trim(), expected.trim());
1989    }
1990
1991    #[test]
1992    fn test_uifmt_for_signed_authorization() {
1993        let inner = Authorization {
1994            chain_id: U256::ONE,
1995            address: address!("0x000000000000000000000000000000000000dead"),
1996            nonce: 42,
1997        };
1998        let signed_authorization =
1999            SignedAuthorization::new_unchecked(inner, 1, U256::from(20), U256::from(30));
2000
2001        assert_eq!(
2002            signed_authorization.pretty(),
2003            r#"{recoveredAuthority: 0xf3eaBD0de6Ca1aE7fC4D81FfD6C9a40e5D5D7e30, signedAuthority: {"chainId":"0x1","address":"0x000000000000000000000000000000000000dead","nonce":"0x2a","yParity":"0x1","r":"0x14","s":"0x1e"}}"#
2004        );
2005    }
2006
2007    #[test]
2008    fn can_pretty_print_tempo_tx() {
2009        let s = r#"{
2010            "type":"0x76",
2011            "chainId":"0xa5bd",
2012            "feeToken":"0x20c0000000000000000000000000000000000001",
2013            "maxPriorityFeePerGas":"0x0",
2014            "maxFeePerGas":"0x2cb417800",
2015            "gas":"0x2d178",
2016            "calls":[
2017                {
2018                    "data":null,
2019                    "input":"0x095ea7b3000000000000000000000000dec00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000989680",
2020                    "to":"0x20c0000000000000000000000000000000000000",
2021                    "value":"0x0"
2022                },
2023                {
2024                    "data":null,
2025                    "input":"0xf8856c0f00000000000000000000000020c000000000000000000000000000000000000000000000000000000000000020c00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000097d330",
2026                    "to":"0xdec0000000000000000000000000000000000000",
2027                    "value":"0x0"
2028                }
2029            ],
2030            "accessList":[],
2031            "nonceKey":"0x0",
2032            "nonce":"0x0",
2033            "feePayerSignature":null,
2034            "validBefore":null,
2035            "validAfter":null,
2036            "keyAuthorization":null,
2037            "aaAuthorizationList":[],
2038            "signature":{
2039                "pubKeyX":"0xaacc80b21e45fb11f349424dce3a2f23547f60c0ff2f8bcaede2a247545ce8dd",
2040                "pubKeyY":"0x87abf0dbb7a5c9507efae2e43833356651b45ac576c2e61cec4e9c0f41fcbf6e",
2041                "r":"0xcfd45c3b19745a42f80b134dcb02a8ba099a0e4e7be1984da54734aa81d8f29f",
2042                "s":"0x74bb9170ae6d25bd510c83fe35895ee5712efe13980a5edc8094c534e23af85e",
2043                "type":"webAuthn",
2044                "webauthnData":"0x7b98b7a8e6c68d7eac741a52e6fdae0560ce3c16ef5427ad46d7a54d0ed86dd41d000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2238453071464a7a50585167546e645473643649456659457776323173516e626966374c4741776e4b43626b222c226f726967696e223a2268747470733a2f2f74656d706f2d6465782e76657263656c2e617070222c2263726f73734f726967696e223a66616c73657d"
2045            },
2046            "hash":"0x6d6d8c102064e6dee44abad2024a8b1d37959230baab80e70efbf9b0c739c4fd",
2047            "blockHash":"0xc82b23589ceef5341ed307d33554714db6f9eefd4187a9ca8abc910a325b4689",
2048            "blockNumber":"0x321fde",
2049            "transactionIndex":"0x0",
2050            "from":"0x566ff0f4a6114f8072ecdc8a7a8a13d8d0c6b45f",
2051            "gasPrice":"0x2540be400"
2052        }"#;
2053
2054        let tx: Transaction<TempoTxEnvelope> = serde_json::from_str(s).unwrap();
2055
2056        assert_eq!(
2057            tx.pretty().trim(),
2058            r#"
2059blockHash            0xc82b23589ceef5341ed307d33554714db6f9eefd4187a9ca8abc910a325b4689
2060blockNumber          3284958
2061from                 0x566Ff0f4a6114F8072ecDC8A7A8A13d8d0C6B45F
2062transactionIndex     0
2063effectiveGasPrice    10000000000
2064hash                 0x6d6d8c102064e6dee44abad2024a8b1d37959230baab80e70efbf9b0c739c4fd
2065type                 118
2066chainId              42429
2067feeToken             0x20C0000000000000000000000000000000000001
2068maxPriorityFeePerGas 0
2069maxFeePerGas         12000000000
2070gasLimit             184696
2071calls                [
2072	to: 0x20C0000000000000000000000000000000000000, value: 0, input: 0x095ea7b3000000000000000000000000dec00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000989680
2073	to: 0xDEc0000000000000000000000000000000000000, value: 0, input: 0xf8856c0f00000000000000000000000020c000000000000000000000000000000000000000000000000000000000000020c00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000097d330
2074]
2075accessList           []
2076nonceKey             0
2077nonce                0
2078feePayerSignature    
2079validBefore          
2080validAfter           
2081tempoSignature       {"type":"webAuthn","r":"0xcfd45c3b19745a42f80b134dcb02a8ba099a0e4e7be1984da54734aa81d8f29f","s":"0x74bb9170ae6d25bd510c83fe35895ee5712efe13980a5edc8094c534e23af85e","pubKeyX":"0xaacc80b21e45fb11f349424dce3a2f23547f60c0ff2f8bcaede2a247545ce8dd","pubKeyY":"0x87abf0dbb7a5c9507efae2e43833356651b45ac576c2e61cec4e9c0f41fcbf6e","webauthnData":"0x7b98b7a8e6c68d7eac741a52e6fdae0560ce3c16ef5427ad46d7a54d0ed86dd41d000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2238453071464a7a50585167546e645473643649456659457776323173516e626966374c4741776e4b43626b222c226f726967696e223a2268747470733a2f2f74656d706f2d6465782e76657263656c2e617070222c2263726f73734f726967696e223a66616c73657d"}
2082"#
2083                .trim()
2084        );
2085    }
2086
2087    #[test]
2088    fn can_pretty_print_tempo_receipt() {
2089        let s = r#"{"type":"0x76","status":"0x1","cumulativeGasUsed":"0x176d7f4","logs":[{"address":"0x20c0000000000000000000000000000000000000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x0000000000000000000000000000000000000000000000000000000000000001"],"data":"0x00000000000000000000000000000000000000000000000000000000000003e8","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb8","removed":false},{"address":"0x20c0000000000000000000000000000000000003","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x000000000000000000000000feec000000000000000000000000000000000000"],"data":"0x0000000000000000000000000000000000000000000000000000000000000417","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb9","removed":false}],"logsBloom":"0x00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000040008000004200000000000000008000000000000000000040000000000000400000000000002000000000000000000000000000000000000000000000010000000000000000000000000000000000020000000000000800000000000000000000000000020000000000000000000000000000000000400000000000000000000000000000002000000000000000400000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","gasUsed":"0xcc6a","effectiveGasPrice":"0x4a817c802","from":"0xa70ab0448e66cd77995bfbba5c5b64b41a85f3fd","to":"0x20c0000000000000000000000000000000000000","contractAddress":null,"feeToken":"0x20c0000000000000000000000000000000000003","feePayer":"0xa70ab0448e66cd77995bfbba5c5b64b41a85f3fd"}"#;
2090
2091        let tx: TempoTransactionReceipt = serde_json::from_str(s).unwrap();
2092
2093        assert_eq!(
2094            tx.pretty().trim(),
2095            r#"
2096blockHash            0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66
2097blockNumber          6922711
2098contractAddress      
2099cumulativeGasUsed    24565748
2100effectiveGasPrice    20000000002
2101from                 0xa70ab0448e66cD77995bfBBa5c5b64B41a85F3fd
2102gasUsed              52330
2103logs                 [{"address":"0x20c0000000000000000000000000000000000000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x0000000000000000000000000000000000000000000000000000000000000001"],"data":"0x00000000000000000000000000000000000000000000000000000000000003e8","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb8","removed":false},{"address":"0x20c0000000000000000000000000000000000003","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x000000000000000000000000feec000000000000000000000000000000000000"],"data":"0x0000000000000000000000000000000000000000000000000000000000000417","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb9","removed":false}]
2104logsBloom            0x00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000040008000004200000000000000008000000000000000000040000000000000400000000000002000000000000000000000000000000000000000000000010000000000000000000000000000000000020000000000000800000000000000000000000000020000000000000000000000000000000000400000000000000000000000000000002000000000000000400000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000
2105root                 
2106status               true
2107transactionHash      0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f
2108transactionIndex     99
2109type                 118
2110feePayer             0xa70ab0448e66cD77995bfBBa5c5b64B41a85F3fd
2111feeToken             0x20C0000000000000000000000000000000000003
2112to                   0x20C0000000000000000000000000000000000000
2113"#
2114                .trim()
2115        );
2116    }
2117
2118    #[test]
2119    fn test_ethereum_receipt_uifmt() {
2120        let s = r#"{"type":"0x2","status":"0x1","cumulativeGasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x1234567890123456789012345678901234567890123456789012345678901234","transactionIndex":"0x0","blockHash":"0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd","blockNumber":"0x1","gasUsed":"0x5208","effectiveGasPrice":"0x3b9aca00","from":"0x1234567890123456789012345678901234567890","to":"0x0987654321098765432109876543210987654321","contractAddress":null}"#;
2121        let receipt: TransactionReceipt = serde_json::from_str(s).unwrap();
2122
2123        let pretty_output = receipt.pretty();
2124
2125        assert!(pretty_output.contains("blockHash"));
2126        assert!(pretty_output.contains("blockNumber"));
2127        assert!(pretty_output.contains("status"));
2128        assert!(pretty_output.contains("gasUsed"));
2129        assert!(pretty_output.contains("transactionHash"));
2130        assert!(pretty_output.contains("type"));
2131        assert!(
2132            pretty_output
2133                .contains("0x1234567890123456789012345678901234567890123456789012345678901234")
2134        );
2135        assert!(pretty_output.contains("1 (success)"));
2136        assert!(pretty_output.contains("0x0987654321098765432109876543210987654321"));
2137    }
2138
2139    #[test]
2140    fn test_get_pretty_receipt_attr() {
2141        let receipt_json = serde_json::json!({
2142            "type": "0x2",
2143            "status": "0x1",
2144            "cumulativeGasUsed": "0x5208",
2145            "logs": [],
2146            "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
2147            "transactionHash": "0x1234567890123456789012345678901234567890123456789012345678901234",
2148            "transactionIndex": "0x0",
2149            "blockHash": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd",
2150            "blockNumber": "0x1",
2151            "gasUsed": "0x5208",
2152            "effectiveGasPrice": "0x3b9aca00",
2153            "from": "0x1234567890123456789012345678901234567890",
2154            "to": "0x0987654321098765432109876543210987654321",
2155            "contractAddress": null
2156        });
2157
2158        let receipt: TransactionReceipt = serde_json::from_value(receipt_json).unwrap();
2159
2160        // Test basic receipt attributes
2161        assert_eq!(
2162            Some("0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd".to_string()),
2163            get_pretty_receipt_attr::<Ethereum>(&receipt, "blockHash")
2164        );
2165        assert_eq!(
2166            Some("1".to_string()),
2167            get_pretty_receipt_attr::<Ethereum>(&receipt, "blockNumber")
2168        );
2169        assert_eq!(
2170            Some("0x1234567890123456789012345678901234567890123456789012345678901234".to_string()),
2171            get_pretty_receipt_attr::<Ethereum>(&receipt, "transactionHash")
2172        );
2173        assert_eq!(
2174            Some("21000".to_string()),
2175            get_pretty_receipt_attr::<Ethereum>(&receipt, "gasUsed")
2176        );
2177        assert_eq!(
2178            Some("true".to_string()),
2179            get_pretty_receipt_attr::<Ethereum>(&receipt, "status")
2180        );
2181        assert_eq!(
2182            Some("EIP-1559".to_string()),
2183            get_pretty_receipt_attr::<Ethereum>(&receipt, "type")
2184        );
2185        assert_eq!(Some("[]".to_string()), get_pretty_receipt_attr::<Ethereum>(&receipt, "logs"));
2186        assert!(get_pretty_receipt_attr::<Ethereum>(&receipt, "logsBloom").is_some());
2187    }
2188}