Skip to content

Commit

Permalink
fix: add back transaction type (alloy-rs#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and ben186 committed Jul 27, 2024
1 parent df410db commit 6ad93fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl Transaction {
nonce: Some(self.nonce),
chain_id: self.chain_id,
access_list: self.access_list,
transaction_type: self.transaction_type,
max_fee_per_gas: self.max_fee_per_gas,
max_priority_fee_per_gas: self.max_priority_fee_per_gas,
max_fee_per_blob_gas: self.max_fee_per_blob_gas,
Expand Down
15 changes: 15 additions & 0 deletions crates/rpc-types/src/eth/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub struct TransactionRequest {
/// An EIP-2930 access list, which lowers cost for accessing accounts and storages in the list. See [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) for more information.
#[serde(default)]
pub access_list: Option<AccessList>,
/// The EIP-2718 transaction type. See [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) for more information.
#[serde(default, rename = "type", with = "alloy_serde::num::u8_hex_opt")]
pub transaction_type: Option<u8>,
/// Blob versioned hashes for EIP-4844 transactions.
#[serde(skip_serializing_if = "Option::is_none")]
pub blob_versioned_hashes: Option<Vec<B256>>,
Expand All @@ -84,6 +87,7 @@ impl Hash for TransactionRequest {
self.nonce.hash(state);
self.chain_id.hash(state);
self.access_list.hash(state);
self.transaction_type.hash(state);
self.blob_versioned_hashes.hash(state);
self.sidecar.hash(state);
}
Expand All @@ -99,6 +103,12 @@ impl TransactionRequest {
self
}

/// Sets the transactions type for the transactions.
pub const fn transaction_type(mut self, transaction_type: u8) -> Self {
self.transaction_type = Some(transaction_type);
self
}

/// Sets the gas limit for the transaction.
pub const fn gas_limit(mut self, gas_limit: u128) -> Self {
self.gas = Some(gas_limit);
Expand Down Expand Up @@ -579,6 +589,7 @@ impl From<TxLegacy> for TransactionRequest {
input: TransactionInput::from(tx.input),
nonce: Some(tx.nonce),
chain_id: tx.chain_id,
transaction_type: Some(0),
..Default::default()
}
}
Expand All @@ -596,6 +607,7 @@ impl From<TxEip2930> for TransactionRequest {
nonce: Some(tx.nonce),
chain_id: Some(tx.chain_id),
access_list: Some(tx.access_list),
transaction_type: Some(1),
..Default::default()
}
}
Expand All @@ -614,6 +626,7 @@ impl From<TxEip1559> for TransactionRequest {
nonce: Some(tx.nonce),
chain_id: Some(tx.chain_id),
access_list: Some(tx.access_list),
transaction_type: Some(2),
..Default::default()
}
}
Expand All @@ -634,6 +647,7 @@ impl From<TxEip4844> for TransactionRequest {
chain_id: Some(tx.chain_id),
access_list: Some(tx.access_list),
blob_versioned_hashes: Some(tx.blob_versioned_hashes),
transaction_type: Some(3),
..Default::default()
}
}
Expand All @@ -657,6 +671,7 @@ impl From<TxEip4844WithSidecar> for TransactionRequest {
access_list: Some(tx.access_list),
blob_versioned_hashes: Some(tx.blob_versioned_hashes),
sidecar: Some(sidecar),
transaction_type: Some(3),
..Default::default()
}
}
Expand Down

0 comments on commit 6ad93fb

Please sign in to comment.