refactor: use tuple struct construction for SqliteStore type

This commit is contained in:
thunderbiscuit 2024-06-27 12:17:00 -04:00
parent f4366ac49f
commit cddd5f25d8
No known key found for this signature in database
GPG Key ID: 88253696EB836462

View File

@ -8,23 +8,19 @@ use bdk_wallet::KeychainKind;
use std::sync::{Arc, Mutex, MutexGuard}; use std::sync::{Arc, Mutex, MutexGuard};
pub struct SqliteStore { pub struct SqliteStore(Mutex<BdkSqliteStore<KeychainKind, ConfirmationTimeHeightAnchor>>);
inner_mutex: Mutex<BdkSqliteStore<KeychainKind, ConfirmationTimeHeightAnchor>>,
}
impl SqliteStore { impl SqliteStore {
pub fn new(path: String) -> Result<Self, SqliteError> { pub fn new(path: String) -> Result<Self, SqliteError> {
let connection = Connection::open(path)?; let connection = Connection::open(path)?;
let db = Store::new(connection)?; let db = Store::new(connection)?;
Ok(Self { Ok(Self(Mutex::new(db)))
inner_mutex: Mutex::new(db),
})
} }
pub(crate) fn get_store( pub(crate) fn get_store(
&self, &self,
) -> MutexGuard<BdkSqliteStore<KeychainKind, ConfirmationTimeHeightAnchor>> { ) -> MutexGuard<BdkSqliteStore<KeychainKind, ConfirmationTimeHeightAnchor>> {
self.inner_mutex.lock().expect("sqlite store") self.0.lock().expect("sqlite store")
} }
pub fn write(&self, changeset: &ChangeSet) -> Result<(), SqliteError> { pub fn write(&self, changeset: &ChangeSet) -> Result<(), SqliteError> {