diff --git a/primitives/src/transactions/ethereum.rs b/primitives/src/transactions/ethereum.rs index 49cbf994..b48d0dbd 100644 --- a/primitives/src/transactions/ethereum.rs +++ b/primitives/src/transactions/ethereum.rs @@ -445,6 +445,14 @@ impl TxEssence for EthereumTxEssence { EthereumTxEssence::Eip1559(tx) => tx._alloy_rlp_payload_length(), } } + /// Returns a reference to the transaction's call data + fn data(&self) -> &Bytes { + match self { + EthereumTxEssence::Legacy(tx) => &tx.data, + EthereumTxEssence::Eip2930(tx) => &tx.data, + EthereumTxEssence::Eip1559(tx) => &tx.data, + } + } } #[cfg(test)] diff --git a/primitives/src/transactions/mod.rs b/primitives/src/transactions/mod.rs index 18c5565b..c1aafb93 100644 --- a/primitives/src/transactions/mod.rs +++ b/primitives/src/transactions/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use alloy_primitives::{Address, TxHash}; +use alloy_primitives::{Address, Bytes, TxHash}; use alloy_rlp::Encodable; use serde::{Deserialize, Serialize}; @@ -70,6 +70,8 @@ pub trait TxEssence: Encodable + Clone { /// This method calculates the combined length of all the individual fields /// of the transaction when they are RLP-encoded. fn payload_length(&self) -> usize; + /// Returns a reference to the transaction's call data + fn data(&self) -> &Bytes; } /// Provides RLP encoding functionality for [Transaction]. diff --git a/primitives/src/transactions/optimism.rs b/primitives/src/transactions/optimism.rs index b1ba4bbd..be266b38 100644 --- a/primitives/src/transactions/optimism.rs +++ b/primitives/src/transactions/optimism.rs @@ -119,6 +119,13 @@ impl TxEssence for OptimismTxEssence { OptimismTxEssence::OptimismDeposited(op) => op._alloy_rlp_payload_length(), } } + /// Returns a reference to the transaction's call data + fn data(&self) -> &Bytes { + match self { + OptimismTxEssence::Ethereum(eth) => eth.data(), + OptimismTxEssence::OptimismDeposited(op) => &op.data, + } + } } #[cfg(test)]