mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
impl From for Status/SealedHeader (#927)
This commit is contained in:
committed by
GitHub
parent
82b10fae41
commit
d0e3741136
@ -1,7 +1,11 @@
|
||||
use crate::{EthVersion, StatusBuilder};
|
||||
|
||||
use ethers_core::utils::Genesis;
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_primitives::{Chain, ForkId, Hardfork, H256, MAINNET, U256};
|
||||
use reth_primitives::{
|
||||
constants::EIP1559_INITIAL_BASE_FEE, Chain, ChainSpec, ForkId, Hardfork, Header, H256, MAINNET,
|
||||
U256,
|
||||
};
|
||||
use reth_rlp::{RlpDecodable, RlpEncodable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Debug, Display};
|
||||
@ -39,6 +43,40 @@ pub struct Status {
|
||||
pub forkid: ForkId,
|
||||
}
|
||||
|
||||
impl From<Genesis> for Status {
|
||||
fn from(genesis: Genesis) -> Status {
|
||||
let chain = genesis.config.chain_id;
|
||||
let total_difficulty = genesis.difficulty.into();
|
||||
let mut chainspec = ChainSpec::from(genesis);
|
||||
let mut header = Header::from(chainspec.genesis().clone());
|
||||
|
||||
let hardforks = chainspec.hardforks();
|
||||
|
||||
// set initial base fee depending on eip-1559
|
||||
if Some(&0u64) == hardforks.get(&Hardfork::London) {
|
||||
header.base_fee_per_gas = Some(EIP1559_INITIAL_BASE_FEE);
|
||||
}
|
||||
|
||||
// calculate the hash
|
||||
let sealed_header = header.seal();
|
||||
|
||||
// set the new genesis hash after modifying the base fee
|
||||
chainspec.genesis_hash = sealed_header.hash();
|
||||
|
||||
// we need to calculate the fork id AFTER re-setting the genesis hash
|
||||
let forkid = chainspec.fork_id(0);
|
||||
|
||||
Status {
|
||||
version: EthVersion::Eth67 as u8,
|
||||
chain: Chain::Id(chain),
|
||||
total_difficulty,
|
||||
blockhash: sealed_header.hash(),
|
||||
genesis: sealed_header.hash(),
|
||||
forkid,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Status {
|
||||
/// Helper for returning a builder for the status message.
|
||||
pub fn builder() -> StatusBuilder {
|
||||
|
||||
Reference in New Issue
Block a user