mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
primitives: use alloy Header struct (#10691)
This commit is contained in:
@ -94,14 +94,14 @@ pub struct Header {
|
||||
impl From<Header> for SealedHeader {
|
||||
fn from(value: Header) -> Self {
|
||||
let header = RethHeader {
|
||||
base_fee_per_gas: value.base_fee_per_gas.map(|v| v.to::<u64>()),
|
||||
base_fee_per_gas: value.base_fee_per_gas.map(|v| v.to::<u64>().into()),
|
||||
beneficiary: value.coinbase,
|
||||
difficulty: value.difficulty,
|
||||
extra_data: value.extra_data,
|
||||
gas_limit: value.gas_limit.to::<u64>(),
|
||||
gas_used: value.gas_used.to::<u64>(),
|
||||
gas_limit: value.gas_limit.to::<u64>().into(),
|
||||
gas_used: value.gas_used.to::<u64>().into(),
|
||||
mix_hash: value.mix_hash,
|
||||
nonce: u64::from_be_bytes(value.nonce.0),
|
||||
nonce: u64::from_be_bytes(value.nonce.0).into(),
|
||||
number: value.number.to::<u64>(),
|
||||
timestamp: value.timestamp.to::<u64>(),
|
||||
transactions_root: value.transactions_trie,
|
||||
@ -111,12 +111,12 @@ impl From<Header> for SealedHeader {
|
||||
parent_hash: value.parent_hash,
|
||||
logs_bloom: value.bloom,
|
||||
withdrawals_root: value.withdrawals_root,
|
||||
blob_gas_used: value.blob_gas_used.map(|v| v.to::<u64>()),
|
||||
excess_blob_gas: value.excess_blob_gas.map(|v| v.to::<u64>()),
|
||||
blob_gas_used: value.blob_gas_used.map(|v| v.to::<u64>().into()),
|
||||
excess_blob_gas: value.excess_blob_gas.map(|v| v.to::<u64>().into()),
|
||||
parent_beacon_block_root: value.parent_beacon_block_root,
|
||||
requests_root: value.requests_root,
|
||||
};
|
||||
header.seal(value.hash)
|
||||
Self::new(header, value.hash)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use alloy_eips::{
|
||||
eip6110::DepositRequest, eip7002::WithdrawalRequest, eip7251::ConsolidationRequest,
|
||||
};
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, TxKind, B256, U256};
|
||||
use alloy_primitives::{Address, BlockNumber, Bytes, Sealable, TxKind, B256, U256};
|
||||
pub use rand::Rng;
|
||||
use rand::{
|
||||
distributions::uniform::SampleRange, rngs::StdRng, seq::SliceRandom, thread_rng, SeedableRng,
|
||||
@ -96,7 +96,9 @@ pub fn random_header<R: Rng>(rng: &mut R, number: u64, parent: Option<B256>) ->
|
||||
parent_hash: parent.unwrap_or_default(),
|
||||
..Default::default()
|
||||
};
|
||||
header.seal_slow()
|
||||
let sealed = header.seal_slow();
|
||||
let (header, seal) = sealed.into_parts();
|
||||
SealedHeader::new(header, seal)
|
||||
}
|
||||
|
||||
/// Generates a random legacy [Transaction].
|
||||
@ -195,20 +197,24 @@ pub fn random_block<R: Rng>(rng: &mut R, number: u64, block_params: BlockParams)
|
||||
});
|
||||
let withdrawals_root = withdrawals.as_ref().map(|w| proofs::calculate_withdrawals_root(w));
|
||||
|
||||
let sealed = Header {
|
||||
parent_hash: block_params.parent.unwrap_or_default(),
|
||||
number,
|
||||
gas_used: total_gas.into(),
|
||||
gas_limit: total_gas.into(),
|
||||
transactions_root,
|
||||
ommers_hash,
|
||||
base_fee_per_gas: Some(rng.gen::<u64>().into()),
|
||||
requests_root,
|
||||
withdrawals_root,
|
||||
..Default::default()
|
||||
}
|
||||
.seal_slow();
|
||||
|
||||
let (header, seal) = sealed.into_parts();
|
||||
|
||||
SealedBlock {
|
||||
header: Header {
|
||||
parent_hash: block_params.parent.unwrap_or_default(),
|
||||
number,
|
||||
gas_used: total_gas,
|
||||
gas_limit: total_gas,
|
||||
transactions_root,
|
||||
ommers_hash,
|
||||
base_fee_per_gas: Some(rng.gen()),
|
||||
requests_root,
|
||||
withdrawals_root,
|
||||
..Default::default()
|
||||
}
|
||||
.seal_slow(),
|
||||
header: SealedHeader::new(header, seal),
|
||||
body: transactions,
|
||||
ommers,
|
||||
withdrawals: withdrawals.map(Withdrawals::new),
|
||||
|
||||
Reference in New Issue
Block a user