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

fix: Update optimism type names to be inline with reth #2590

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ethers-contract/src/multicall/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl<M: Middleware> Multicall<M> {
TypedTransaction::Eip2930(tx) => (tx.tx.to, tx.tx.data, tx.tx.value),
TypedTransaction::Eip1559(tx) => (tx.to, tx.data, tx.value),
#[cfg(feature = "optimism")]
TypedTransaction::OptimismDeposited(tx) => (tx.tx.to, tx.tx.data, tx.tx.value),
TypedTransaction::DepositTransaction(tx) => (tx.tx.to, tx.tx.data, tx.tx.value),
};
if data.is_none() && !call.function.outputs.is_empty() {
return self
Expand Down
78 changes: 37 additions & 41 deletions ethers-core/src/types/transaction/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

#[cfg(feature = "optimism")]
use super::optimism_deposited::{
OptimismDepositedRequestError, OptimismDepositedTransactionRequest,
};
use super::optimism::{DepositTransaction, DepositTransactionError};

/// The TypedTransaction enum represents all Ethereum transaction types.
///
Expand Down Expand Up @@ -45,7 +43,7 @@ pub enum TypedTransaction {
// 0x7E
#[cfg(feature = "optimism")]
#[serde(rename = "0x7E")]
OptimismDeposited(OptimismDepositedTransactionRequest),
DepositTransaction(DepositTransaction),
}

/// An error involving a typed transaction request.
Expand All @@ -63,7 +61,7 @@ pub enum TypedTransactionError {
/// When decoding a signed Optimism Deposited transaction
#[cfg(feature = "optimism")]
#[error(transparent)]
OptimismDepositedError(#[from] OptimismDepositedRequestError),
DepositTransactionError(#[from] DepositTransactionError),
/// Error decoding the transaction type from the transaction's RLP encoding
#[error(transparent)]
TypeDecodingError(#[from] rlp::DecoderError),
Expand Down Expand Up @@ -98,7 +96,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.from.as_ref(),
Eip1559(inner) => inner.from.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.from.as_ref(),
DepositTransaction(inner) => inner.tx.from.as_ref(),
}
}

Expand All @@ -108,7 +106,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.from = Some(from),
Eip1559(inner) => inner.from = Some(from),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.from = Some(from),
DepositTransaction(inner) => inner.tx.from = Some(from),
};
self
}
Expand All @@ -119,7 +117,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.to.as_ref(),
Eip1559(inner) => inner.to.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.to.as_ref(),
DepositTransaction(inner) => inner.tx.to.as_ref(),
}
}

Expand All @@ -134,7 +132,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.to = Some(to),
Eip1559(inner) => inner.to = Some(to),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.to = Some(to),
DepositTransaction(inner) => inner.tx.to = Some(to),
};
self
}
Expand All @@ -145,7 +143,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.nonce.as_ref(),
Eip1559(inner) => inner.nonce.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.nonce.as_ref(),
DepositTransaction(inner) => inner.tx.nonce.as_ref(),
}
}

Expand All @@ -156,7 +154,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.nonce = Some(nonce),
Eip1559(inner) => inner.nonce = Some(nonce),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.nonce = Some(nonce),
DepositTransaction(inner) => inner.tx.nonce = Some(nonce),
};
self
}
Expand All @@ -167,7 +165,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.value.as_ref(),
Eip1559(inner) => inner.value.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.value.as_ref(),
DepositTransaction(inner) => inner.tx.value.as_ref(),
}
}

Expand All @@ -178,7 +176,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.value = Some(value),
Eip1559(inner) => inner.value = Some(value),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.value = Some(value),
DepositTransaction(inner) => inner.tx.value = Some(value),
};
self
}
Expand All @@ -189,7 +187,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.gas.as_ref(),
Eip1559(inner) => inner.gas.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.gas.as_ref(),
DepositTransaction(inner) => inner.tx.gas.as_ref(),
}
}

Expand All @@ -199,7 +197,7 @@ impl TypedTransaction {
Eip2930(inner) => &mut inner.tx.gas,
Eip1559(inner) => &mut inner.gas,
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => &mut inner.tx.gas,
DepositTransaction(inner) => &mut inner.tx.gas,
}
}

Expand All @@ -210,7 +208,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.gas = Some(gas),
Eip1559(inner) => inner.gas = Some(gas),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.gas = Some(gas),
DepositTransaction(inner) => inner.tx.gas = Some(gas),
};
self
}
Expand All @@ -228,7 +226,7 @@ impl TypedTransaction {
}
}
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.gas_price,
DepositTransaction(inner) => inner.tx.gas_price,
}
}

Expand All @@ -242,7 +240,7 @@ impl TypedTransaction {
inner.max_priority_fee_per_gas = Some(gas_price);
}
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.gas_price = Some(gas_price),
DepositTransaction(inner) => inner.tx.gas_price = Some(gas_price),
};
self
}
Expand All @@ -253,7 +251,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.chain_id,
Eip1559(inner) => inner.chain_id,
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.chain_id,
DepositTransaction(inner) => inner.tx.chain_id,
}
}

Expand All @@ -264,7 +262,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.chain_id = Some(chain_id),
Eip1559(inner) => inner.chain_id = Some(chain_id),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.chain_id = Some(chain_id),
DepositTransaction(inner) => inner.tx.chain_id = Some(chain_id),
};
self
}
Expand All @@ -275,7 +273,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.data.as_ref(),
Eip1559(inner) => inner.data.as_ref(),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.data.as_ref(),
DepositTransaction(inner) => inner.tx.data.as_ref(),
}
}

Expand All @@ -285,7 +283,7 @@ impl TypedTransaction {
Eip2930(inner) => Some(&inner.access_list),
Eip1559(inner) => Some(&inner.access_list),
#[cfg(feature = "optimism")]
OptimismDeposited(_) => None,
DepositTransaction(_) => None,
}
}

Expand All @@ -295,7 +293,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.access_list = access_list,
Eip1559(inner) => inner.access_list = access_list,
#[cfg(feature = "optimism")]
OptimismDeposited(_) => {}
DepositTransaction(_) => {}
};
self
}
Expand All @@ -306,7 +304,7 @@ impl TypedTransaction {
Eip2930(inner) => inner.tx.data = Some(data),
Eip1559(inner) => inner.data = Some(data),
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => inner.tx.data = Some(data),
DepositTransaction(inner) => inner.tx.data = Some(data),
};
self
}
Expand All @@ -326,7 +324,7 @@ impl TypedTransaction {
encoded.extend_from_slice(inner.rlp_signed(signature).as_ref());
}
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => {
DepositTransaction(inner) => {
encoded.extend_from_slice(&[0x7E]);
encoded.extend_from_slice(inner.rlp().as_ref());
}
Expand All @@ -349,7 +347,7 @@ impl TypedTransaction {
encoded.extend_from_slice(inner.rlp().as_ref());
}
#[cfg(feature = "optimism")]
OptimismDeposited(inner) => {
DepositTransaction(inner) => {
encoded.extend_from_slice(&[0x7E]);
encoded.extend_from_slice(inner.rlp().as_ref());
}
Expand Down Expand Up @@ -407,8 +405,8 @@ impl TypedTransaction {
#[cfg(feature = "optimism")]
if first == 0x7E {
// Optimism Deposited (0x7E)
let decoded_request = OptimismDepositedTransactionRequest::decode_signed_rlp(&rest)?;
return Ok((Self::OptimismDeposited(decoded_request.0), decoded_request.1))
let decoded_request = DepositTransaction::decode_signed_rlp(&rest)?;
return Ok((Self::DepositTransaction(decoded_request.0), decoded_request.1))
}

Err(rlp::DecoderError::Custom("invalid tx type").into())
Expand Down Expand Up @@ -438,7 +436,7 @@ impl Decodable for TypedTransaction {
#[cfg(feature = "optimism")]
Some(x) if x == U64::from(0x7E) => {
// Optimism Deposited (0x7E)
Ok(Self::OptimismDeposited(OptimismDepositedTransactionRequest::decode(&rest)?))
Ok(Self::DepositTransaction(DepositTransaction::decode(&rest)?))
}
_ => {
// Legacy (0x00)
Expand Down Expand Up @@ -468,9 +466,9 @@ impl From<Eip1559TransactionRequest> for TypedTransaction {
}

#[cfg(feature = "optimism")]
impl From<OptimismDepositedTransactionRequest> for TypedTransaction {
fn from(src: OptimismDepositedTransactionRequest) -> TypedTransaction {
TypedTransaction::OptimismDeposited(src)
impl From<DepositTransaction> for TypedTransaction {
fn from(src: DepositTransaction) -> TypedTransaction {
TypedTransaction::DepositTransaction(src)
}
}

Expand All @@ -490,7 +488,7 @@ impl From<&Transaction> for TypedTransaction {
#[cfg(feature = "optimism")]
// Optimism Deposited (0x7E)
Some(x) if x == U64::from(0x7E) => {
let request: OptimismDepositedTransactionRequest = tx.into();
let request: DepositTransaction = tx.into();
request.into()
}
// Legacy (0x00)
Expand Down Expand Up @@ -522,9 +520,9 @@ impl TypedTransaction {
}
}
#[cfg(feature = "optimism")]
pub fn as_optimism_deposited_ref(&self) -> Option<&OptimismDepositedTransactionRequest> {
pub fn as_optimism_deposited_ref(&self) -> Option<&DepositTransaction> {
match self {
OptimismDeposited(tx) => Some(tx),
DepositTransaction(tx) => Some(tx),
_ => None,
}
}
Expand All @@ -548,11 +546,9 @@ impl TypedTransaction {
}
}
#[cfg(feature = "optimism")]
pub fn as_optimism_deposited_mut(
&mut self,
) -> Option<&mut OptimismDepositedTransactionRequest> {
pub fn as_optimism_deposited_mut(&mut self) -> Option<&mut DepositTransaction> {
match self {
OptimismDeposited(tx) => Some(tx),
DepositTransaction(tx) => Some(tx),
_ => None,
}
}
Expand Down Expand Up @@ -608,7 +604,7 @@ impl TypedTransaction {
gateway_fee: None,
},
#[cfg(feature = "optimism")]
OptimismDeposited(tx) => tx.tx,
DepositTransaction(tx) => tx.tx,
}
}
}
Expand Down Expand Up @@ -649,7 +645,7 @@ impl TypedTransaction {
access_list,
},
#[cfg(feature = "optimism")]
OptimismDeposited(tx) => Eip2930TransactionRequest { tx: tx.tx, access_list },
DepositTransaction(tx) => Eip2930TransactionRequest { tx: tx.tx, access_list },
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethers-core/src/types/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod eip2718;
pub mod eip2930;

#[cfg(feature = "optimism")]
pub mod optimism_deposited;
pub mod optimism;

pub mod eip712;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const NUM_TX_FIELDS: usize = 8;

/// An error involving an OptimismDeposited transaction request.
#[derive(Debug, Error)]
pub enum OptimismDepositedRequestError {
pub enum DepositTransactionError {
/// When decoding a transaction request from RLP
#[error(transparent)]
DecodingError(#[from] rlp::DecoderError),
}

/// Parameters for sending a transaction
#[derive(Clone, Default, Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct OptimismDepositedTransactionRequest {
pub struct DepositTransaction {
#[serde(flatten)]
pub tx: TransactionRequest,

Expand All @@ -34,7 +34,7 @@ pub struct OptimismDepositedTransactionRequest {
pub is_system_tx: Option<bool>,
}

impl OptimismDepositedTransactionRequest {
impl DepositTransaction {
pub fn new(
tx: TransactionRequest,
source_hash: Option<H256>,
Expand Down Expand Up @@ -90,9 +90,7 @@ impl OptimismDepositedTransactionRequest {

/// Decodes the given RLP into a transaction
/// Note: this transaction does not have a signature
pub fn decode_signed_rlp(
rlp: &rlp::Rlp,
) -> Result<(Self, Signature), OptimismDepositedRequestError> {
pub fn decode_signed_rlp(rlp: &rlp::Rlp) -> Result<(Self, Signature), DepositTransactionError> {
let mut offset = 0;
let txn = Self::decode_base_rlp(rlp, &mut offset)?;
let sig = Signature { r: 0.into(), s: 0.into(), v: 0 };
Expand All @@ -102,16 +100,16 @@ impl OptimismDepositedTransactionRequest {
}

/// Get a Eip2930TransactionRequest from a rlp encoded byte stream
impl Decodable for OptimismDepositedTransactionRequest {
impl Decodable for DepositTransaction {
fn decode(rlp: &rlp::Rlp) -> Result<Self, rlp::DecoderError> {
Self::decode_base_rlp(rlp, &mut 0)
}
}

/// Get an OptimismDeposited transaction request from a Transaction
impl From<&Transaction> for OptimismDepositedTransactionRequest {
fn from(tx: &Transaction) -> OptimismDepositedTransactionRequest {
OptimismDepositedTransactionRequest {
impl From<&Transaction> for DepositTransaction {
fn from(tx: &Transaction) -> DepositTransaction {
DepositTransaction {
tx: tx.into(),
source_hash: tx.source_hash,
mint: tx.mint,
Expand Down Expand Up @@ -173,7 +171,7 @@ mod test {
let encoded = Bytes::from(hex::decode("7ef90159a0a8157ccf61bcdfbcb74a84ec1262e62644dd1e7e3614abcbd8db0c99a60049fc94deaddeaddeaddeaddeaddeaddeaddeaddead00019442000000000000000000000000000000000000158080830f424080b90104015d8eb90000000000000000000000000000000000000000000000000000000000878c1c00000000000000000000000000000000000000000000000000000000644662bc0000000000000000000000000000000000000000000000000000001ee24fba17b7e19cc10812911dfa8a438e0a81a9933f843aa5b528899b8d9e221b649ae0df00000000000000000000000000000000000000000000000000000000000000060000000000000000000000007431310e026b69bfc676c0013e12a1a11411eec9000000000000000000000000000000000000000000000000000000000000083400000000000000000000000000000000000000000000000000000000000f4240").unwrap());
let tx = TypedTransaction::decode(&rlp::Rlp::new(&encoded)).unwrap();

assert!(matches!(tx, TypedTransaction::OptimismDeposited(_)));
assert!(matches!(tx, TypedTransaction::DepositTransaction(_)));

assert_eq!(tx.gas(), Some(&U256::from(1000000u64)));
assert_eq!(tx.gas_price(), None);
Expand Down
2 changes: 1 addition & 1 deletion ethers-middleware/src/gas_oracle/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
}
}
#[cfg(feature = "optimism")]
TypedTransaction::OptimismDeposited(ref mut inner) => {
TypedTransaction::DepositTransaction(ref mut inner) => {
if inner.tx.gas_price.is_none() {
inner.tx.gas_price = Some(self.get_gas_price().await?);
}
Expand Down
Loading