Skip to content

Commit

Permalink
feat: add eip4844 fields to rpc transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Aug 31, 2023
1 parent b5aa943 commit 35e2d9f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
35 changes: 23 additions & 12 deletions crates/rpc/rpc-types-compat/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn fill(
transaction_index: Option<U256>,
) -> Transaction {
let signer = tx.signer();
let signed_tx = tx.into_signed();
let mut signed_tx = tx.into_signed();

let to = match signed_tx.kind() {
PrimitiveTransactionKind::Create => None,
Expand All @@ -62,7 +62,9 @@ fn fill(
};

let chain_id = signed_tx.chain_id().map(U64::from);
let access_list = match &signed_tx.transaction {
let mut blob_versioned_hashes = Vec::new();

let access_list = match &mut signed_tx.transaction {
PrimitiveTransaction::Legacy(_) => None,
PrimitiveTransaction::Eip2930(tx) => Some(
tx.access_list
Expand All @@ -84,16 +86,21 @@ fn fill(
})
.collect(),
),
PrimitiveTransaction::Eip4844(tx) => Some(
tx.access_list
.0
.iter()
.map(|item| AccessListItem {
address: item.address.0.into(),
storage_keys: item.storage_keys.iter().map(|key| key.0.into()).collect(),
})
.collect(),
),
PrimitiveTransaction::Eip4844(tx) => {
// extract the blob hashes from the transaction
blob_versioned_hashes = std::mem::take(&mut tx.blob_versioned_hashes);

Some(
tx.access_list
.0
.iter()
.map(|item| AccessListItem {
address: item.address.0.into(),
storage_keys: item.storage_keys.iter().map(|key| key.0.into()).collect(),
})
.collect(),
)
}
};

let signature =
Expand All @@ -119,5 +126,9 @@ fn fill(
block_hash,
block_number: block_number.map(U256::from),
transaction_index,

// EIP-4844 fields
max_fee_per_blob_gas: tx.transaction.max_fee_per_blob_gas().map(U128::from),

Check failure on line 131 in crates/rpc/rpc-types-compat/src/transaction/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

borrow of moved value: `tx`

error[E0382]: borrow of moved value: `tx` --> crates/rpc/rpc-types-compat/src/transaction/mod.rs:131:31 | 34 | tx: TransactionSignedEcRecovered, | -- move occurs because `tx` has type `reth_primitives::TransactionSignedEcRecovered`, which does not implement the `Copy` trait ... 41 | let mut signed_tx = tx.into_signed(); | ------------- `tx` moved due to this method call ... 131 | max_fee_per_blob_gas: tx.transaction.max_fee_per_blob_gas().map(U128::from), | ^^^^^^^^^^^^^^ value borrowed here after move | note: `reth_primitives::TransactionSignedEcRecovered::into_signed` takes ownership of the receiver `self`, which moves `tx` --> /home/runner/work/reth/reth/crates/primitives/src/transaction/mod.rs:1106:24 | 1106 | pub fn into_signed(self) -> TransactionSigned { | ^^^^ = note: borrow occurs due to deref coercion to `reth_primitives::TransactionSigned` note: deref defined here --> /home/runner/work/reth/reth/crates/primitives/src/transaction/mod.rs:1087:52 | 1087 | #[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)] | ^^^^^ = note: this error originates in the derive macro `Deref` (in Nightly builds, run with -Z macro-backtrace for more info) help: you can `clone` the value and consume it, but this might not be your desired behavior | 41 | let mut signed_tx = tx.clone().into_signed(); | ++++++++
blob_versioned_hashes,
}
}
10 changes: 10 additions & 0 deletions crates/rpc/rpc-types/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub struct Transaction {
/// The miner's tip.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_priority_fee_per_gas: Option<U128>,
/// Configured max fee per blob gas for eip-4844 transactions
#[serde(skip_serializing_if = "Option::is_none")]
pub max_fee_per_blob_gas: Option<U128>,
/// Data
pub input: Bytes,
/// All _flattened_ fields of the transaction signature.
Expand All @@ -52,6 +55,9 @@ pub struct Transaction {
pub signature: Option<Signature>,
/// The chain id of the transaction, if any.
pub chain_id: Option<U64>,
/// Contains the blob hashes for eip-4844 transactions.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub blob_versioned_hashes: Vec<H256>,
/// EIP2930
///
/// Pre-pay to warm storage access.
Expand Down Expand Up @@ -91,10 +97,12 @@ mod tests {
y_parity: None,
}),
chain_id: Some(U64::from(17)),
blob_versioned_hashes: vec![],
access_list: None,
transaction_type: Some(U64::from(20)),
max_fee_per_gas: Some(U128::from(21)),
max_priority_fee_per_gas: Some(U128::from(22)),
max_fee_per_blob_gas: None,
};
let serialized = serde_json::to_string(&transaction).unwrap();
assert_eq!(
Expand Down Expand Up @@ -126,10 +134,12 @@ mod tests {
y_parity: Some(Parity(true)),
}),
chain_id: Some(U64::from(17)),
blob_versioned_hashes: vec![],
access_list: None,
transaction_type: Some(U64::from(20)),
max_fee_per_gas: Some(U128::from(21)),
max_priority_fee_per_gas: Some(U128::from(22)),
max_fee_per_blob_gas: None,
};
let serialized = serde_json::to_string(&transaction).unwrap();
assert_eq!(
Expand Down

0 comments on commit 35e2d9f

Please sign in to comment.