mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: simplify optimism tx compat (#8925)
This commit is contained in:
@ -182,30 +182,27 @@ impl TryFrom<alloy_rpc_types::Transaction> for Transaction {
|
||||
}))
|
||||
}
|
||||
#[cfg(feature = "optimism")]
|
||||
Some(TxType::Deposit) => Ok(Self::Deposit(crate::transaction::TxDeposit {
|
||||
source_hash: tx
|
||||
Some(TxType::Deposit) => {
|
||||
let fields = tx
|
||||
.other
|
||||
.get_deserialized::<String>("sourceHash")
|
||||
.ok_or_else(|| ConversionError::Custom("MissingSourceHash".to_string()))?
|
||||
.map_err(|_| ConversionError::Custom("MissingSourceHash".to_string()))?
|
||||
.parse()
|
||||
.map_err(|_| ConversionError::Custom("InvalidSourceHash".to_string()))?,
|
||||
from: tx.from,
|
||||
to: TxKind::from(tx.to),
|
||||
mint: Option::transpose(
|
||||
tx.other.get_deserialized::<alloy_primitives::U128>("mint"),
|
||||
)
|
||||
.map_err(|_| ConversionError::Custom("MissingMintValue".to_string()))?
|
||||
.map(|num| num.to::<u128>())
|
||||
.filter(|num| *num > 0),
|
||||
value: tx.value,
|
||||
gas_limit: tx
|
||||
.gas
|
||||
.try_into()
|
||||
.map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?,
|
||||
is_system_transaction: tx.from == crate::constants::OP_SYSTEM_TX_FROM_ADDR,
|
||||
input: tx.input,
|
||||
})),
|
||||
.deserialize_into::<alloy_rpc_types::optimism::OptimismTransactionFields>()
|
||||
.map_err(|e| ConversionError::Custom(e.to_string()))?;
|
||||
Ok(Self::Deposit(crate::transaction::TxDeposit {
|
||||
source_hash: fields
|
||||
.source_hash
|
||||
.ok_or_else(|| ConversionError::Custom("MissingSourceHash".to_string()))?,
|
||||
from: tx.from,
|
||||
to: TxKind::from(tx.to),
|
||||
mint: fields.mint.map(|n| n.to::<u128>()).filter(|n| *n != 0),
|
||||
value: tx.value,
|
||||
gas_limit: tx
|
||||
.gas
|
||||
.try_into()
|
||||
.map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?,
|
||||
is_system_transaction: fields.is_system_tx.unwrap_or(false),
|
||||
input: tx.input,
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -272,6 +269,7 @@ impl TryFrom<alloy_rpc_types::Signature> for Signature {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "optimism")]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use alloy_primitives::{B256, U256};
|
||||
@ -279,7 +277,6 @@ mod tests {
|
||||
use revm_primitives::{address, Address};
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "optimism")]
|
||||
fn optimism_deposit_tx_conversion_no_mint() {
|
||||
let input = r#"{
|
||||
"blockHash": "0xef664d656f841b5ad6a2b527b963f1eb48b97d7889d742f6cbff6950388e24cd",
|
||||
@ -330,7 +327,6 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "optimism")]
|
||||
fn optimism_deposit_tx_conversion_mint() {
|
||||
let input = r#"{
|
||||
"blockHash": "0x7194f63b105e93fb1a27c50d23d62e422d4185a68536c55c96284911415699b2",
|
||||
|
||||
@ -256,7 +256,7 @@ impl BlockWithSenders {
|
||||
/// Sealed Ethereum full block.
|
||||
///
|
||||
/// Withdrawals can be optionally included at the end of the RLP encoded message.
|
||||
#[derive_arbitrary(rlp)]
|
||||
#[derive_arbitrary(rlp 32)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
|
||||
@ -47,10 +47,10 @@ pub fn maybe_generate_tests(args: TokenStream, ast: &DeriveInput) -> TokenStream
|
||||
|
||||
#[test]
|
||||
fn malformed_rlp_header_check() {
|
||||
use rand::RngCore;
|
||||
use rand::RngCore;
|
||||
|
||||
// get random instance of type
|
||||
let mut raw = [0u8;1024];
|
||||
let mut raw = [0u8; 1024];
|
||||
rand::thread_rng().fill_bytes(&mut raw);
|
||||
let mut unstructured = arbitrary::Unstructured::new(&raw[..]);
|
||||
let val = <super::#type_ident as arbitrary::Arbitrary>::arbitrary(&mut unstructured);
|
||||
@ -72,7 +72,6 @@ pub fn maybe_generate_tests(args: TokenStream, ast: &DeriveInput) -> TokenStream
|
||||
let res = super::#type_ident::decode(&mut b.as_ref());
|
||||
assert!(res.is_err(), "malformed header was decoded");
|
||||
}
|
||||
|
||||
});
|
||||
} else if let Ok(num) = arg.to_string().parse() {
|
||||
default_cases = num;
|
||||
|
||||
Reference in New Issue
Block a user