Skip to content

Commit

Permalink
optimism feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin committed Jun 19, 2024
1 parent 1659563 commit f1037c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions examples/exex/remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ reth-exex-test-utils.workspace = true

tokio.workspace = true

[features]
default = []
optimism = ["reth/optimism"]

[[bin]]
name = "exex"
path = "bin/exex.rs"
Expand Down
42 changes: 27 additions & 15 deletions examples/exex/remote/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ impl From<&reth::primitives::Header> for proto::Header {
}
}

impl From<&reth::primitives::TransactionSigned> for proto::Transaction {
fn from(transaction: &reth::primitives::TransactionSigned) -> Self {
impl TryFrom<&reth::primitives::TransactionSigned> for proto::Transaction {
type Error = Error;

fn try_from(transaction: &reth::primitives::TransactionSigned) -> Result<Self, Self::Error> {
let hash = transaction.hash().to_vec();
let signature = proto::Signature {
r: transaction.signature.r.to_le_bytes_vec(),
Expand Down Expand Up @@ -218,9 +220,11 @@ impl From<&reth::primitives::TransactionSigned> for proto::Transaction {
max_fee_per_blob_gas: max_fee_per_blob_gas.to_le_bytes().to_vec(),
input: input.to_vec(),
}),
#[cfg(feature = "optimism")]
reth::primitives::Transaction::Deposit(_) => eyre::bail!("deposit transaction not supported"),
};

proto::Transaction { hash, signature: Some(signature), transaction: Some(transaction) }
Ok(proto::Transaction { hash, signature: Some(signature), transaction: Some(transaction) })
}
}

Expand Down Expand Up @@ -305,7 +309,7 @@ impl TryFrom<&reth::revm::primitives::Bytecode> for proto::Bytecode {
})
}
reth::revm::primitives::Bytecode::Eof(_) => {
return Err(eyre::eyre!("EOF bytecode not supported"))
eyre::bail!("EOF bytecode not supported");
}
};
Ok(proto::Bytecode { bytecode: Some(bytecode) })
Expand Down Expand Up @@ -377,24 +381,30 @@ impl TryFrom<(Address, &reth::revm::db::states::reverts::AccountRevert)> for pro
}
}

impl From<&Option<reth::primitives::Receipt>> for proto::Receipt {
fn from(receipt: &Option<reth::primitives::Receipt>) -> Self {
proto::Receipt {
receipt: Some(receipt.as_ref().map_or(proto::receipt::Receipt::Empty(()), |receipt| {
proto::receipt::Receipt::NonEmpty(receipt.into())
})),
}
impl TryFrom<&Option<reth::primitives::Receipt>> for proto::Receipt {
type Error = eyre::Error;

fn try_from(receipt: &Option<reth::primitives::Receipt>) -> Result<Self, Self::Error> {
Ok(proto::Receipt {
receipt: Some(receipt.as_ref().map_or(eyre::Ok(proto::receipt::Receipt::Empty(())), |receipt| {
Ok(proto::receipt::Receipt::NonEmpty(receipt.try_into()?))
})?),
})
}
}

impl From<&reth::primitives::Receipt> for proto::NonEmptyReceipt {
fn from(receipt: &reth::primitives::Receipt) -> Self {
proto::NonEmptyReceipt {
impl TryFrom<&reth::primitives::Receipt> for proto::NonEmptyReceipt {
type Error = eyre::Error;

fn try_from(receipt: &reth::primitives::Receipt) -> Result<Self, Self::Error> {
Ok(proto::NonEmptyReceipt {
tx_type: match receipt.tx_type {
reth::primitives::TxType::Legacy => proto::TxType::Legacy,
reth::primitives::TxType::Eip2930 => proto::TxType::Eip2930,
reth::primitives::TxType::Eip1559 => proto::TxType::Eip1559,
reth::primitives::TxType::Eip4844 => proto::TxType::Eip4844,
#[cfg(feature = "optimism")]
reth::primitives::TxType::Deposit => eyre::bail!("deposit transaction not supported"),
} as i32,
success: receipt.success,
cumulative_gas_used: receipt.cumulative_gas_used,
Expand All @@ -409,7 +419,7 @@ impl From<&reth::primitives::Receipt> for proto::NonEmptyReceipt {
}),
})
.collect(),
}
})
}
}

Expand Down Expand Up @@ -924,6 +934,8 @@ impl TryFrom<&proto::NonEmptyReceipt> for reth::primitives::Receipt {
})
})
.collect::<eyre::Result<_>>()?,
#[cfg(feature = "optimism")]
..Default::default()
})
}
}

0 comments on commit f1037c3

Please sign in to comment.