lib: setup the connection to bitcoind before the connection to SQLite.

This commit is contained in:
Antoine Poinsot 2024-07-29 14:41:56 +02:00 committed by jp1ac4
parent ccc88421b3
commit 50e7ffafa4
No known key found for this signature in database
GPG Key ID: C61FA2110D7DC407

View File

@ -337,7 +337,15 @@ impl DaemonHandle {
log::info!("Created a new data directory at '{}'", data_dir.display()); log::info!("Created a new data directory at '{}'", data_dir.display());
} }
// Then set up the database // Set up the connection to bitcoind (if using it) first as we may need it for the database
// migration when setting up SQLite below.
let bitcoind = if bitcoin.is_none() {
Some(setup_bitcoind(&config, &data_dir, fresh_data_dir)?)
} else {
None
};
// Then set up the database backend.
let db = match db { let db = match db {
Some(db) => sync::Arc::from(sync::Mutex::from(db)), Some(db) => sync::Arc::from(sync::Mutex::from(db)),
None => sync::Arc::from(sync::Mutex::from(setup_sqlite( None => sync::Arc::from(sync::Mutex::from(setup_sqlite(
@ -348,14 +356,12 @@ impl DaemonHandle {
)?)) as sync::Arc<sync::Mutex<dyn DatabaseInterface>>, )?)) as sync::Arc<sync::Mutex<dyn DatabaseInterface>>,
}; };
// Now, set up the Bitcoin interface. // Finally set up the Bitcoin backend.
let bit = match bitcoin { let bit = match (bitcoin, bitcoind) {
Some(bit) => sync::Arc::from(sync::Mutex::from(bit)), (Some(bit), None) => sync::Arc::from(sync::Mutex::from(bit)),
None => sync::Arc::from(sync::Mutex::from(setup_bitcoind( (None, Some(bit)) => sync::Arc::from(sync::Mutex::from(bit))
&config, as sync::Arc<sync::Mutex<dyn BitcoinInterface>>,
&data_dir, _ => unreachable!("Either bitcoind or bitcoin interface is always set."),
fresh_data_dir,
)?)) as sync::Arc<sync::Mutex<dyn BitcoinInterface>>,
}; };
// If we are on a UNIX system and they told us to daemonize, do it now. // If we are on a UNIX system and they told us to daemonize, do it now.