From 3a782b3b0da3ffbb2ec2480feb39c3b9e09149fe Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Thu, 8 Dec 2022 13:40:50 +0100 Subject: [PATCH] Fix Clippy Rust 1.65 --- src/blockchain/any.rs | 4 ++-- src/blockchain/compact_filters/mod.rs | 6 +++++- src/blockchain/compact_filters/store.rs | 6 +++--- src/blockchain/electrum.rs | 6 ++++-- src/blockchain/esplora/async.rs | 6 ++++-- src/blockchain/esplora/blocking.rs | 5 ++++- src/blockchain/mod.rs | 9 +++++---- src/blockchain/rpc.rs | 7 +++++-- src/descriptor/policy.rs | 4 ++-- src/wallet/mod.rs | 15 ++++++--------- 10 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/blockchain/any.rs b/src/blockchain/any.rs index 1d1a407d..38b5f117 100644 --- a/src/blockchain/any.rs +++ b/src/blockchain/any.rs @@ -131,7 +131,7 @@ impl GetBlockHash for AnyBlockchain { impl WalletSync for AnyBlockchain { fn wallet_sync( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { maybe_await!(impl_inner_method!( @@ -144,7 +144,7 @@ impl WalletSync for AnyBlockchain { fn wallet_setup( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { maybe_await!(impl_inner_method!( diff --git a/src/blockchain/compact_filters/mod.rs b/src/blockchain/compact_filters/mod.rs index 9b47df9c..41099a52 100644 --- a/src/blockchain/compact_filters/mod.rs +++ b/src/blockchain/compact_filters/mod.rs @@ -51,6 +51,7 @@ use std::collections::HashSet; use std::fmt; +use std::ops::DerefMut; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; @@ -274,7 +275,7 @@ impl WalletSync for CompactFiltersBlockchain { #[allow(clippy::mutex_atomic)] // Mutex is easier to understand than a CAS loop. fn wallet_setup( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { let first_peer = &self.peers[0]; @@ -322,6 +323,9 @@ impl WalletSync for CompactFiltersBlockchain { cf_sync.prepare_sync(Arc::clone(first_peer))?; + let mut database = database.borrow_mut(); + let database = database.deref_mut(); + let all_scripts = Arc::new( database .iter_script_pubkeys(None)? diff --git a/src/blockchain/compact_filters/store.rs b/src/blockchain/compact_filters/store.rs index 9d573100..6b8d4943 100644 --- a/src/blockchain/compact_filters/store.rs +++ b/src/blockchain/compact_filters/store.rs @@ -233,7 +233,7 @@ impl ChainStore { batch.put_cf( cf_handle, StoreEntry::BlockHeaderIndex(Some(genesis.block_hash())).get_key(), - &0usize.to_be_bytes(), + 0usize.to_be_bytes(), ); store.write(batch)?; } @@ -302,7 +302,7 @@ impl ChainStore { batch.put_cf( new_cf_handle, StoreEntry::BlockHeaderIndex(Some(header.block_hash())).get_key(), - &from.to_be_bytes(), + from.to_be_bytes(), ); batch.put_cf( new_cf_handle, @@ -584,7 +584,7 @@ impl ChainStore { batch.put_cf( cf_handle, StoreEntry::BlockHeaderIndex(Some(header.block_hash())).get_key(), - &(height).to_be_bytes(), + (height).to_be_bytes(), ); batch.put_cf( cf_handle, diff --git a/src/blockchain/electrum.rs b/src/blockchain/electrum.rs index 6cbeef56..845bb64b 100644 --- a/src/blockchain/electrum.rs +++ b/src/blockchain/electrum.rs @@ -25,7 +25,7 @@ //! ``` use std::collections::{HashMap, HashSet}; -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; #[allow(unused_imports)] use log::{debug, error, info, trace}; @@ -117,9 +117,11 @@ impl GetBlockHash for ElectrumBlockchain { impl WalletSync for ElectrumBlockchain { fn wallet_setup( &self, - database: &mut D, + database: &RefCell, _progress_update: Box, ) -> Result<(), Error> { + let mut database = database.borrow_mut(); + let database = database.deref_mut(); let mut request = script_sync::start(database, self.stop_gap)?; let mut block_times = HashMap::::new(); let mut txid_to_height = HashMap::::new(); diff --git a/src/blockchain/esplora/async.rs b/src/blockchain/esplora/async.rs index 900d9537..01010740 100644 --- a/src/blockchain/esplora/async.rs +++ b/src/blockchain/esplora/async.rs @@ -12,7 +12,7 @@ //! Esplora by way of `reqwest` HTTP client. use std::collections::{HashMap, HashSet}; -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; use bitcoin::{Transaction, Txid}; @@ -135,10 +135,12 @@ impl GetBlockHash for EsploraBlockchain { impl WalletSync for EsploraBlockchain { fn wallet_setup( &self, - database: &mut D, + database: &RefCell, _progress_update: Box, ) -> Result<(), Error> { use crate::blockchain::script_sync::Request; + let mut database = database.borrow_mut(); + let database = database.deref_mut(); let mut request = script_sync::start(database, self.stop_gap)?; let mut tx_index: HashMap = HashMap::new(); diff --git a/src/blockchain/esplora/blocking.rs b/src/blockchain/esplora/blocking.rs index 768573c3..e75e5456 100644 --- a/src/blockchain/esplora/blocking.rs +++ b/src/blockchain/esplora/blocking.rs @@ -12,6 +12,7 @@ //! Esplora by way of `ureq` HTTP client. use std::collections::{HashMap, HashSet}; +use std::ops::DerefMut; #[allow(unused_imports)] use log::{debug, error, info, trace}; @@ -117,10 +118,12 @@ impl GetBlockHash for EsploraBlockchain { impl WalletSync for EsploraBlockchain { fn wallet_setup( &self, - database: &mut D, + database: &RefCell, _progress_update: Box, ) -> Result<(), Error> { use crate::blockchain::script_sync::Request; + let mut database = database.borrow_mut(); + let database = database.deref_mut(); let mut request = script_sync::start(database, self.stop_gap)?; let mut tx_index: HashMap = HashMap::new(); let batch_update = loop { diff --git a/src/blockchain/mod.rs b/src/blockchain/mod.rs index 2502f61b..84a8c2e3 100644 --- a/src/blockchain/mod.rs +++ b/src/blockchain/mod.rs @@ -16,6 +16,7 @@ //! [Compact Filters/Neutrino](crate::blockchain::compact_filters), along with a generalized trait //! [`Blockchain`] that can be implemented to build customized backends. +use std::cell::RefCell; use std::collections::HashSet; use std::ops::Deref; use std::sync::mpsc::{channel, Receiver, Sender}; @@ -133,7 +134,7 @@ pub trait WalletSync { /// Populate the internal database with transactions and UTXOs fn wallet_setup( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error>; @@ -156,7 +157,7 @@ pub trait WalletSync { /// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo fn wallet_sync( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { maybe_await!(self.wallet_setup(database, progress_update)) @@ -377,7 +378,7 @@ impl GetBlockHash for Arc { impl WalletSync for Arc { fn wallet_setup( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { maybe_await!(self.deref().wallet_setup(database, progress_update)) @@ -385,7 +386,7 @@ impl WalletSync for Arc { fn wallet_sync( &self, - database: &mut D, + database: &RefCell, progress_update: Box, ) -> Result<(), Error> { maybe_await!(self.deref().wallet_sync(database, progress_update)) diff --git a/src/blockchain/rpc.rs b/src/blockchain/rpc.rs index e5940dec..da19e20c 100644 --- a/src/blockchain/rpc.rs +++ b/src/blockchain/rpc.rs @@ -49,8 +49,9 @@ use bitcoincore_rpc::Auth as RpcAuth; use bitcoincore_rpc::{Client, RpcApi}; use log::{debug, info}; use serde::{Deserialize, Serialize}; +use std::cell::RefCell; use std::collections::{HashMap, HashSet}; -use std::ops::Deref; +use std::ops::{Deref, DerefMut}; use std::path::PathBuf; use std::thread; use std::time::Duration; @@ -192,10 +193,12 @@ impl GetBlockHash for RpcBlockchain { } impl WalletSync for RpcBlockchain { - fn wallet_setup(&self, db: &mut D, prog: Box) -> Result<(), Error> + fn wallet_setup(&self, db: &RefCell, prog: Box) -> Result<(), Error> where D: BatchDatabase, { + let mut db = db.borrow_mut(); + let db = db.deref_mut(); let batch = DbState::new(db, &self.sync_params, &*prog)? .sync_with_core(&self.client, self.is_descriptors)? .as_db_batch()?; diff --git a/src/descriptor/policy.rs b/src/descriptor/policy.rs index f481f988..22e41334 100644 --- a/src/descriptor/policy.rs +++ b/src/descriptor/policy.rs @@ -1197,7 +1197,7 @@ mod test { .unwrap(); assert_matches!(&policy.item, EcdsaSignature(PkOrF::Fingerprint(f)) if f == &fingerprint); - assert_matches!(&policy.contribution, Satisfaction::Complete {condition} if condition.csv == None && condition.timelock == None); + assert_matches!(&policy.contribution, Satisfaction::Complete {condition} if condition.csv.is_none() && condition.timelock.is_none()); } // 2 pub keys descriptor, required 2 prv keys @@ -1346,7 +1346,7 @@ mod test { .unwrap(); assert_matches!(policy.item, EcdsaSignature(PkOrF::Fingerprint(f)) if f == fingerprint); - assert_matches!(policy.contribution, Satisfaction::Complete {condition} if condition.csv == None && condition.timelock == None); + assert_matches!(policy.contribution, Satisfaction::Complete {condition} if condition.csv.is_none() && condition.timelock.is_none()); } // single key, 1 prv and 1 pub key descriptor, required 1 prv keys diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index f65440e1..6cbaf8a6 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -17,7 +17,7 @@ use std::cell::RefCell; use std::collections::HashMap; use std::collections::{BTreeMap, HashSet}; use std::fmt; -use std::ops::{Deref, DerefMut}; +use std::ops::Deref; use std::str::FromStr; use std::sync::Arc; @@ -1719,14 +1719,11 @@ where let max_rounds = if has_wildcard { 100 } else { 1 }; for _ in 0..max_rounds { - let sync_res = - if run_setup { - maybe_await!(blockchain - .wallet_setup(self.database.borrow_mut().deref_mut(), new_progress())) - } else { - maybe_await!(blockchain - .wallet_sync(self.database.borrow_mut().deref_mut(), new_progress())) - }; + let sync_res = if run_setup { + maybe_await!(blockchain.wallet_setup(&self.database, new_progress())) + } else { + maybe_await!(blockchain.wallet_sync(&self.database, new_progress())) + }; // If the error is the special `MissingCachedScripts` error, we return the number of // scripts we should ensure cached.