alloy_rpc_types_any/transaction/
receipt.rs1use alloy_consensus_any::AnyReceiptEnvelope;
2use alloy_rpc_types_eth::{Log, TransactionReceipt};
3use alloy_serde::WithOtherFields;
4
5#[doc(alias = "AnyTxReceipt")]
7pub type AnyTransactionReceipt = WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;
8
9#[cfg(test)]
10mod test {
11 use super::*;
12 use alloy_primitives::b256;
13
14 #[test]
15 fn deserialize_tx_receipt_op() {
16 #[derive(Debug, serde::Deserialize)]
18 struct OpOtherFields {
19 #[serde(rename = "l1BaseFeeScalar")]
20 l1_base_fee_scalar: String,
21 #[serde(rename = "l1BlobBaseFee")]
22 l1_blob_base_fee: String,
23 #[serde(rename = "l1BlobBaseFeeScalar")]
24 l1_blob_base_fee_scalar: String,
25 #[serde(rename = "l1Fee")]
26 l1_fee: String,
27 #[serde(rename = "l1GasPrice")]
28 l1_gas_price: String,
29 #[serde(rename = "l1GasUsed")]
30 l1_gas_used: String,
31 }
32
33 let receipt_json = r#"
34 {
35 "status": "0x1",
36 "cumulativeGasUsed": "0xf1740",
37 "logs": [
38 {
39 "address": "0x4200000000000000000000000000000000000006",
40 "topics": [
41 "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
42 "0x0000000000000000000000005112996d3ae99f0b5360cea1a620ffcd78e8ff83",
43 "0x00000000000000000000000077e7c5cbeaad915cf5462064b02984e16a902e67"
44 ],
45 "data": "0x000000000000000000000000000000000000000000000000001c66f6e8b40c00",
46 "blockHash": "0x88e07a0d797b84bd122d6993a6faf5a59ada7f40c181c553c191dd400d3d1583",
47 "blockNumber": "0x73a43e1",
48 "transactionHash": "0x2bc7cb4648e847712e39abd42178e35214a70bb15c568d604687661b9539b4c2",
49 "transactionIndex": "0x9",
50 "logIndex": "0x16",
51 "removed": false
52 }
53 ],
54 "logsBloom": "0x00000000000000000000000000000000000000000000000000040000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000008000000100000000000000000100000000000000000000010000020000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000002000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
55 "type": "0x0",
56 "transactionHash": "0x2bc7cb4648e847712e39abd42178e35214a70bb15c568d604687661b9539b4c2",
57 "transactionIndex": "0x9",
58 "blockHash": "0x88e07a0d797b84bd122d6993a6faf5a59ada7f40c181c553c191dd400d3d1583",
59 "blockNumber": "0x73a43e1",
60 "gasUsed": "0x85b9",
61 "effectiveGasPrice": "0x3ac9e84",
62 "from": "0x5112996d3ae99f0b5360cea1a620ffcd78e8ff83",
63 "to": "0x4200000000000000000000000000000000000006",
64 "contractAddress": null,
65 "l1BaseFeeScalar": "0x558",
66 "l1BlobBaseFee": "0x1",
67 "l1BlobBaseFeeScalar": "0xc5fc5",
68 "l1Fee": "0x105d4b2024",
69 "l1GasPrice": "0x5d749a07e",
70 "l1GasUsed": "0x800"
71 }
72 "#;
73 let receipt = serde_json::from_str::<AnyTransactionReceipt>(receipt_json).unwrap();
74
75 assert_eq!(
76 receipt.transaction_hash,
77 b256!("2bc7cb4648e847712e39abd42178e35214a70bb15c568d604687661b9539b4c2")
78 );
79
80 let other: OpOtherFields = receipt.other.deserialize_into().unwrap();
81 assert_eq!(other.l1_base_fee_scalar, "0x558");
82 assert_eq!(other.l1_blob_base_fee, "0x1");
83 assert_eq!(other.l1_blob_base_fee_scalar, "0xc5fc5");
84 assert_eq!(other.l1_fee, "0x105d4b2024");
85 assert_eq!(other.l1_gas_price, "0x5d749a07e");
86 assert_eq!(other.l1_gas_used, "0x800");
87 }
88
89 #[test]
90 fn deserialize_tx_receipt_arb() {
91 #[derive(Debug, serde::Deserialize)]
93 struct ArbOtherFields {
94 #[serde(rename = "gasUsedForL1")]
95 gas_used_for_l1: String,
96 #[serde(rename = "l1BlockNumber")]
97 l1_block_number: String,
98 }
99
100 let receipt_json = r#"
101 {
102 "status": "0x1",
103 "cumulativeGasUsed": "0x27ebb8",
104 "logs": [
105 {
106 "address": "0x912ce59144191c1204e64559fe8253a0e49e6548",
107 "topics": [
108 "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
109 "0x000000000000000000000000e487d95426e55a29f2266e6788ab55608ebb829b",
110 "0x0000000000000000000000009855134ed0c8b71266d9f3e15c0a518c07be5baf"
111 ],
112 "data": "0x00000000000000000000000000000000000000000000000009d40825d5ee8000",
113 "blockHash": "0x83ddb8850803238bd58615680bc3718686ec1e3deaea0bc5f67c07c8577547f5",
114 "blockNumber": "0xd288ac5",
115 "transactionHash": "0x5aeca744e0c1f6d7f68641aedd394ac4b6e18cbeac3f8b3c81056c0e51a61cf3",
116 "transactionIndex": "0x7",
117 "logIndex": "0x7",
118 "removed": false
119 }
120 ],
121 "logsBloom": "0x00000000000000000000000000000000000000000000000000000000005000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000100000000000001000000000000000000000000000000000000000000020000000000000000000004400000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
122 "type": "0x0",
123 "transactionHash": "0x5aeca744e0c1f6d7f68641aedd394ac4b6e18cbeac3f8b3c81056c0e51a61cf3",
124 "transactionIndex": "0x7",
125 "blockHash": "0x83ddb8850803238bd58615680bc3718686ec1e3deaea0bc5f67c07c8577547f5",
126 "blockNumber": "0xd288ac5",
127 "gasUsed": "0x3ad89",
128 "effectiveGasPrice": "0x989680",
129 "from": "0xe487d95426e55a29f2266e6788ab55608ebb829b",
130 "to": "0x912ce59144191c1204e64559fe8253a0e49e6548",
131 "contractAddress": null,
132 "gasUsedForL1": "0x2c906",
133 "l1BlockNumber": "0x1323b96"
134 }
135 "#;
136 let receipt = serde_json::from_str::<AnyTransactionReceipt>(receipt_json).unwrap();
137
138 assert_eq!(
139 receipt.transaction_hash,
140 b256!("5aeca744e0c1f6d7f68641aedd394ac4b6e18cbeac3f8b3c81056c0e51a61cf3")
141 );
142
143 let other: ArbOtherFields = receipt.other.deserialize_into().unwrap();
144 assert_eq!(other.gas_used_for_l1, "0x2c906");
145 assert_eq!(other.l1_block_number, "0x1323b96");
146 }
147}