use crate::DatabaseIdentifier;
use holo_hash::{AgentPubKey, DnaHash};
use holochain_zome_types::cell::CellId;
use std::sync::Arc;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Authored {
cell_id: Arc<CellId>,
id: String,
}
impl DatabaseIdentifier for Authored {
fn database_id(&self) -> &str {
&self.id
}
}
impl Authored {
pub fn new(cell_id: Arc<CellId>) -> Self {
let id = format!("authored-{}-{}", cell_id.dna_hash(), cell_id.agent_pubkey());
Self { cell_id, id }
}
pub fn dna_hash(&self) -> &DnaHash {
self.cell_id.dna_hash()
}
pub fn agent_pubkey(&self) -> &AgentPubKey {
self.cell_id.agent_pubkey()
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Dht {
dna_hash: Arc<DnaHash>,
id: String,
}
impl DatabaseIdentifier for Dht {
fn database_id(&self) -> &str {
&self.id
}
}
impl Dht {
pub fn new(dna_hash: Arc<DnaHash>) -> Self {
let id = format!("dht-{dna_hash}");
Self { dna_hash, id }
}
pub fn dna_hash(&self) -> &DnaHash {
&self.dna_hash
}
pub fn to_dna_hash(&self) -> Arc<DnaHash> {
self.dna_hash.clone()
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Conductor;
impl DatabaseIdentifier for Conductor {
fn database_id(&self) -> &str {
"conductor"
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Wasm;
impl DatabaseIdentifier for Wasm {
fn database_id(&self) -> &str {
"wasm"
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PeerMetaStore {
dna_hash: Arc<DnaHash>,
id: String,
}
impl DatabaseIdentifier for PeerMetaStore {
fn database_id(&self) -> &str {
&self.id
}
}
impl PeerMetaStore {
pub fn new(dna_hash: Arc<DnaHash>) -> Self {
let id = format!("p2p-peer-meta-{dna_hash}");
Self { dna_hash, id }
}
pub fn dna_hash(&self) -> &DnaHash {
&self.dna_hash
}
pub fn to_dna_hash(&self) -> Arc<DnaHash> {
self.dna_hash.clone()
}
}