From 35e2d9f2a9e92178c42e2e8e36d27e631c71a69d Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 30 Aug 2023 17:17:50 -0700 Subject: [PATCH] feat: add eip4844 fields to rpc transaction --- .../rpc-types-compat/src/transaction/mod.rs | 35 ++++++++++++------- .../rpc/rpc-types/src/eth/transaction/mod.rs | 10 ++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/rpc/rpc-types-compat/src/transaction/mod.rs b/crates/rpc/rpc-types-compat/src/transaction/mod.rs index 9cda539ef1b2d..b71dae00db908 100644 --- a/crates/rpc/rpc-types-compat/src/transaction/mod.rs +++ b/crates/rpc/rpc-types-compat/src/transaction/mod.rs @@ -38,7 +38,7 @@ fn fill( transaction_index: Option, ) -> 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, @@ -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 @@ -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 = @@ -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), + blob_versioned_hashes, } } diff --git a/crates/rpc/rpc-types/src/eth/transaction/mod.rs b/crates/rpc/rpc-types/src/eth/transaction/mod.rs index 6b6601af62a53..b2effca69e71b 100644 --- a/crates/rpc/rpc-types/src/eth/transaction/mod.rs +++ b/crates/rpc/rpc-types/src/eth/transaction/mod.rs @@ -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, + /// Configured max fee per blob gas for eip-4844 transactions + #[serde(skip_serializing_if = "Option::is_none")] + pub max_fee_per_blob_gas: Option, /// Data pub input: Bytes, /// All _flattened_ fields of the transaction signature. @@ -52,6 +55,9 @@ pub struct Transaction { pub signature: Option, /// The chain id of the transaction, if any. pub chain_id: Option, + /// Contains the blob hashes for eip-4844 transactions. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub blob_versioned_hashes: Vec, /// EIP2930 /// /// Pre-pay to warm storage access. @@ -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!( @@ -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!(