Bootstrap geth Rust workspace
This commit is contained in:
commit
26f81ff1ef
73 changed files with 4835 additions and 0 deletions
11
crates/geth-config/Cargo.toml
Normal file
11
crates/geth-config/Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "geth-config"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
directories.workspace = true
|
||||
serde.workspace = true
|
||||
thiserror.workspace = true
|
||||
81
crates/geth-config/src/lib.rs
Normal file
81
crates/geth-config/src/lib.rs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GethPaths {
|
||||
home: PathBuf,
|
||||
}
|
||||
|
||||
impl GethPaths {
|
||||
pub fn resolve() -> Result<Self, ConfigError> {
|
||||
if let Some(home) = std::env::var_os("GETH_HOME") {
|
||||
return Ok(Self {
|
||||
home: PathBuf::from(home),
|
||||
});
|
||||
}
|
||||
let project_dirs = directories::ProjectDirs::from("local", "geth", "geth")
|
||||
.ok_or(ConfigError::NoDataDirectory)?;
|
||||
Ok(Self {
|
||||
home: project_dirs.data_dir().to_path_buf(),
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn from_home(home: impl Into<PathBuf>) -> Self {
|
||||
Self { home: home.into() }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn home(&self) -> &Path {
|
||||
&self.home
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn config_file(&self) -> PathBuf {
|
||||
self.home.join("config.toml")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn metadata_db(&self) -> PathBuf {
|
||||
self.home.join("geth.sqlite")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn identity_dir(&self) -> PathBuf {
|
||||
self.home.join("identity")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn agent_key(&self) -> PathBuf {
|
||||
self.identity_dir().join("agent.ed25519")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn cas_dir(&self) -> PathBuf {
|
||||
self.home.join("cas")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_dir(&self) -> PathBuf {
|
||||
self.home.join("run")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn socket_path(&self) -> PathBuf {
|
||||
self.run_dir().join("geth.sock")
|
||||
}
|
||||
|
||||
pub fn ensure_base_dirs(&self) -> Result<(), ConfigError> {
|
||||
std::fs::create_dir_all(self.identity_dir())?;
|
||||
std::fs::create_dir_all(self.cas_dir().join("blobs"))?;
|
||||
std::fs::create_dir_all(self.run_dir())?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ConfigError {
|
||||
#[error("could not determine OS data directory and GETH_HOME is unset")]
|
||||
NoDataDirectory,
|
||||
#[error("io error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
Loading…
Reference in a new issue