Skip to content

Commit

Permalink
Reintroduce data() on TxEssence
Browse files Browse the repository at this point in the history
  • Loading branch information
intoverflow committed Nov 20, 2023
1 parent 2290e8b commit daea808
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions primitives/src/transactions/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion primitives/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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].
Expand Down
7 changes: 7 additions & 0 deletions primitives/src/transactions/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit daea808

Please sign in to comment.