From d96e447b706c947981d29852146fccbce327e3c5 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Sat, 9 Nov 2024 09:23:20 +0100 Subject: [PATCH] nits --- .../coins/utxo/utxo_block_header_storage/mod.rs | 9 ++++----- .../z_coin/storage/blockdb/blockdb_sql_storage.rs | 15 +++++++-------- mm2src/mm2_core/src/mm_ctx.rs | 6 +++--- .../tests/docker_tests/swap_watcher_tests.rs | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/mm2src/coins/utxo/utxo_block_header_storage/mod.rs b/mm2src/coins/utxo/utxo_block_header_storage/mod.rs index dbe43dcd36..c065016176 100644 --- a/mm2src/coins/utxo/utxo_block_header_storage/mod.rs +++ b/mm2src/coins/utxo/utxo_block_header_storage/mod.rs @@ -52,13 +52,12 @@ impl BlockHeaderStorage { let conn = ctx .sqlite_connection - .get_or_init(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap()))); + .get() + .cloned() + .unwrap_or_else(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap()))); Ok(BlockHeaderStorage { - inner: Box::new(SqliteBlockHeadersStorage { - ticker, - conn: conn.clone(), - }), + inner: Box::new(SqliteBlockHeadersStorage { ticker, conn }), }) } diff --git a/mm2src/coins/z_coin/storage/blockdb/blockdb_sql_storage.rs b/mm2src/coins/z_coin/storage/blockdb/blockdb_sql_storage.rs index 4f33158bd9..08be5a0e99 100644 --- a/mm2src/coins/z_coin/storage/blockdb/blockdb_sql_storage.rs +++ b/mm2src/coins/z_coin/storage/blockdb/blockdb_sql_storage.rs @@ -73,11 +73,13 @@ impl BlockDbImpl { async_blocking(move || { let conn = ctx .sqlite_connection - .get_or_init(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap()))); + .get() + .cloned() + .unwrap_or_else(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap()))); let conn_clone = conn.clone(); - let conn_clone = conn_clone.lock().unwrap(); - run_optimization_pragmas(&conn_clone).map_err(|err| ZcoinStorageError::DbError(err.to_string()))?; - conn_clone + let conn_lock = conn_clone.lock().unwrap(); + run_optimization_pragmas(&conn_lock).map_err(|err| ZcoinStorageError::DbError(err.to_string()))?; + conn_lock .execute( "CREATE TABLE IF NOT EXISTS compactblocks ( height INTEGER PRIMARY KEY, @@ -87,10 +89,7 @@ impl BlockDbImpl { ) .map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?; - Ok(BlockDbImpl { - db: conn.clone(), - ticker, - }) + Ok(BlockDbImpl { db: conn, ticker }) }) .await } diff --git a/mm2src/mm2_core/src/mm_ctx.rs b/mm2src/mm2_core/src/mm_ctx.rs index b8dcfee85c..0a1afb2eea 100644 --- a/mm2src/mm2_core/src/mm_ctx.rs +++ b/mm2src/mm2_core/src/mm_ctx.rs @@ -204,14 +204,14 @@ impl MmCtx { lazy_static! { static ref DEFAULT: H160 = [0; 20].into(); } - self.rmd160.get_or_init(|| *DEFAULT) + self.rmd160.get().unwrap_or(&*DEFAULT) } pub fn shared_db_id(&self) -> &H160 { lazy_static! { static ref DEFAULT: H160 = [0; 20].into(); } - self.shared_db_id.get_or_init(|| *DEFAULT) + self.shared_db_id.get().unwrap_or(&*DEFAULT) } #[cfg(not(target_arch = "wasm32"))] @@ -346,7 +346,7 @@ impl MmCtx { pub fn spawner(&self) -> MmFutSpawner { MmFutSpawner::new(&self.abortable_system) } /// True if the MarketMaker instance needs to stop. - pub fn is_stopping(&self) -> bool { *self.stop.get_or_init(|| false) } + pub fn is_stopping(&self) -> bool { *self.stop.get().unwrap_or(&false) } pub fn gui(&self) -> Option<&str> { self.conf["gui"].as_str() } diff --git a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs index 49abc5c77f..43eb715324 100644 --- a/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs +++ b/mm2src/mm2_main/tests/docker_tests/swap_watcher_tests.rs @@ -3300,5 +3300,5 @@ fn test_watcher_reward() { let watcher_reward = block_on(utxo_coin.get_maker_watcher_reward(&MmCoinEnum::UtxoCoin(utxo_coin.clone()), None, timeout)).unwrap(); - assert!(matches!(watcher_reward, None)); + assert!(watcher_reward.is_none()); }