Remove unconstrained generic in ProviderFactory::new_with_database_path (#6869)

This commit is contained in:
makcandrov
2024-02-29 02:28:25 -08:00
committed by GitHub
parent f82963376b
commit 70d786af9e

View File

@@ -64,20 +64,6 @@ impl<DB> ProviderFactory<DB> {
Self { db, chain_spec, snapshot_provider: None }
}
/// Create new database provider by passing a path. [`ProviderFactory`] will own the database
/// instance.
pub fn new_with_database_path<P: AsRef<Path>>(
path: P,
chain_spec: Arc<ChainSpec>,
args: DatabaseArguments,
) -> RethResult<ProviderFactory<DatabaseEnv>> {
Ok(ProviderFactory::<DatabaseEnv> {
db: init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?,
chain_spec,
snapshot_provider: None,
})
}
/// Database provider that comes with a shared snapshot provider.
pub fn with_snapshots(
mut self,
@@ -97,6 +83,22 @@ impl<DB> ProviderFactory<DB> {
}
}
impl ProviderFactory<DatabaseEnv> {
/// Create new database provider by passing a path. [`ProviderFactory`] will own the database
/// instance.
pub fn new_with_database_path<P: AsRef<Path>>(
path: P,
chain_spec: Arc<ChainSpec>,
args: DatabaseArguments,
) -> RethResult<Self> {
Ok(ProviderFactory::<DatabaseEnv> {
db: init_db(path, args).map_err(|e| RethError::Custom(e.to_string()))?,
chain_spec,
snapshot_provider: None,
})
}
}
impl<DB: Database> ProviderFactory<DB> {
/// Returns a provider with a created `DbTx` inside, which allows fetching data from the
/// database using different types of providers. Example: [`HeaderProvider`]
@@ -534,7 +536,7 @@ mod tests {
use alloy_rlp::Decodable;
use assert_matches::assert_matches;
use rand::Rng;
use reth_db::{tables, test_utils::ERROR_TEMPDIR, transaction::DbTxMut, DatabaseEnv};
use reth_db::{tables, test_utils::ERROR_TEMPDIR, transaction::DbTxMut};
use reth_interfaces::{
provider::ProviderError,
test_utils::{
@@ -578,7 +580,7 @@ mod tests {
#[test]
fn provider_factory_with_database_path() {
let chain_spec = ChainSpecBuilder::mainnet().build();
let factory = ProviderFactory::<DatabaseEnv>::new_with_database_path(
let factory = ProviderFactory::new_with_database_path(
tempfile::TempDir::new().expect(ERROR_TEMPDIR).into_path(),
Arc::new(chain_spec),
Default::default(),