mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-24 22:58:13 -05:00
feat: allow access to db via NodeBuilder (#17021)
This commit is contained in:
@@ -50,15 +50,20 @@ async fn test_eth_launcher() {
|
||||
let _builder =
|
||||
NodeBuilder::new(config)
|
||||
.with_database(db)
|
||||
.with_launch_context(tasks.executor())
|
||||
.with_types_and_provider::<EthereumNode, BlockchainProvider<
|
||||
NodeTypesWithDBAdapter<EthereumNode, Arc<TempDatabase<DatabaseEnv>>>,
|
||||
>>()
|
||||
.with_components(EthereumNode::components())
|
||||
.with_add_ons(EthereumAddOns::default())
|
||||
.apply(|builder| {
|
||||
let _ = builder.db();
|
||||
builder
|
||||
})
|
||||
.launch_with_fn(|builder| {
|
||||
let launcher = EngineNodeLauncher::new(
|
||||
tasks.executor(),
|
||||
builder.config.datadir(),
|
||||
builder.config().datadir(),
|
||||
Default::default(),
|
||||
);
|
||||
builder.launch_with(launcher)
|
||||
|
||||
@@ -160,6 +160,48 @@ impl<ChainSpec> NodeBuilder<(), ChainSpec> {
|
||||
pub const fn new(config: NodeConfig<ChainSpec>) -> Self {
|
||||
Self { config, database: () }
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig<ChainSpec> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the node builder's config.
|
||||
pub const fn config_mut(&mut self) -> &mut NodeConfig<ChainSpec> {
|
||||
&mut self.config
|
||||
}
|
||||
|
||||
/// Returns a reference to the node's database
|
||||
pub const fn db(&self) -> &DB {
|
||||
&self.database
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the node's database
|
||||
pub const fn db_mut(&mut self) -> &mut DB {
|
||||
&mut self.database
|
||||
}
|
||||
|
||||
/// Applies a fallible function to the builder.
|
||||
pub fn try_apply<F, R>(self, f: F) -> Result<Self, R>
|
||||
where
|
||||
F: FnOnce(Self) -> Result<Self, R>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
/// Applies a fallible function to the builder, if the condition is `true`.
|
||||
pub fn try_apply_if<F, R>(self, cond: bool, f: F) -> Result<Self, R>
|
||||
where
|
||||
F: FnOnce(Self) -> Result<Self, R>,
|
||||
{
|
||||
if cond {
|
||||
f(self)
|
||||
} else {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a function to the builder
|
||||
pub fn apply<F>(self, f: F) -> Self
|
||||
@@ -182,18 +224,6 @@ impl<ChainSpec> NodeBuilder<(), ChainSpec> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, ChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig<ChainSpec> {
|
||||
&self.config
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the node builder's config.
|
||||
pub const fn config_mut(&mut self) -> &mut NodeConfig<ChainSpec> {
|
||||
&mut self.config
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, ChainSpec: EthChainSpec> NodeBuilder<DB, ChainSpec> {
|
||||
/// Configures the underlying database that the node will use.
|
||||
pub fn with_database<D>(self, database: D) -> NodeBuilder<D, ChainSpec> {
|
||||
@@ -413,6 +443,36 @@ where
|
||||
&self.builder.config
|
||||
}
|
||||
|
||||
/// Returns a reference to node's database.
|
||||
pub const fn db(&self) -> &T::DB {
|
||||
&self.builder.adapter.database
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to node's database.
|
||||
pub const fn db_mut(&mut self) -> &mut T::DB {
|
||||
&mut self.builder.adapter.database
|
||||
}
|
||||
|
||||
/// Applies a fallible function to the builder.
|
||||
pub fn try_apply<F, R>(self, f: F) -> Result<Self, R>
|
||||
where
|
||||
F: FnOnce(Self) -> Result<Self, R>,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
/// Applies a fallible function to the builder, if the condition is `true`.
|
||||
pub fn try_apply_if<F, R>(self, cond: bool, f: F) -> Result<Self, R>
|
||||
where
|
||||
F: FnOnce(Self) -> Result<Self, R>,
|
||||
{
|
||||
if cond {
|
||||
f(self)
|
||||
} else {
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply a function to the builder
|
||||
pub fn apply<F>(self, f: F) -> Self
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user