feat: Relax trait bound requirements of creating and spawning signers

This commit is contained in:
Mårten Blankfors
2024-03-06 11:11:55 +01:00
parent fdba3e9694
commit 6d59036f5e
2 changed files with 13 additions and 9 deletions

View File

@@ -189,13 +189,7 @@ pub fn set_runloop_signal_handler<ST: EventStopSignaler + Send + 'static>(mut st
}).expect("FATAL: failed to set signal handler");
}
impl<
CMD: Send + 'static,
R: Send + 'static,
SL: SignerRunLoop<R, CMD> + Send + Sync + 'static,
EV: EventReceiver + Send + 'static,
> Signer<CMD, R, SL, EV>
{
impl<CMD, R, SL, EV> Signer<CMD, R, SL, EV> {
/// Create a new signer with the given runloop and event receiver.
pub fn new(
runloop: SL,
@@ -210,7 +204,15 @@ impl<
result_sender: Some(result_sender),
}
}
}
impl<
CMD: Send + 'static,
R: Send + 'static,
SL: SignerRunLoop<R, CMD> + Send + 'static,
EV: EventReceiver + Send + 'static,
> Signer<CMD, R, SL, EV>
{
/// This is a helper function to spawn both the runloop and event receiver in their own
/// threads. Advanced signers may not need this method, and instead opt to run the receiver
/// and runloop directly. However, this method is present to help signer developers to get

View File

@@ -33,8 +33,7 @@ pub struct SignerDb {
/// The SQLite database path
pub db_path: Option<PathBuf>,
// /// Connection to the DB
// /// TODO: Figure out how to manage this connection
// connection: Option<Connection>,
connection: Option<Connection>,
}
const CREATE_BLOCKS_TABLE: &'static str = "
@@ -50,6 +49,7 @@ impl SignerDb {
pub fn new(db_path: &Option<PathBuf>) -> Result<SignerDb, DBError> {
let signer_db = SignerDb {
db_path: db_path.clone(),
connection: None,
};
let mut connection = signer_db.get_connection()?;
connection.pragma_update(None, "journal_mode", &"WAL".to_sql().unwrap())?;
@@ -63,6 +63,7 @@ impl SignerDb {
tx.commit().expect("Unable to commit tx");
Ok(SignerDb {
db_path: db_path.clone(),
connection: None,
})
}
@@ -148,6 +149,7 @@ impl SignerDb {
pub fn memory_db() -> SignerDb {
SignerDb {
db_path: Some(PathBuf::from(":memory:")),
connection: None,
}
}