mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix static file derive (#14473)
This commit is contained in:
@ -119,15 +119,14 @@ impl ReadOnlyConfig {
|
|||||||
/// ```text
|
/// ```text
|
||||||
/// -`datadir`
|
/// -`datadir`
|
||||||
/// |__db
|
/// |__db
|
||||||
/// |__static_files
|
/// |__static_files
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// By default this watches the static file directory for changes, see also
|
/// By default this watches the static file directory for changes, see also
|
||||||
/// [`StaticFileProvider::read_only`]
|
/// [`StaticFileProvider::read_only`]
|
||||||
pub fn from_datadir(datadir: impl AsRef<Path>) -> Self {
|
pub fn from_datadir(datadir: impl AsRef<Path>) -> Self {
|
||||||
let datadir = datadir.as_ref();
|
let datadir = datadir.as_ref();
|
||||||
let db_path = datadir.join("db");
|
Self::from_dirs(datadir.join("db"), datadir.join("static_files"))
|
||||||
Self::from_db_dir(db_path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Derives the [`ReadOnlyConfig`] from the database dir.
|
/// Derives the [`ReadOnlyConfig`] from the database dir.
|
||||||
@ -136,16 +135,35 @@ impl ReadOnlyConfig {
|
|||||||
///
|
///
|
||||||
/// ```text
|
/// ```text
|
||||||
/// - db
|
/// - db
|
||||||
/// |__static_files
|
/// -static_files
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// By default this watches the static file directory for changes, see also
|
/// By default this watches the static file directory for changes, see also
|
||||||
/// [`StaticFileProvider::read_only`]
|
/// [`StaticFileProvider::read_only`]
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// If the path does not exist
|
||||||
pub fn from_db_dir(db_dir: impl AsRef<Path>) -> Self {
|
pub fn from_db_dir(db_dir: impl AsRef<Path>) -> Self {
|
||||||
let db_dir = db_dir.as_ref();
|
let db_dir = db_dir.as_ref();
|
||||||
|
let static_files_dir = std::fs::canonicalize(db_dir)
|
||||||
|
.unwrap()
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.to_path_buf()
|
||||||
|
.join("static_files");
|
||||||
|
Self::from_dirs(db_dir, static_files_dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates the config for the given paths.
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// By default this watches the static file directory for changes, see also
|
||||||
|
/// [`StaticFileProvider::read_only`]
|
||||||
|
pub fn from_dirs(db_dir: impl AsRef<Path>, static_files_dir: impl AsRef<Path>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
static_files_dir: db_dir.join("static_files"),
|
static_files_dir: static_files_dir.as_ref().into(),
|
||||||
db_dir: db_dir.into(),
|
db_dir: db_dir.as_ref().into(),
|
||||||
db_args: Default::default(),
|
db_args: Default::default(),
|
||||||
watch_static_files: true,
|
watch_static_files: true,
|
||||||
}
|
}
|
||||||
@ -247,8 +265,6 @@ impl<N, Val1, Val2> TypesAnd2<N, Val1, Val2> {
|
|||||||
{
|
{
|
||||||
TypesAnd3::new(self.val_1, self.val_2, static_file_provider)
|
TypesAnd3::new(self.val_1, self.val_2, static_file_provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add helper fns for opening static file provider
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is staging type that contains the configured types and _three_ values.
|
/// This is staging type that contains the configured types and _three_ values.
|
||||||
|
|||||||
@ -20,13 +20,13 @@ use reth_ethereum::{
|
|||||||
// These abstractions do not include any caching and the user is responsible for doing that.
|
// These abstractions do not include any caching and the user is responsible for doing that.
|
||||||
// Other parts of the code which include caching are parts of the `EthApi` abstraction.
|
// Other parts of the code which include caching are parts of the `EthApi` abstraction.
|
||||||
fn main() -> eyre::Result<()> {
|
fn main() -> eyre::Result<()> {
|
||||||
// Opens a RO handle to the database file.
|
// The path to data directory, e.g. "~/.local/reth/share/mainnet"
|
||||||
let db_path = std::env::var("RETH_DB_PATH")?;
|
let datadir = std::env::var("RETH_DATADIR")?;
|
||||||
|
|
||||||
// Instantiate a provider factory for Ethereum mainnet using the provided DB path.
|
// Instantiate a provider factory for Ethereum mainnet using the provided datadir path.
|
||||||
let spec = ChainSpecBuilder::mainnet().build();
|
let spec = ChainSpecBuilder::mainnet().build();
|
||||||
let factory = EthereumNode::provider_factory_builder()
|
let factory = EthereumNode::provider_factory_builder()
|
||||||
.open_read_only(spec.into(), ReadOnlyConfig::from_db_dir(db_path))?;
|
.open_read_only(spec.into(), ReadOnlyConfig::from_datadir(datadir))?;
|
||||||
|
|
||||||
// This call opens a RO transaction on the database. To write to the DB you'd need to call
|
// This call opens a RO transaction on the database. To write to the DB you'd need to call
|
||||||
// the `provider_rw` function and look for the `Writer` variants of the traits.
|
// the `provider_rw` function and look for the `Writer` variants of the traits.
|
||||||
|
|||||||
Reference in New Issue
Block a user