Skip to content

Commit ae8295e

Browse files
committed
chain/ethereum: Populate new Firehose protobuf fields in codec
1 parent 13fb573 commit ae8295e

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

chain/ethereum/src/codec.rs

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ impl<'a> TryInto<Transaction> for TransactionTraceAt<'a> {
291291
format_err!("EIP-4844 transactions cannot be contract creation transactions. The 'to' field must contain a valid address.")
292292
})?;
293293

294+
let blob_versioned_hashes: Vec<B256> = self
295+
.trace
296+
.blob_hashes
297+
.iter()
298+
.map(|hash| B256::from_slice(hash))
299+
.collect();
300+
301+
let max_fee_per_blob_gas_u128 = self
302+
.trace
303+
.blob_gas_fee_cap
304+
.as_ref()
305+
.map_or(0u128, |x| {
306+
let val: U256 = x.into();
307+
val.to::<u128>()
308+
});
309+
294310
let tx_eip4844 = TxEip4844 {
295311
chain_id: 0, // TODO(alloy_migration): extract actual chain_id from trace (0 = placeholder)
296312
nonce,
@@ -300,8 +316,8 @@ impl<'a> TryInto<Transaction> for TransactionTraceAt<'a> {
300316
to: to_address,
301317
value,
302318
access_list: access_list.clone(), // Use actual access list from trace
303-
blob_versioned_hashes: Vec::new(), // TODO(alloy_migration): blob hashes not available in current protobuf definition
304-
max_fee_per_blob_gas: 0u128, // TODO(alloy_migration): blob gas fee not available in current protobuf definition
319+
blob_versioned_hashes,
320+
max_fee_per_blob_gas: max_fee_per_blob_gas_u128,
305321
input: input.clone(),
306322
};
307323
let tx = TxEip4844Variant::TxEip4844(tx_eip4844);
@@ -317,6 +333,13 @@ impl<'a> TryInto<Transaction> for TransactionTraceAt<'a> {
317333
format_err!("EIP-7702 transactions cannot be contract creation transactions. The 'to' field must contain a valid address.")
318334
})?;
319335

336+
// Convert set_code_authorizations to alloy authorization list
337+
// Note: Alloy's SignedAuthorization expects the full authorization data
338+
// For now, we'll leave this empty as converting the protobuf SetCodeAuthorization
339+
// to alloy's SignedAuthorization requires signature reconstruction which is complex.
340+
// The authorization data is available in self.trace.set_code_authorizations if needed.
341+
let authorization_list = Vec::new(); // TODO(alloy_migration): Complex conversion from SetCodeAuthorization to alloy::consensus::SignedAuthorization
342+
320343
let tx = TxEip7702 {
321344
chain_id: 0, // TODO(alloy_migration): extract actual chain_id from trace (0 = placeholder)
322345
nonce,
@@ -326,7 +349,7 @@ impl<'a> TryInto<Transaction> for TransactionTraceAt<'a> {
326349
to: to_address,
327350
value,
328351
access_list: access_list.clone(), // Use actual access list from trace
329-
authorization_list: Vec::new(), // TODO(alloy_migration): authorization list not available in current protobuf definition
352+
authorization_list,
330353
input: input.clone(),
331354
};
332355
let signed_tx = Signed::new_unchecked(
@@ -396,17 +419,33 @@ impl TryInto<AlloyBlock> for &Block {
396419
mix_hash: header.mix_hash.try_decode_proto("mix hash")?,
397420
nonce: header.nonce.into(),
398421

399-
withdrawals_root: None, // TODO(alloy_migration): not available in current protobuf definition
400-
blob_gas_used: None, // TODO(alloy_migration): not available in current protobuf definition
401-
excess_blob_gas: None, // TODO(alloy_migration): not available in current protobuf definition
402-
parent_beacon_block_root: None, // TODO(alloy_migration): not available in current protobuf definition
403-
requests_hash: None, // TODO(alloy_migration): not available in current protobuf definition
422+
withdrawals_root: if header.withdrawals_root.is_empty() {
423+
None
424+
} else {
425+
Some(header.withdrawals_root.try_decode_proto("withdrawals root")?)
426+
},
427+
blob_gas_used: header.blob_gas_used,
428+
excess_blob_gas: header.excess_blob_gas,
429+
parent_beacon_block_root: if header.parent_beacon_root.is_empty() {
430+
None
431+
} else {
432+
Some(header.parent_beacon_root.try_decode_proto("parent beacon root")?)
433+
},
434+
requests_hash: if header.requests_hash.is_empty() {
435+
None
436+
} else {
437+
Some(header.requests_hash.try_decode_proto("requests hash")?)
438+
}
404439
};
405440

406441
let rpc_header = alloy::rpc::types::Header {
407442
hash: block_hash,
408443
inner: consensus_header,
409-
total_difficulty: header.total_difficulty.as_ref().map(|v| v.into()),
444+
total_difficulty: {
445+
#[allow(deprecated)]
446+
let total_difficulty = &header.total_difficulty;
447+
total_difficulty.as_ref().map(|v| v.into())
448+
},
410449
size: Some(U256::from(self.size)),
411450
};
412451

@@ -577,8 +616,11 @@ fn transaction_trace_to_alloy_txn_reciept(
577616
let val: U256 = x.into();
578617
val.to::<u128>()
579618
}), // gas_price already contains effective gas price per protobuf spec
580-
blob_gas_used: None, // TODO(alloy_migration): blob gas used not available in current protobuf definition
581-
blob_gas_price: None, // TODO(alloy_migration): blob gas price not available in current protobuf definition
619+
blob_gas_used: r.blob_gas_used,
620+
blob_gas_price: r.blob_gas_price.as_ref().map(|x| {
621+
let val: U256 = x.into();
622+
val.to::<u128>()
623+
}),
582624
inner: envelope,
583625
}))
584626
}

0 commit comments

Comments
 (0)