mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: bound most NetworkBuilder methods by NetworkPrimitives generic (#13119)
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
use alloy_eips::eip2718::Decodable2718;
|
||||
use alloy_primitives::hex;
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use reth_eth_wire::{EthVersion, PooledTransactions, ProtocolMessage};
|
||||
use reth_eth_wire::{EthNetworkPrimitives, EthVersion, PooledTransactions, ProtocolMessage};
|
||||
use reth_primitives::PooledTransactionsElement;
|
||||
use std::{fs, path::PathBuf};
|
||||
use test_fuzz::test_fuzz;
|
||||
@ -51,7 +51,7 @@ fn decode_request_pair_pooled_blob_transactions() {
|
||||
.join("testdata/request_pair_pooled_blob_transactions");
|
||||
let data = fs::read_to_string(network_data_path).expect("Unable to read file");
|
||||
let hex_data = hex::decode(data.trim()).unwrap();
|
||||
let _txs: ProtocolMessage =
|
||||
let _txs: ProtocolMessage<EthNetworkPrimitives> =
|
||||
ProtocolMessage::decode_message(EthVersion::Eth68, &mut &hex_data[..]).unwrap();
|
||||
}
|
||||
|
||||
|
||||
@ -24,35 +24,50 @@ pub struct NetworkBuilder<Tx, Eth, N: NetworkPrimitives = EthNetworkPrimitives>
|
||||
|
||||
// === impl NetworkBuilder ===
|
||||
|
||||
impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
|
||||
impl<Tx, Eth, N: NetworkPrimitives> NetworkBuilder<Tx, Eth, N> {
|
||||
/// Consumes the type and returns all fields.
|
||||
pub fn split(self) -> (NetworkManager, Tx, Eth) {
|
||||
pub fn split(self) -> (NetworkManager<N>, Tx, Eth) {
|
||||
let Self { network, transactions, request_handler } = self;
|
||||
(network, transactions, request_handler)
|
||||
}
|
||||
|
||||
/// Returns the network manager.
|
||||
pub const fn network(&self) -> &NetworkManager {
|
||||
pub const fn network(&self) -> &NetworkManager<N> {
|
||||
&self.network
|
||||
}
|
||||
|
||||
/// Returns the mutable network manager.
|
||||
pub fn network_mut(&mut self) -> &mut NetworkManager {
|
||||
pub fn network_mut(&mut self) -> &mut NetworkManager<N> {
|
||||
&mut self.network
|
||||
}
|
||||
|
||||
/// Returns the handle to the network.
|
||||
pub fn handle(&self) -> NetworkHandle {
|
||||
pub fn handle(&self) -> NetworkHandle<N> {
|
||||
self.network.handle().clone()
|
||||
}
|
||||
|
||||
/// Consumes the type and returns all fields and also return a [`NetworkHandle`].
|
||||
pub fn split_with_handle(self) -> (NetworkHandle, NetworkManager, Tx, Eth) {
|
||||
pub fn split_with_handle(self) -> (NetworkHandle<N>, NetworkManager<N>, Tx, Eth) {
|
||||
let Self { network, transactions, request_handler } = self;
|
||||
let handle = network.handle().clone();
|
||||
(handle, network, transactions, request_handler)
|
||||
}
|
||||
|
||||
/// Creates a new [`EthRequestHandler`] and wires it to the network.
|
||||
pub fn request_handler<Client>(
|
||||
self,
|
||||
client: Client,
|
||||
) -> NetworkBuilder<Tx, EthRequestHandler<Client, N>, N> {
|
||||
let Self { mut network, transactions, .. } = self;
|
||||
let (tx, rx) = mpsc::channel(ETH_REQUEST_CHANNEL_CAPACITY);
|
||||
network.set_eth_request_handler(tx);
|
||||
let peers = network.handle().peers_handle().clone();
|
||||
let request_handler = EthRequestHandler::new(client, peers, rx);
|
||||
NetworkBuilder { network, request_handler, transactions }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
|
||||
/// Creates a new [`TransactionsManager`] and wires it to the network.
|
||||
pub fn transactions<Pool: TransactionPool>(
|
||||
self,
|
||||
@ -66,17 +81,4 @@ impl<Tx, Eth> NetworkBuilder<Tx, Eth> {
|
||||
let transactions = TransactionsManager::new(handle, pool, rx, transactions_manager_config);
|
||||
NetworkBuilder { network, request_handler, transactions }
|
||||
}
|
||||
|
||||
/// Creates a new [`EthRequestHandler`] and wires it to the network.
|
||||
pub fn request_handler<Client>(
|
||||
self,
|
||||
client: Client,
|
||||
) -> NetworkBuilder<Tx, EthRequestHandler<Client>> {
|
||||
let Self { mut network, transactions, .. } = self;
|
||||
let (tx, rx) = mpsc::channel(ETH_REQUEST_CHANNEL_CAPACITY);
|
||||
network.set_eth_request_handler(tx);
|
||||
let peers = network.handle().peers_handle().clone();
|
||||
let request_handler = EthRequestHandler::new(client, peers, rx);
|
||||
NetworkBuilder { network, request_handler, transactions }
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ impl<N: NetworkPrimitives> NetworkConfig<(), N> {
|
||||
}
|
||||
|
||||
/// Convenience method for creating the corresponding builder type with a random secret key.
|
||||
pub fn builder_with_rng_secret_key() -> NetworkConfigBuilder {
|
||||
pub fn builder_with_rng_secret_key() -> NetworkConfigBuilder<N> {
|
||||
NetworkConfigBuilder::with_rng_secret_key()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user