fedimint_cursed_redb/
native.rs
1use std::path::Path;
2
3use anyhow::{Context as _, Result};
4use fedimint_db_locked::{Locked, LockedBuilder};
5use redb::Database;
6
7use crate::MemAndRedb;
8
9impl MemAndRedb {
10 pub async fn new(db_path: impl AsRef<Path>) -> Result<Locked<MemAndRedb>> {
11 let db_path = db_path.as_ref();
12 fedimint_core::task::block_in_place(|| Self::open_blocking(db_path))
13 }
14
15 fn open_blocking(db_path: &Path) -> Result<Locked<MemAndRedb>> {
16 std::fs::create_dir_all(
17 db_path
18 .parent()
19 .ok_or_else(|| anyhow::anyhow!("db path must have a base dir"))?,
20 )?;
21 LockedBuilder::new(db_path)?.with_db(|| {
22 let db = Database::create(db_path).context("Failed to create/open redb database")?;
23 Self::new_from_redb(db)
24 })
25 }
26}