diff --git a/src/database/mod.rs b/src/database/mod.rs index 758d204ce..13d459641 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -18,7 +18,7 @@ mod wallet; use dash_sdk::dpp::dashcore::Network; use rusqlite::{Connection, Params}; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; /// Error indicating a corrupted data blob in the database. /// @@ -41,17 +41,25 @@ impl From for rusqlite::Error { #[derive(Debug)] pub struct Database { - conn: Mutex, + conn: Arc>, } impl Database { pub fn new>(path: P) -> rusqlite::Result { let conn = Connection::open(path)?; Ok(Self { - conn: Mutex::new(conn), + conn: Arc::new(Mutex::new(conn)), }) } + /// Get a shared reference to the underlying connection. + /// + /// Used by `ClientPersistentCommitmentTree` to share the same SQLite + /// connection for the shielded commitment tree tables. + pub fn shared_connection(&self) -> Arc> { + self.conn.clone() + } + pub fn execute(&self, sql: &str, params: P) -> rusqlite::Result { let conn = self.conn.lock().unwrap(); conn.execute(sql, params)