]> Untitled Git - bdk/commitdiff
Fix Clippy Rust 1.65
authorYuki Kishimoto <yukikishimoto@protonmail.com>
Thu, 8 Dec 2022 12:40:50 +0000 (13:40 +0100)
committerYuki Kishimoto <yukikishimoto@protonmail.com>
Sat, 7 Jan 2023 14:08:37 +0000 (15:08 +0100)
src/blockchain/any.rs
src/blockchain/compact_filters/mod.rs
src/blockchain/compact_filters/store.rs
src/blockchain/electrum.rs
src/blockchain/esplora/async.rs
src/blockchain/esplora/blocking.rs
src/blockchain/mod.rs
src/blockchain/rpc.rs
src/descriptor/policy.rs
src/wallet/mod.rs

index 1d1a407ddfdc6531031aed8c48373368bfd76ea2..38b5f117f9af5375dc6b62c8cd7820d16338c681 100644 (file)
@@ -131,7 +131,7 @@ impl GetBlockHash for AnyBlockchain {
 impl WalletSync for AnyBlockchain {
     fn wallet_sync<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error> {
         maybe_await!(impl_inner_method!(
@@ -144,7 +144,7 @@ impl WalletSync for AnyBlockchain {
 
     fn wallet_setup<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error> {
         maybe_await!(impl_inner_method!(
index 9b47df9cf0c8bf064ffd992669ab8f07673940be..41099a52af949cdd5c0df9450cf45fecf28d9521 100644 (file)
@@ -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<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> 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)?
index 9d5731009dc84975a301f3df88e378eebb791d59..6b8d4943bd45b51da77588b8edbba647fcfc9552 100644 (file)
@@ -233,7 +233,7 @@ impl ChainStore<Full> {
             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<Full> {
         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<T: StoreType> ChainStore<T> {
             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,
index 6cbeef5651fc4c83445548f2d8ef2739332be314..845bb64b5b8ab73e0b048d056823f6a6c9bbed08 100644 (file)
@@ -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<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         _progress_update: Box<dyn Progress>,
     ) -> 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::<u32, u32>::new();
         let mut txid_to_height = HashMap::<Txid, u32>::new();
index 900d95376dbe6b852af4cbab64309c046134d4e8..010107409ce113c9639e9987ad419cc03edc9244 100644 (file)
@@ -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<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         _progress_update: Box<dyn Progress>,
     ) -> 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<Txid, Tx> = HashMap::new();
 
index 768573c3f5b71f83f606a5a1dc2e8d58a90f3df8..e75e5456c92c20f70bc1b02044e1a5b7d8ed3ece 100644 (file)
@@ -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<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         _progress_update: Box<dyn Progress>,
     ) -> 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<Txid, Tx> = HashMap::new();
         let batch_update = loop {
index 2502f61b0cf3224e64d1c03f778168286c3b7e72..84a8c2e395502e1ed7d1c46dc303e39839ba1523 100644 (file)
@@ -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<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error>;
 
@@ -156,7 +157,7 @@ pub trait WalletSync {
     /// [`BatchOperations::del_utxo`]: crate::database::BatchOperations::del_utxo
     fn wallet_sync<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error> {
         maybe_await!(self.wallet_setup(database, progress_update))
@@ -377,7 +378,7 @@ impl<T: GetBlockHash> GetBlockHash for Arc<T> {
 impl<T: WalletSync> WalletSync for Arc<T> {
     fn wallet_setup<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error> {
         maybe_await!(self.deref().wallet_setup(database, progress_update))
@@ -385,7 +386,7 @@ impl<T: WalletSync> WalletSync for Arc<T> {
 
     fn wallet_sync<D: BatchDatabase>(
         &self,
-        database: &mut D,
+        database: &RefCell<D>,
         progress_update: Box<dyn Progress>,
     ) -> Result<(), Error> {
         maybe_await!(self.deref().wallet_sync(database, progress_update))
index e5940dec534bb929e16232d52e4e47223e505513..da19e20c67b88ceb50f73bf57d337cd87a58e608 100644 (file)
@@ -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<D>(&self, db: &mut D, prog: Box<dyn Progress>) -> Result<(), Error>
+    fn wallet_setup<D>(&self, db: &RefCell<D>, prog: Box<dyn Progress>) -> 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()?;
index f481f9888dcc03c4d6f9c4db7b66874082793e7f..22e41334b7f95cdf3f61dc88d3845bc17e5af2eb 100644 (file)
@@ -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
index f65440e178ad84158e36f6af039abf163b9b20bc..6cbaf8a60e1f683a34439b9dcfdc6fbe3f715e18 100644 (file)
@@ -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.