feat: add eip4844 fields to rpc transaction (#4422)

This commit is contained in:
Matthias Seitz
2023-08-30 17:30:45 -07:00
committed by GitHub
parent 893f4cf2a2
commit 3d9e968b03
2 changed files with 33 additions and 12 deletions

View File

@ -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,
@ -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: signed_tx.max_fee_per_blob_gas().map(U128::from),
blob_versioned_hashes,
}
}

View File

@ -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.
@ -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.
@ -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!(