From 6d59036f5e8acb1cde3fbbabb54b490076718f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Blankfors?= Date: Wed, 6 Mar 2024 11:11:55 +0100 Subject: [PATCH] feat: Relax trait bound requirements of creating and spawning signers --- libsigner/src/runloop.rs | 16 +++++++++------- stacks-signer/src/signerdb.rs | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/libsigner/src/runloop.rs b/libsigner/src/runloop.rs index 54dd58e17..0b7eb2dbc 100644 --- a/libsigner/src/runloop.rs +++ b/libsigner/src/runloop.rs @@ -189,13 +189,7 @@ pub fn set_runloop_signal_handler(mut st }).expect("FATAL: failed to set signal handler"); } -impl< - CMD: Send + 'static, - R: Send + 'static, - SL: SignerRunLoop + Send + Sync + 'static, - EV: EventReceiver + Send + 'static, - > Signer -{ +impl Signer { /// 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 + Send + 'static, + EV: EventReceiver + Send + 'static, + > Signer +{ /// 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 diff --git a/stacks-signer/src/signerdb.rs b/stacks-signer/src/signerdb.rs index be1aae2a5..269fb327b 100644 --- a/stacks-signer/src/signerdb.rs +++ b/stacks-signer/src/signerdb.rs @@ -33,8 +33,7 @@ pub struct SignerDb { /// The SQLite database path pub db_path: Option, // /// Connection to the DB - // /// TODO: Figure out how to manage this connection - // connection: Option, + connection: Option, } const CREATE_BLOCKS_TABLE: &'static str = " @@ -50,6 +49,7 @@ impl SignerDb { pub fn new(db_path: &Option) -> Result { 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, } }