use crate::DatabaseIdentifier;
use holo_hash::{AgentPubKey, DnaHash};
use holochain_zome_types::cell::CellId;
use std::sync::Arc;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DbKind {
Wasm,
Conductor,
}
#[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
}
fn db_kind(&self) -> DbKind {
todo!("Authored migrations not yet implemented")
}
}
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
}
fn db_kind(&self) -> DbKind {
todo!("Dht migrations not yet implemented")
}
}
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_v2.db"
}
fn db_kind(&self) -> DbKind {
DbKind::Conductor
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Wasm;
impl DatabaseIdentifier for Wasm {
fn database_id(&self) -> &str {
"wasm"
}
fn db_kind(&self) -> DbKind {
DbKind::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
}
fn db_kind(&self) -> DbKind {
todo!("PeerMetaStore migrations not yet implemented")
}
}
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()
}
}