|
1 | 1 | use crate::Error;
|
2 | 2 | use alloy_consensus::{Receipt, ReceiptWithBloom};
|
3 | 3 | use alloy_consensus::{ReceiptEnvelope, TxType};
|
4 |
| - |
| 4 | +use alloy_eips::eip2718::Decodable2718; |
| 5 | +use alloy_network::eip2718::Encodable2718; |
5 | 6 | use alloy_primitives::U64;
|
6 | 7 | use alloy_primitives::{Bloom, Log, LogData, U8};
|
7 | 8 | use alloy_rpc_types::{Log as RpcLog, TransactionReceipt};
|
8 | 9 |
|
9 | 10 | #[derive(Debug, Clone)]
|
10 | 11 | pub struct ConsensusTxReceipt(pub ReceiptEnvelope);
|
11 | 12 |
|
| 13 | +impl ConsensusTxReceipt { |
| 14 | + pub fn rlp_encode(&self) -> Vec<u8> { |
| 15 | + self.0.encoded_2718() |
| 16 | + } |
| 17 | + |
| 18 | + pub fn rlp_decode(mut data: &[u8]) -> Result<Self, Error> { |
| 19 | + let envelope = ReceiptEnvelope::decode_2718(&mut data).map_err(Error::Rlp)?; |
| 20 | + Ok(ConsensusTxReceipt(envelope)) |
| 21 | + } |
| 22 | + |
| 23 | + pub fn success(&self) -> bool { |
| 24 | + match &self.0 { |
| 25 | + ReceiptEnvelope::Legacy(receipt) => receipt.receipt.success, |
| 26 | + ReceiptEnvelope::Eip2930(receipt) => receipt.receipt.success, |
| 27 | + ReceiptEnvelope::Eip1559(receipt) => receipt.receipt.success, |
| 28 | + ReceiptEnvelope::Eip4844(receipt) => receipt.receipt.success, |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + pub fn cumulative_gas_used(&self) -> u64 { |
| 33 | + match &self.0 { |
| 34 | + ReceiptEnvelope::Legacy(receipt) => receipt.receipt.cumulative_gas_used, |
| 35 | + ReceiptEnvelope::Eip2930(receipt) => receipt.receipt.cumulative_gas_used, |
| 36 | + ReceiptEnvelope::Eip1559(receipt) => receipt.receipt.cumulative_gas_used, |
| 37 | + ReceiptEnvelope::Eip4844(receipt) => receipt.receipt.cumulative_gas_used, |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + pub fn logs(&self) -> Vec<Log<LogData>> { |
| 42 | + match &self.0 { |
| 43 | + ReceiptEnvelope::Legacy(receipt) => receipt.receipt.logs.clone(), |
| 44 | + ReceiptEnvelope::Eip2930(receipt) => receipt.receipt.logs.clone(), |
| 45 | + ReceiptEnvelope::Eip1559(receipt) => receipt.receipt.logs.clone(), |
| 46 | + ReceiptEnvelope::Eip4844(receipt) => receipt.receipt.logs.clone(), |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + pub fn bloom(&self) -> Bloom { |
| 51 | + match &self.0 { |
| 52 | + ReceiptEnvelope::Legacy(receipt) => receipt.bloom, |
| 53 | + ReceiptEnvelope::Eip2930(receipt) => receipt.bloom, |
| 54 | + ReceiptEnvelope::Eip1559(receipt) => receipt.bloom, |
| 55 | + ReceiptEnvelope::Eip4844(receipt) => receipt.bloom, |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
12 | 60 | #[derive(Debug, Clone)]
|
13 | 61 | pub(crate) struct RpcTxReceipt(pub TransactionReceipt);
|
14 | 62 |
|
|
0 commit comments