Skip to content

Commit

Permalink
chore: cleanup workspace imports
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 29, 2024
1 parent e307f18 commit fea14c0
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 23 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ alloy-rlp = { version = "0.3", default-features = false }
alloy-sol-types = { version = "0.8", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }

# Revm
revm = "17.1.0"

# Serde
serde_repr = "0.1"
serde = { version = "1.0", default-features = false, features = [
"derive",
"alloc",
] }
serde_with = "3.11"
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# Encoding
snap = "1.1.1"
bincode = "1.3.3"
ethereum_ssz = "0.8"

# rpc
Expand All @@ -85,8 +90,8 @@ jsonrpsee-core = "0.24"
jsonrpsee-types = "0.24"

# misc
async-trait = "0.1.83"
cfg-if = "1"
async-trait = "0.1.83"
spin = { version = "0.9.8", features = ["mutex"] }
derive_more = { version = "1.0", default-features = false }

Expand All @@ -98,6 +103,7 @@ thiserror = "1.0"
proptest = "1.5"
proptest-derive = "0.5"
tokio = "1"
rstest = "0.23.0"

## crypto
c-kzg = { version = "1.0", default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ alloy-primitives = { workspace = true, features = ["rlp"] }
arbitrary = { workspace = true, features = ["derive"], optional = true }

# serde
serde_with = { workspace = true, optional = true }
alloy-serde = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_with = { version = "3.9", optional = true }

# misc
spin.workspace = true
derive_more = { workspace = true, features = ["display"] }

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["rand"] }
alloy-signer.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
bincode = "1.3"
rand.workspace = true
bincode.workspace = true
serde_json.workspace = true
alloy-signer.workspace = true
tokio = { workspace = true, features = ["macros"] }
arbitrary = { workspace = true, features = ["derive"] }
alloy-primitives = { workspace = true, features = ["rand"] }

[features]
default = ["std"]
Expand Down
67 changes: 66 additions & 1 deletion crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Receipt envelope types for Optimism.

use crate::{OpDepositReceipt, OpDepositReceiptWithBloom, OpTxType};
use alloc::vec::Vec;
use alloy_consensus::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt};
use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718};
use alloy_primitives::{Bloom, Log};
use alloy_primitives::{logs_bloom, Bloom, Log};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};

/// Receipt envelope, as defined in [EIP-2718], modified for OP Stack chains.
Expand Down Expand Up @@ -46,6 +47,48 @@ pub enum OpReceiptEnvelope<T = Log> {
Deposit(OpDepositReceiptWithBloom<T>),
}

impl OpReceiptEnvelope<Log> {
/// Creates a new [`OpReceiptEnvelope`] from the given parts.
pub fn from_parts<'a>(
status: bool,
cumulative_gas_used: u128,
logs: impl IntoIterator<Item = &'a Log>,
tx_type: OpTxType,
deposit_nonce: Option<u64>,
deposit_receipt_version: Option<u64>,
) -> Self {
let logs = logs.into_iter().cloned().collect::<Vec<_>>();
let logs_bloom = logs_bloom(&logs);
let inner_receipt =
Receipt { status: Eip658Value::Eip658(status), cumulative_gas_used, logs };
match tx_type {
OpTxType::Legacy => {
Self::Legacy(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip2930 => {
Self::Eip2930(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip1559 => {
Self::Eip1559(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Eip7702 => {
Self::Eip7702(ReceiptWithBloom { receipt: inner_receipt, logs_bloom })
}
OpTxType::Deposit => {
let inner = OpDepositReceiptWithBloom {
receipt: OpDepositReceipt {
inner: inner_receipt,
deposit_nonce,
deposit_receipt_version,
},
logs_bloom,
};
Self::Deposit(inner)
}
}
}
}

impl<T> OpReceiptEnvelope<T> {
/// Return the [`OpTxType`] of the inner receipt.
pub const fn tx_type(&self) -> OpTxType {
Expand Down Expand Up @@ -307,4 +350,26 @@ mod tests {
assert_eq!(receipt.length(), expected.len());
assert_eq!(data, expected);
}

#[test]
fn legacy_receipt_from_parts() {
let receipt =
OpReceiptEnvelope::from_parts(true, 100, vec![], OpTxType::Legacy, None, None);
assert!(receipt.status());
assert_eq!(receipt.cumulative_gas_used(), 100);
assert_eq!(receipt.logs().len(), 0);
assert_eq!(receipt.tx_type(), OpTxType::Legacy);
}

#[test]
fn deposit_receipt_from_parts() {
let receipt =
OpReceiptEnvelope::from_parts(true, 100, vec![], OpTxType::Deposit, Some(1), Some(2));
assert!(receipt.status());
assert_eq!(receipt.cumulative_gas_used(), 100);
assert_eq!(receipt.logs().len(), 0);
assert_eq!(receipt.tx_type(), OpTxType::Deposit);
assert_eq!(receipt.deposit_nonce(), Some(1));
assert_eq!(receipt.deposit_receipt_version(), Some(2));
}
}
6 changes: 3 additions & 3 deletions crates/genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ serde = { workspace = true, optional = true }
serde_repr = { workspace = true, optional = true }

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["rand"] }
arbitrary = { workspace = true, features = ["derive"] }
serde_json.workspace = true
rand.workspace = true
serde_json.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
alloy-primitives = { workspace = true, features = ["rand"] }

[features]
default = ["serde", "std"]
Expand Down
7 changes: 4 additions & 3 deletions crates/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ serde = { workspace = true, optional = true }
alloy-serde = { workspace = true, optional = true }

[dev-dependencies]
arbitrary = { workspace = true, features = ["derive"] }
revm.workspace = true
rand.workspace = true
rstest.workspace = true
proptest.workspace = true
serde_json.workspace = true
rstest = "0.22.0"
revm = "14.0.2"
alloy-sol-types.workspace = true
arbitrary = { workspace = true, features = ["derive"] }

[features]
default = ["serde", "std"]
Expand Down
Loading

0 comments on commit fea14c0

Please sign in to comment.