Accept a custom database interface when starting the daemon

This commit is contained in:
Antoine Poinsot committed 2022-08-17 19:39:55 +02:00
1 parent f365effacd
commit ea3595349d
5 files changed
+53 -21

No files matched your search

+9
View File
@@ -8,6 +8,8 @@ use crate::{
database::sqlite::{schema::DbTip, SqliteConn, SqliteDb},
};
use std::sync;
use miniscript::bitcoin::util::bip32;
pub trait DatabaseInterface: Send {
@@ -20,6 +22,13 @@ impl DatabaseInterface for SqliteDb {
}
}
// FIXME: do we need to repeat the entire trait implemenation? Isn't there a nicer way?
impl DatabaseInterface for sync::Arc<sync::Mutex<dyn DatabaseInterface>> {
fn connection(&self) -> Box<dyn DatabaseConnection> {
self.lock().unwrap().connection()
}
}
pub trait DatabaseConnection {
/// Get the tip of the best chain we've seen.
fn chain_tip(&mut self) -> Option<BlockChainTip>;