Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: Optimism Hydrated RPC Receipt Fields #2591

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions ethers-core/src/types/transaction/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,25 @@ pub struct TransactionReceipt {
/// amount that's actually paid by users can only be determined post-execution
#[serde(rename = "effectiveGasPrice", default, skip_serializing_if = "Option::is_none")]
pub effective_gas_price: Option<U256>,
/// Deposit nonce for Optimism deposited transactions
#[cfg(feature = "optimism")]
pub deposit_nonce: Option<u64>,
/// L1 fee for the transaction
#[cfg(feature = "optimism")]
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee: Option<U256>,
/// L1 fee scalar for the transaction
#[cfg(feature = "optimism")]
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_fee_scalar: Option<U256>,
/// L1 gas price for the transaction
#[cfg(feature = "optimism")]
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_price: Option<U256>,
/// L1 gas used for the transaction
#[cfg(feature = "optimism")]
#[serde(skip_serializing_if = "Option::is_none")]
pub l1_gas_used: Option<U256>,
/// Captures unknown fields such as additional fields used by L2s
#[cfg(not(feature = "celo"))]
#[serde(flatten)]
Expand All @@ -478,11 +497,29 @@ pub struct TransactionReceipt {

impl rlp::Encodable for TransactionReceipt {
fn rlp_append(&self, s: &mut RlpStream) {
#[cfg(feature = "optimism")]
let is_deposit = self.transaction_type == Some(U64::from(0x7E));
#[cfg(feature = "optimism")]
{
if is_deposit {
s.append(&U64::from(0x7E));
s.begin_list(5);
} else {
s.begin_list(4);
}
}
#[cfg(not(feature = "optimism"))]
s.begin_list(4);
rlp_opt(s, &self.status);
s.append(&self.cumulative_gas_used);
s.append(&self.logs_bloom);
s.append_list(&self.logs);
#[cfg(feature = "optimism")]
if is_deposit {
if let Some(deposit_nonce) = self.deposit_nonce {
s.append(&deposit_nonce);
}
}
}
}

Expand All @@ -508,6 +545,43 @@ impl PartialOrd<Self> for TransactionReceipt {
}
}

#[cfg(test)]
#[cfg(feature = "optimism")]
mod tests {
use super::*;
use rlp::Encodable;

#[test]
fn decode_deposit_receipt_regolith_roundtrip() {
let data = hex::decode("7ef9010c0182b741b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0833d3bbf").unwrap();
let expected = TransactionReceipt {
transaction_hash: H256::zero(),
transaction_index: U64::zero(),
block_hash: None,
block_number: None,
from: Address::zero(),
to: None,
cumulative_gas_used: U256::from(46913),
gas_used: None,
contract_address: None,
logs: vec![],
status: Some(U64::from(1)),
root: None,
logs_bloom: Bloom::default(),
transaction_type: Some(U64::from(0x7E)),
effective_gas_price: None,
deposit_nonce: Some(4012991),
l1_fee: None,
l1_fee_scalar: None,
l1_gas_price: None,
l1_gas_used: None,
#[cfg(not(feature = "celo"))]
other: crate::types::OtherFields::default(),
};
assert_eq!(expected.rlp_bytes().to_vec(), data);
}
}

#[cfg(test)]
#[cfg(not(any(feature = "celo", feature = "optimism")))]
mod tests {
Expand Down