primitives: rm redundant chain_id function for Transaction (#11751)

This commit is contained in:
Thomas Coratger
2024-10-15 17:27:26 +02:00
committed by GitHub
parent 6fb271036d
commit 5aceb3e11e
9 changed files with 15 additions and 20 deletions

1
Cargo.lock generated
View File

@ -8835,6 +8835,7 @@ dependencies = [
name = "reth-rpc-types-compat" name = "reth-rpc-types-compat"
version = "1.1.0" version = "1.1.0"
dependencies = [ dependencies = [
"alloy-consensus",
"alloy-eips", "alloy-eips",
"alloy-primitives", "alloy-primitives",
"alloy-rlp", "alloy-rlp",

View File

@ -5,7 +5,7 @@ use crate::{
Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxType, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxType,
}; };
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use alloy_consensus::{TxEip1559, TxEip2930, TxEip4844, TxLegacy}; use alloy_consensus::{Transaction as _, TxEip1559, TxEip2930, TxEip4844, TxLegacy};
use alloy_primitives::{Parity, TxKind}; use alloy_primitives::{Parity, TxKind};
use alloy_rlp::Error as RlpError; use alloy_rlp::Error as RlpError;
use alloy_serde::WithOtherFields; use alloy_serde::WithOtherFields;

View File

@ -4,7 +4,10 @@ use crate::BlockHashOrNumber;
use alloy_eips::eip7702::SignedAuthorization; use alloy_eips::eip7702::SignedAuthorization;
use alloy_primitives::{keccak256, Address, ChainId, TxKind, B256, U256}; use alloy_primitives::{keccak256, Address, ChainId, TxKind, B256, U256};
use alloy_consensus::{SignableTransaction, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy}; use alloy_consensus::{
SignableTransaction, Transaction as AlloyTransaction, TxEip1559, TxEip2930, TxEip4844,
TxEip7702, TxLegacy,
};
use alloy_eips::{ use alloy_eips::{
eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718}, eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718},
eip2930::AccessList, eip2930::AccessList,
@ -197,19 +200,6 @@ impl Transaction {
} }
} }
/// Get `chain_id`.
pub const fn chain_id(&self) -> Option<u64> {
match self {
Self::Legacy(TxLegacy { chain_id, .. }) => *chain_id,
Self::Eip2930(TxEip2930 { chain_id, .. }) |
Self::Eip1559(TxEip1559 { chain_id, .. }) |
Self::Eip4844(TxEip4844 { chain_id, .. }) |
Self::Eip7702(TxEip7702 { chain_id, .. }) => Some(*chain_id),
#[cfg(feature = "optimism")]
Self::Deposit(_) => None,
}
}
/// Sets the transaction's chain id to the provided value. /// Sets the transaction's chain id to the provided value.
pub fn set_chain_id(&mut self, chain_id: u64) { pub fn set_chain_id(&mut self, chain_id: u64) {
match self { match self {
@ -824,7 +814,7 @@ impl Encodable for Transaction {
} }
} }
impl alloy_consensus::Transaction for Transaction { impl AlloyTransaction for Transaction {
fn chain_id(&self) -> Option<ChainId> { fn chain_id(&self) -> Option<ChainId> {
match self { match self {
Self::Legacy(tx) => tx.chain_id(), Self::Legacy(tx) => tx.chain_id(),
@ -1974,6 +1964,7 @@ mod tests {
transaction::{signature::Signature, TxEip1559, TxKind, TxLegacy}, transaction::{signature::Signature, TxEip1559, TxKind, TxLegacy},
Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
}; };
use alloy_consensus::Transaction as _;
use alloy_eips::eip2718::{Decodable2718, Encodable2718}; use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{address, b256, bytes, hex, Address, Bytes, Parity, B256, U256}; use alloy_primitives::{address, b256, bytes, hex, Address, Bytes, Parity, B256, U256};
use alloy_rlp::{Decodable, Encodable, Error as RlpError}; use alloy_rlp::{Decodable, Encodable, Error as RlpError};

View File

@ -24,6 +24,7 @@ alloy-rpc-types.workspace = true
alloy-rpc-types-eth = { workspace = true, default-features = false, features = ["serde"] } alloy-rpc-types-eth = { workspace = true, default-features = false, features = ["serde"] }
alloy-serde.workspace = true alloy-serde.workspace = true
alloy-rpc-types-engine.workspace = true alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true
[dev-dependencies] [dev-dependencies]
serde_json.workspace = true serde_json.workspace = true

View File

@ -4,6 +4,7 @@ mod signature;
pub use signature::*; pub use signature::*;
use std::fmt; use std::fmt;
use alloy_consensus::Transaction as _;
use alloy_rpc_types::{ use alloy_rpc_types::{
request::{TransactionInput, TransactionRequest}, request::{TransactionInput, TransactionRequest},
Transaction, TransactionInfo, Transaction, TransactionInfo,

View File

@ -1,5 +1,6 @@
//! L1 `eth` API types. //! L1 `eth` API types.
use alloy_consensus::Transaction as _;
use alloy_network::{AnyNetwork, Network}; use alloy_network::{AnyNetwork, Network};
use alloy_primitives::{Address, TxKind}; use alloy_primitives::{Address, TxKind};
use alloy_rpc_types::{Transaction, TransactionInfo}; use alloy_rpc_types::{Transaction, TransactionInfo};

View File

@ -27,6 +27,7 @@ revm.workspace = true
alloy-eips.workspace = true alloy-eips.workspace = true
alloy-primitives.workspace = true alloy-primitives.workspace = true
alloy-rlp.workspace = true alloy-rlp.workspace = true
alloy-consensus.workspace = true
# async/futures # async/futures
futures-util.workspace = true futures-util.workspace = true
@ -54,7 +55,6 @@ rand = { workspace = true, optional = true }
paste = { workspace = true, optional = true } paste = { workspace = true, optional = true }
proptest = { workspace = true, optional = true } proptest = { workspace = true, optional = true }
proptest-arbitrary-interop = { workspace = true, optional = true } proptest-arbitrary-interop = { workspace = true, optional = true }
alloy-consensus = { workspace = true, optional = true }
[dev-dependencies] [dev-dependencies]
reth-primitives = { workspace = true, features = ["arbitrary"] } reth-primitives = { workspace = true, features = ["arbitrary"] }
@ -69,12 +69,11 @@ pprof = { workspace = true, features = ["criterion", "flamegraph"] }
assert_matches.workspace = true assert_matches.workspace = true
tempfile.workspace = true tempfile.workspace = true
serde_json.workspace = true serde_json.workspace = true
alloy-consensus.workspace = true
[features] [features]
default = ["serde"] default = ["serde"]
serde = ["dep:serde"] serde = ["dep:serde"]
test-utils = ["rand", "paste", "serde", "alloy-consensus"] test-utils = ["rand", "paste", "serde"]
arbitrary = ["proptest", "reth-primitives/arbitrary", "proptest-arbitrary-interop"] arbitrary = ["proptest", "reth-primitives/arbitrary", "proptest-arbitrary-interop"]
[[bench]] [[bench]]

View File

@ -7,6 +7,7 @@ use crate::{
validate::ValidPoolTransaction, validate::ValidPoolTransaction,
AllTransactionsEvents, AllTransactionsEvents,
}; };
use alloy_consensus::Transaction as _;
use alloy_eips::{eip2718::Encodable2718, eip2930::AccessList, eip4844::BlobAndProofV1}; use alloy_eips::{eip2718::Encodable2718, eip2930::AccessList, eip4844::BlobAndProofV1};
use alloy_primitives::{Address, TxHash, TxKind, B256, U256}; use alloy_primitives::{Address, TxHash, TxKind, B256, U256};
use futures_util::{ready, Stream}; use futures_util::{ready, Stream};

View File

@ -1,6 +1,6 @@
//! Generators for different data structures like block headers, block bodies and ranges of those. //! Generators for different data structures like block headers, block bodies and ranges of those.
use alloy_consensus::TxLegacy; use alloy_consensus::{Transaction as _, TxLegacy};
use alloy_eips::{ use alloy_eips::{
eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest, eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest,
}; };