Skip to main content

khive_runtime/
node_pins.rs

1//! Runtime-owned history of confirmed node public keys.
2//!
3//! Call these methods on the runtime bound to comm's assigned backend, exactly
4//! as for ordinary comm note operations. The runtime never supplies SQL. Pins
5//! are retained indefinitely: removing a configuration entry does not revoke a
6//! retained public key, and no pin is overwritten or deleted.
7use crate::error::RuntimeResult;
8use crate::KhiveRuntime;
9use khive_db::stores::note::node_pins::NodePinStore;
10pub use khive_db::stores::note::node_pins::{NodePinKey, NodePinRecord};
11
12impl KhiveRuntime {
13    fn node_pin_store(&self) -> NodePinStore {
14        NodePinStore::new(self.backend().pool_arc())
15    }
16
17    /// Retain confirmed pins in one transaction. An exact existing payload is a
18    /// no-op; different bytes at an existing identity refuse the whole call.
19    pub async fn retain_confirmed_node_pins(&self, pins: Vec<NodePinRecord>) -> RuntimeResult<()> {
20        self.node_pin_store().retain(pins).await?;
21        Ok(())
22    }
23
24    /// Read the confirmed pin for one exact identity, including old key epochs.
25    pub async fn confirmed_node_pin(
26        &self,
27        key: NodePinKey,
28    ) -> RuntimeResult<Option<NodePinRecord>> {
29        Ok(self.node_pin_store().get(key).await?)
30    }
31}
32
33#[cfg(test)]
34#[path = "node_pins_tests.rs"]
35mod tests;