use std::path::Path;
use std::sync::Arc;
use crate::identity_first::{
ContinuityStore, LocalContinuityStore, LocalLeaseProvider, contracts::LeaseProvider,
};
pub struct GatewayIdentitySubstrate {
pub continuity_store: Arc<dyn ContinuityStore>,
pub lease_provider: Arc<dyn LeaseProvider>,
}
pub fn open_identity_substrate(continuity_db: &Path) -> Result<GatewayIdentitySubstrate, String> {
let store = LocalContinuityStore::open(continuity_db).map_err(|e| {
format!(
"failed to open continuity store {}: {e}",
continuity_db.display()
)
})?;
let fencing_floor = store
.max_fencing_token()
.map_err(|e| format!("failed to read continuity fencing high-water: {e}"))?;
Ok(GatewayIdentitySubstrate {
continuity_store: Arc::new(store),
lease_provider: Arc::new(LocalLeaseProvider::with_floor(fencing_floor)),
})
}