mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: phase out some ethers usage (#3467)
This commit is contained in:
@ -3,7 +3,7 @@ use crate::{
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use reth_eth_wire::{DisconnectReason, ProtocolVersion};
|
||||
use reth_primitives::{rpc::Chain::Mainnet, NodeRecord, PeerId};
|
||||
use reth_primitives::{Chain, NodeRecord, PeerId};
|
||||
use reth_rpc_types::{EthProtocolInfo, NetworkStatus};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
@ -33,7 +33,7 @@ impl NetworkInfo for NoopNetwork {
|
||||
}
|
||||
|
||||
fn chain_id(&self) -> u64 {
|
||||
Mainnet.into()
|
||||
Chain::mainnet().into()
|
||||
}
|
||||
|
||||
fn is_syncing(&self) -> bool {
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
Address, BlockHash, BlockNumber, Header, SealedHeader, TransactionSigned, Withdrawal, H256,
|
||||
Address, BlockHash, BlockNumber, Header, SealedHeader, TransactionSigned, Withdrawal, H256, U64,
|
||||
};
|
||||
use ethers_core::types::{BlockNumber as EthersBlockNumber, U64};
|
||||
use fixed_hash::rustc_hex::FromHexError;
|
||||
use reth_codecs::derive_arbitrary;
|
||||
use reth_rlp::{Decodable, DecodeError, Encodable, RlpDecodable, RlpEncodable};
|
||||
@ -564,19 +563,6 @@ impl From<u64> for BlockNumberOrTag {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EthersBlockNumber> for BlockNumberOrTag {
|
||||
fn from(value: EthersBlockNumber) -> Self {
|
||||
match value {
|
||||
EthersBlockNumber::Latest => BlockNumberOrTag::Latest,
|
||||
EthersBlockNumber::Finalized => BlockNumberOrTag::Finalized,
|
||||
EthersBlockNumber::Safe => BlockNumberOrTag::Safe,
|
||||
EthersBlockNumber::Earliest => BlockNumberOrTag::Earliest,
|
||||
EthersBlockNumber::Pending => BlockNumberOrTag::Pending,
|
||||
EthersBlockNumber::Number(num) => BlockNumberOrTag::Number(num.as_u64()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<U64> for BlockNumberOrTag {
|
||||
fn from(num: U64) -> Self {
|
||||
num.as_u64().into()
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
use crate::{
|
||||
net::{goerli_nodes, mainnet_nodes, sepolia_nodes},
|
||||
NodeRecord, U256,
|
||||
NodeRecord, U256, U64,
|
||||
};
|
||||
use ethers_core::types::U64;
|
||||
use reth_codecs::add_arbitrary_tests;
|
||||
use reth_rlp::{Decodable, Encodable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -2,10 +2,10 @@ use crate::{
|
||||
basefee::calculate_next_block_base_fee,
|
||||
keccak256,
|
||||
proofs::{EMPTY_LIST_HASH, EMPTY_ROOT},
|
||||
BlockHash, BlockNumHash, BlockNumber, Bloom, Bytes, H160, H256, U256,
|
||||
BlockHash, BlockNumHash, BlockNumber, Bloom, Bytes, H160, H256, H64, U256,
|
||||
};
|
||||
use bytes::{Buf, BufMut, BytesMut};
|
||||
use ethers_core::types::{Block, H256 as EthersH256, H64};
|
||||
|
||||
use reth_codecs::{add_arbitrary_tests, derive_arbitrary, main_codec, Compact};
|
||||
use reth_rlp::{length_of_length, Decodable, Encodable, EMPTY_STRING_CODE};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -343,40 +343,6 @@ impl<'a> arbitrary::Arbitrary<'a> for SealedHeader {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Block<EthersH256>> for Header {
|
||||
fn from(block: &Block<EthersH256>) -> Self {
|
||||
Header {
|
||||
parent_hash: block.parent_hash.0.into(),
|
||||
number: block.number.unwrap().as_u64(),
|
||||
gas_limit: block.gas_limit.as_u64(),
|
||||
difficulty: block.difficulty.into(),
|
||||
nonce: block.nonce.unwrap().to_low_u64_be(),
|
||||
extra_data: block.extra_data.0.clone().into(),
|
||||
state_root: block.state_root.0.into(),
|
||||
transactions_root: block.transactions_root.0.into(),
|
||||
receipts_root: block.receipts_root.0.into(),
|
||||
timestamp: block.timestamp.as_u64(),
|
||||
mix_hash: block.mix_hash.unwrap().0.into(),
|
||||
beneficiary: block.author.unwrap().0.into(),
|
||||
base_fee_per_gas: block.base_fee_per_gas.map(|fee| fee.as_u64()),
|
||||
ommers_hash: block.uncles_hash.0.into(),
|
||||
gas_used: block.gas_used.as_u64(),
|
||||
withdrawals_root: None,
|
||||
logs_bloom: block.logs_bloom.unwrap_or_default().0.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Block<EthersH256>> for SealedHeader {
|
||||
fn from(block: &Block<EthersH256>) -> Self {
|
||||
let header = Header::from(block);
|
||||
match block.hash {
|
||||
Some(hash) => header.seal(hash.0.into()),
|
||||
None => header.seal_slow(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SealedHeader {
|
||||
fn default() -> Self {
|
||||
Header::default().seal_slow()
|
||||
@ -506,6 +472,45 @@ impl From<HeadersDirection> for bool {
|
||||
}
|
||||
}
|
||||
|
||||
mod ethers_compat {
|
||||
use super::*;
|
||||
use ethers_core::types::{Block, H256 as EthersH256};
|
||||
|
||||
impl From<&Block<EthersH256>> for Header {
|
||||
fn from(block: &Block<EthersH256>) -> Self {
|
||||
Header {
|
||||
parent_hash: block.parent_hash.0.into(),
|
||||
number: block.number.unwrap().as_u64(),
|
||||
gas_limit: block.gas_limit.as_u64(),
|
||||
difficulty: block.difficulty.into(),
|
||||
nonce: block.nonce.unwrap().to_low_u64_be(),
|
||||
extra_data: block.extra_data.0.clone().into(),
|
||||
state_root: block.state_root.0.into(),
|
||||
transactions_root: block.transactions_root.0.into(),
|
||||
receipts_root: block.receipts_root.0.into(),
|
||||
timestamp: block.timestamp.as_u64(),
|
||||
mix_hash: block.mix_hash.unwrap().0.into(),
|
||||
beneficiary: block.author.unwrap().0.into(),
|
||||
base_fee_per_gas: block.base_fee_per_gas.map(|fee| fee.as_u64()),
|
||||
ommers_hash: block.uncles_hash.0.into(),
|
||||
gas_used: block.gas_used.as_u64(),
|
||||
withdrawals_root: None,
|
||||
logs_bloom: block.logs_bloom.unwrap_or_default().0.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Block<EthersH256>> for SealedHeader {
|
||||
fn from(block: &Block<EthersH256>) -> Self {
|
||||
let header = Header::from(block);
|
||||
match block.hash {
|
||||
Some(hash) => header.seal(hash.0.into()),
|
||||
None => header.seal_slow(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Bytes, Decodable, Encodable, Header, H256};
|
||||
|
||||
@ -115,7 +115,6 @@ pub type StorageValue = U256;
|
||||
pub type Selector = [u8; 4];
|
||||
|
||||
pub use ethers_core::{
|
||||
types as rpc,
|
||||
types::{BigEndianHash, H128, H64, U64},
|
||||
utils as rpc_utils,
|
||||
};
|
||||
|
||||
@ -11,9 +11,9 @@ pub use signature::Signature;
|
||||
pub use typed::*;
|
||||
|
||||
use reth_primitives::{
|
||||
rpc::transaction::eip2930::AccessListItem, Address, BlockNumber, Bytes,
|
||||
Transaction as PrimitiveTransaction, TransactionKind as PrimitiveTransactionKind,
|
||||
TransactionSignedEcRecovered, TxType, H256, U128, U256, U64,
|
||||
AccessListItem, Address, BlockNumber, Bytes, Transaction as PrimitiveTransaction,
|
||||
TransactionKind as PrimitiveTransactionKind, TransactionSignedEcRecovered, TxType, H256, U128,
|
||||
U256, U64,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ use reth_db::{
|
||||
DatabaseError,
|
||||
};
|
||||
use reth_primitives::{
|
||||
rpc_utils::keccak256,
|
||||
keccak256,
|
||||
stage::{EntitiesCheckpoint, StageCheckpoint, StageId},
|
||||
TransactionSignedNoHash, TxNumber, H256,
|
||||
};
|
||||
@ -178,7 +178,7 @@ fn calculate_hash(
|
||||
) -> Result<(H256, TxNumber), Box<StageError>> {
|
||||
let (tx_id, tx) = entry.map_err(|e| Box::new(e.into()))?;
|
||||
tx.transaction.encode_with_signature(&tx.signature, rlp_buf, false);
|
||||
Ok((H256(keccak256(rlp_buf)), tx_id))
|
||||
Ok((keccak256(rlp_buf), tx_id))
|
||||
}
|
||||
|
||||
fn stage_checkpoint<DB: Database>(
|
||||
|
||||
Reference in New Issue
Block a user