Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Move some functions to `Home` type
cloudhead committed 2 years ago
commit a70664368e76b5c7d4cd285f3dbc4d9b0193d2fa
parent d15534df971e9eaca1a2fa0cea151fce67b48ebf
5 files changed +71 -19
modified radicle-cli/src/commands/self.rs
@@ -106,7 +106,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            term::print(profile.did());
        }
        Show::Home => {
-
            term::print(profile.home().display());
+
            term::print(profile.home().path().display());
        }
        Show::Config => {
            term::print(profile.home.config().display());
@@ -171,7 +171,7 @@ fn all(profile: &Profile) -> anyhow::Result<()> {
    let home = profile.home();
    table.push([
        term::format::style("Home").into(),
-
        term::format::tertiary(home.display()).into(),
+
        term::format::tertiary(home.path().display()).into(),
    ]);

    let config_path = profile.home.config();
modified radicle-httpd/src/lib.rs
@@ -60,7 +60,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> {
    let profile = Profile::load()?;
    let request_id = RequestId::new();

-
    tracing::info!("using radicle home at {}", profile.home().display());
+
    tracing::info!("using radicle home at {}", profile.home().path().display());

    let app =
        router(options, profile)?
modified radicle-node/src/test/environment.rs
@@ -329,9 +329,9 @@ impl Node<MockSigner> {
        let home = Home::new(home).unwrap();
        let signer = MockSigner::default();
        let storage = Storage::open(home.storage()).unwrap();
-
        let addresses = Book::memory().unwrap();
-
        let tracking = tracking::Config::<tracking::Write>::memory().unwrap();
-
        let routing = routing::Table::memory().unwrap();
+
        let addresses = home.addresses_mut().unwrap();
+
        let tracking = home.tracking_mut().unwrap();
+
        let routing = home.routing_mut().unwrap();

        Self {
            id: *signer.public_key(),
modified radicle-tools/src/rad-self.rs
@@ -7,7 +7,7 @@ fn main() -> anyhow::Result<()> {
        "fingerprint: {}",
        radicle::crypto::ssh::fmt::fingerprint(profile.id())
    );
-
    println!("home: {}", profile.home().display());
+
    println!("home: {}", profile.home().path().display());

    Ok(())
}
modified radicle/src/profile.rs
@@ -259,30 +259,34 @@ impl Profile {
        Ok(addresses)
    }

+
    /// Get radicle home.
+
    pub fn home(&self) -> &Home {
+
        &self.home
+
    }
+

    /// Return a multi-source store for aliases.
    pub fn aliases(&self) -> Aliases {
-
        let tracking = self.tracking().ok();
-
        let addresses = self.addresses().ok();
+
        let tracking = self.home.tracking().ok();
+
        let addresses = self.home.addresses().ok();

        Aliases {
            tracking,
            addresses,
        }
    }
+
}

-
    /// Return the path to the keys folder.
-
    pub fn keys(&self) -> PathBuf {
-
        self.home.keys()
-
    }
+
impl std::ops::Deref for Profile {
+
    type Target = Home;

-
    /// Get the profile home directory.
-
    pub fn home(&self) -> &Path {
-
        self.home.path()
+
    fn deref(&self) -> &Self::Target {
+
        &self.home
    }
+
}

-
    /// Get the path to the radicle node socket.
-
    pub fn socket(&self) -> PathBuf {
-
        self.home.socket()
+
impl std::ops::DerefMut for Profile {
+
    fn deref_mut(&mut self) -> &mut Self::Target {
+
        &mut self.home
    }
}

@@ -387,6 +391,54 @@ impl Home {
            .map(PathBuf::from)
            .unwrap_or_else(|| self.node().join(node::DEFAULT_SOCKET_NAME))
    }
+

+
    /// Return a read-only handle to the tracking configuration of the node.
+
    pub fn tracking(&self) -> Result<tracking::store::ConfigReader, tracking::store::Error> {
+
        let path = self.node().join(node::TRACKING_DB_FILE);
+
        let config = tracking::store::Config::reader(path)?;
+

+
        Ok(config)
+
    }
+

+
    /// Return a read-write handle to the tracking configuration of the node.
+
    pub fn tracking_mut(&self) -> Result<tracking::store::ConfigWriter, tracking::store::Error> {
+
        let path = self.node().join(node::TRACKING_DB_FILE);
+
        let config = tracking::store::Config::open(path)?;
+

+
        Ok(config)
+
    }
+

+
    /// Return a read-only handle to the routing database of the node.
+
    pub fn routing(&self) -> Result<routing::Table, routing::Error> {
+
        let path = self.node().join(node::ROUTING_DB_FILE);
+
        let router = routing::Table::reader(path)?;
+

+
        Ok(router)
+
    }
+

+
    /// Return a read-write handle to the routing database of the node.
+
    pub fn routing_mut(&self) -> Result<routing::Table, routing::Error> {
+
        let path = self.node().join(node::ROUTING_DB_FILE);
+
        let router = routing::Table::open(path)?;
+

+
        Ok(router)
+
    }
+

+
    /// Return a handle to a read-only addresses database of the node.
+
    pub fn addresses(&self) -> Result<address::Book, address::Error> {
+
        let path = self.node().join(node::ADDRESS_DB_FILE);
+
        let addresses = address::Book::reader(path)?;
+

+
        Ok(addresses)
+
    }
+

+
    /// Return a handle to the addresses database of the node.
+
    pub fn addresses_mut(&self) -> Result<address::Book, address::Error> {
+
        let path = self.node().join(node::ADDRESS_DB_FILE);
+
        let addresses = address::Book::open(path)?;
+

+
        Ok(addresses)
+
    }
}

#[cfg(test)]