]> Untitled Git - bdk/commitdiff
chore: Make clippy happy
author志宇 <hello@evanlinjin.me>
Thu, 10 Jul 2025 03:04:24 +0000 (03:04 +0000)
committer志宇 <hello@evanlinjin.me>
Thu, 10 Jul 2025 03:04:24 +0000 (03:04 +0000)
18 files changed:
crates/bitcoind_rpc/examples/filter_iter.rs
crates/bitcoind_rpc/src/lib.rs
crates/bitcoind_rpc/tests/test_emitter.rs
crates/chain/src/indexer/keychain_txout.rs
crates/chain/src/rusqlite_impl.rs
crates/chain/src/tx_graph.rs
crates/chain/tests/test_indexed_tx_graph.rs
crates/chain/tests/test_local_chain.rs
crates/chain/tests/test_tx_graph.rs
crates/core/src/spk_client.rs
crates/electrum/src/bdk_electrum_client.rs
crates/electrum/tests/test_electrum.rs
crates/esplora/src/blocking_ext.rs
crates/file_store/src/lib.rs
crates/file_store/src/store.rs
examples/example_cli/src/lib.rs
examples/example_electrum/src/main.rs
examples/example_esplora/src/main.rs

index b4ca0bffd1d9deb1f328aea3bba333c3174908f2..61422f64b9df494cc37410ebe1a0f8fcda4996c0 100644 (file)
@@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> {
             // apply relevant blocks
             if let Event::Block(EventInner { height, ref block }) = event {
                 let _ = graph.apply_block_relevant(block, height);
-                println!("Matched block {}", curr);
+                println!("Matched block {curr}");
             }
             if curr % 1000 == 0 {
                 let progress = (curr - start_height) as f32 / blocks_to_scan as f32;
@@ -107,7 +107,7 @@ fn main() -> anyhow::Result<()> {
 
     let unused_spk = graph.index.reveal_next_spk("external").unwrap().0 .1;
     let unused_address = Address::from_script(&unused_spk, NETWORK)?;
-    println!("Next external address: {}", unused_address);
+    println!("Next external address: {unused_address}");
 
     Ok(())
 }
index 0f3b69308b50b1b477ddbeffa6074f5988292df6..250ff430691dfcc2e789bb461aa254030da8b9aa 100644 (file)
@@ -480,8 +480,7 @@ mod test {
             for txid in &mempool_txids {
                 assert!(
                     emitter.expected_mempool_txids.contains(txid),
-                    "Expected txid {:?} missing",
-                    txid
+                    "Expected txid {txid:?} missing"
                 );
             }
         }
@@ -502,15 +501,13 @@ mod test {
             for txid in confirmed_txids {
                 assert!(
                     !emitter.expected_mempool_txids.contains(&txid),
-                    "Expected txid {:?} should have been removed",
-                    txid
+                    "Expected txid {txid:?} should have been removed"
                 );
             }
             for txid in &mempool_txids {
                 assert!(
                     emitter.expected_mempool_txids.contains(txid),
-                    "Expected txid {:?} missing",
-                    txid
+                    "Expected txid {txid:?} missing"
                 );
             }
         }
index c6b0c86ac5349397f522f19c2e23447920d105ae..9bfa128923c59f69acd270887debd18ed448b408 100644 (file)
@@ -408,8 +408,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
                 confirmed: SEND_AMOUNT * (ADDITIONAL_COUNT - reorg_count) as u64,
                 ..Balance::default()
             },
-            "reorg_count: {}",
-            reorg_count,
+            "reorg_count: {reorg_count}",
         );
     }
 
index 44ebc796e5ee28073c404a322bd7bc4f2db22d10..dceb25a9b6252583e3aff8c585effb47b3355fb2 100644 (file)
@@ -594,7 +594,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
                 let _inserted = self
                     .inner
                     .insert_spk((keychain.clone(), new_index), new_spk);
-                debug_assert!(_inserted, "replenish lookahead: must not have existing spk: keychain={:?}, lookahead={}, next_index={}", keychain, lookahead, next_index);
+                debug_assert!(_inserted, "replenish lookahead: must not have existing spk: keychain={keychain:?}, lookahead={lookahead}, next_index={next_index}");
             }
         } else {
             let spk_iter = SpkIterator::new_with_range(descriptor, next_index..stop_index);
@@ -602,7 +602,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
                 let _inserted = self
                     .inner
                     .insert_spk((keychain.clone(), new_index), new_spk);
-                debug_assert!(_inserted, "replenish lookahead: must not have existing spk: keychain={:?}, lookahead={}, next_index={}", keychain, lookahead, next_index);
+                debug_assert!(_inserted, "replenish lookahead: must not have existing spk: keychain={keychain:?}, lookahead={lookahead}, next_index={next_index}");
             }
         }
     }
index a994ae185a01049933e6be3179ec0b322f61445a..38f76b12e09b5347a1a724aab4370d9fbe751d4b 100644 (file)
@@ -22,17 +22,14 @@ pub const SCHEMAS_TABLE_NAME: &str = "bdk_schemas";
 
 /// Initialize the schema table.
 fn init_schemas_table(db_tx: &Transaction) -> rusqlite::Result<()> {
-    let sql = format!("CREATE TABLE IF NOT EXISTS {}( name TEXT PRIMARY KEY NOT NULL, version INTEGER NOT NULL ) STRICT", SCHEMAS_TABLE_NAME);
+    let sql = format!("CREATE TABLE IF NOT EXISTS {SCHEMAS_TABLE_NAME}( name TEXT PRIMARY KEY NOT NULL, version INTEGER NOT NULL ) STRICT");
     db_tx.execute(&sql, ())?;
     Ok(())
 }
 
 /// Get schema version of `schema_name`.
 fn schema_version(db_tx: &Transaction, schema_name: &str) -> rusqlite::Result<Option<u32>> {
-    let sql = format!(
-        "SELECT version FROM {} WHERE name=:name",
-        SCHEMAS_TABLE_NAME
-    );
+    let sql = format!("SELECT version FROM {SCHEMAS_TABLE_NAME} WHERE name=:name");
     db_tx
         .query_row(&sql, named_params! { ":name": schema_name }, |row| {
             row.get::<_, u32>("version")
@@ -46,10 +43,7 @@ fn set_schema_version(
     schema_name: &str,
     schema_version: u32,
 ) -> rusqlite::Result<()> {
-    let sql = format!(
-        "REPLACE INTO {}(name, version) VALUES(:name, :version)",
-        SCHEMAS_TABLE_NAME,
-    );
+    let sql = format!("REPLACE INTO {SCHEMAS_TABLE_NAME}(name, version) VALUES(:name, :version)");
     db_tx.execute(
         &sql,
         named_params! { ":name": schema_name, ":version": schema_version },
@@ -799,7 +793,7 @@ mod test {
                     ":block_hash": Impl(anchor_block.hash),
                 }) {
                     Ok(updated) => assert_eq!(updated, 1),
-                    Err(err) => panic!("update failed: {}", err),
+                    Err(err) => panic!("update failed: {err}"),
                 }
             }
         }
index 806b14c09afa30b599be913c74aef36765f42c79..713b6268e306a91dce07f81a9100beebc3f38581 100644 (file)
@@ -281,8 +281,7 @@ impl fmt::Display for CalculateFeeError {
         match self {
             CalculateFeeError::MissingTxOut(outpoints) => write!(
                 f,
-                "missing `TxOut` for one or more of the inputs of the tx: {:?}",
-                outpoints
+                "missing `TxOut` for one or more of the inputs of the tx: {outpoints:?}",
             ),
             CalculateFeeError::NegativeFee(fee) => write!(
                 f,
@@ -1119,12 +1118,7 @@ impl<A: Anchor> TxGraph<A> {
             if !canonical_tx.tx_node.tx.is_coinbase() {
                 for txin in &canonical_tx.tx_node.tx.input {
                     let _res = canon_spends.insert(txin.previous_output, txid);
-                    assert!(
-                        _res.is_none(),
-                        "tried to replace {:?} with {:?}",
-                        _res,
-                        txid
-                    );
+                    assert!(_res.is_none(), "tried to replace {_res:?} with {txid:?}",);
                 }
             }
             canon_txs.insert(txid, canonical_tx);
index ee95dde7906eab82d1d3daf0c98aedbfa0ccd59a..ca0eaf67019b207c59621eb0d80a6c1f59bd0d37 100644 (file)
@@ -281,7 +281,7 @@ fn test_list_owned_txouts() {
             let chain_tip = local_chain
                 .get(height)
                 .map(|cp| cp.block_id())
-                .unwrap_or_else(|| panic!("block must exist at {}", height));
+                .unwrap_or_else(|| panic!("block must exist at {height}"));
             let txouts = graph
                 .graph()
                 .filter_chain_txouts(
index a0b8220eeb0fcd1a5f18be3718e67fe4f9851eb5..8adbce4af4c0039815e3f86ef49166ab68567bd0 100644 (file)
@@ -371,10 +371,9 @@ fn local_chain_insert_block() {
         assert_eq!(
             chain.insert_block(t.insert.into()),
             t.expected_result,
-            "[{}] unexpected result when inserting block",
-            i,
+            "[{i}] unexpected result when inserting block",
         );
-        assert_eq!(chain, t.expected_final, "[{}] unexpected final chain", i,);
+        assert_eq!(chain, t.expected_final, "[{i}] unexpected final chain",);
     }
 }
 
index 0a9a567b10362ca71b676aa3dab45432b9e868fe..685b62c6e79c6d3c7b1da6fa84b252139a744d37 100644 (file)
@@ -598,7 +598,7 @@ fn test_calculate_fee_on_coinbase() {
 fn test_walk_ancestors() {
     let local_chain = LocalChain::from_blocks(
         (0..=20)
-            .map(|ht| (ht, BlockHash::hash(format!("Block Hash {}", ht).as_bytes())))
+            .map(|ht| (ht, BlockHash::hash(format!("Block Hash {ht}").as_bytes())))
             .collect(),
     )
     .expect("must contain genesis hash");
@@ -935,7 +935,7 @@ fn test_descendants_no_repeat() {
 fn test_chain_spends() {
     let local_chain = LocalChain::from_blocks(
         (0..=100)
-            .map(|ht| (ht, BlockHash::hash(format!("Block Hash {}", ht).as_bytes())))
+            .map(|ht| (ht, BlockHash::hash(format!("Block Hash {ht}").as_bytes())))
             .collect(),
     )
     .expect("must have genesis hash");
@@ -1453,23 +1453,19 @@ fn tx_graph_update_conversion() {
                 .iter()
                 .map(|tx| tx.compute_txid())
                 .collect::<HashSet<Txid>>(),
-            "{}: txs do not match",
-            test_name
+            "{test_name}: txs do not match"
         );
         assert_eq!(
             update.txouts, update_from_tx_graph.txouts,
-            "{}: txouts do not match",
-            test_name
+            "{test_name}: txouts do not match"
         );
         assert_eq!(
             update.anchors, update_from_tx_graph.anchors,
-            "{}: anchors do not match",
-            test_name
+            "{test_name}: anchors do not match"
         );
         assert_eq!(
             update.seen_ats, update_from_tx_graph.seen_ats,
-            "{}: seen_ats do not match",
-            test_name
+            "{test_name}: seen_ats do not match"
         );
     }
 }
index dc6f36dcd30bb64e2f3832084cd75e2873a33e8d..6f45aed5f990aba85062eba78be4daf0064cef9d 100644 (file)
@@ -26,13 +26,13 @@ impl<I: core::fmt::Debug + core::any::Any> core::fmt::Display for SyncItem<'_, I
         match self {
             SyncItem::Spk(i, spk) => {
                 if (i as &dyn core::any::Any).is::<()>() {
-                    write!(f, "script '{}'", spk)
+                    write!(f, "script '{spk}'")
                 } else {
-                    write!(f, "script {:?} '{}'", i, spk)
+                    write!(f, "script {i:?} '{spk}'")
                 }
             }
-            SyncItem::Txid(txid) => write!(f, "txid '{}'", txid),
-            SyncItem::OutPoint(op) => write!(f, "outpoint '{}'", op),
+            SyncItem::Txid(txid) => write!(f, "txid '{txid}'"),
+            SyncItem::OutPoint(op) => write!(f, "outpoint '{op}'"),
         }
     }
 }
index dde9efebd180f95502d8fa87fc1d11afe7ffd6aa..b0b30ea6812802d2725f315de7d339bf096c8528 100644 (file)
@@ -512,7 +512,7 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
             batch.raw(
                 "blockchain.transaction.get_merkle".into(),
                 vec![
-                    electrum_client::Param::String(format!("{:x}", txid)),
+                    electrum_client::Param::String(format!("{txid:x}")),
                     electrum_client::Param::Usize(height),
                 ],
             );
index 5302e62f271a51fd97cea0dc626a3c08e1c0931e..ec226ab61f060cb0d31bc3c807c18996c612608e 100644 (file)
@@ -723,8 +723,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
                 confirmed: SEND_AMOUNT * (REORG_COUNT - depth) as u64,
                 ..Balance::default()
             },
-            "reorg_count: {}",
-            depth,
+            "reorg_count: {depth}",
         );
     }
 
index 6c4966bfb9e844e801e9b447e7834e49aac65deb..60588376140fa56f065a1f57c966c369b6939d17 100644 (file)
@@ -866,10 +866,10 @@ mod test {
                 .iter()
                 .map(|&h| {
                     let anchor_blockhash: BlockHash = bdk_chain::bitcoin::hashes::Hash::hash(
-                        &format!("hash_at_height_{}", h).into_bytes(),
+                        &format!("hash_at_height_{h}").into_bytes(),
                     );
                     let txid: Txid = bdk_chain::bitcoin::hashes::Hash::hash(
-                        &format!("txid_at_height_{}", h).into_bytes(),
+                        &format!("txid_at_height_{h}").into_bytes(),
                     );
                     let anchor = ConfirmationBlockTime {
                         block_id: BlockId {
index 8703b1a4dbe581c9c7683256592900fdcd98566c..8b76473d518d8d4312326e2ebf5c0be5dfc7fe96 100644 (file)
@@ -25,13 +25,12 @@ pub enum StoreError {
 impl core::fmt::Display for StoreError {
     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
         match self {
-            Self::Io(e) => write!(f, "io error trying to read file: {}", e),
+            Self::Io(e) => write!(f, "io error trying to read file: {e}"),
             Self::InvalidMagicBytes { got, expected } => write!(
                 f,
-                "file has invalid magic bytes: expected={:?} got={:?}",
-                expected, got,
+                "file has invalid magic bytes: expected={expected:?} got={got:?}",
             ),
-            Self::Bincode(e) => write!(f, "bincode error while reading entry {}", e),
+            Self::Bincode(e) => write!(f, "bincode error while reading entry {e}"),
         }
     }
 }
index 12843589601dbfc1024afd89af3b41b5bbcf0f8c..da1fda0b9de969ba9f069160d26744ee49ffd210 100644 (file)
@@ -246,7 +246,7 @@ where
             .serialize_into(&mut self.db_file, changeset)
             .map_err(|e| match *e {
                 bincode::ErrorKind::Io(error) => error,
-                unexpected_err => panic!("unexpected bincode error: {}", unexpected_err),
+                unexpected_err => panic!("unexpected bincode error: {unexpected_err}"),
             })?;
 
         Ok(())
@@ -323,7 +323,7 @@ mod test {
                 error: StoreError::Io(e),
                 ..
             }) => assert_eq!(e.kind(), std::io::ErrorKind::UnexpectedEof),
-            unexpected => panic!("unexpected result: {:?}", unexpected),
+            unexpected => panic!("unexpected result: {unexpected:?}"),
         };
     }
 
@@ -342,7 +342,7 @@ mod test {
             }) => {
                 assert_eq!(got, invalid_magic_bytes.as_bytes())
             }
-            unexpected => panic!("unexpected result: {:?}", unexpected),
+            unexpected => panic!("unexpected result: {unexpected:?}"),
         };
     }
 
@@ -372,7 +372,7 @@ mod test {
             }) => {
                 assert_eq!(changeset, Some(test_changesets))
             }
-            unexpected_res => panic!("unexpected result: {:?}", unexpected_res),
+            unexpected_res => panic!("unexpected result: {unexpected_res:?}"),
         }
     }
 
@@ -400,7 +400,7 @@ mod test {
             }) => {
                 assert_eq!(changeset, Some(test_changesets))
             }
-            unexpected_res => panic!("unexpected result: {:?}", unexpected_res),
+            unexpected_res => panic!("unexpected result: {unexpected_res:?}"),
         }
     }
 
@@ -476,7 +476,7 @@ mod test {
         let last_changeset_bytes = bincode_options().serialize(&last_changeset).unwrap();
 
         for short_write_len in 1..last_changeset_bytes.len() - 1 {
-            let file_path = temp_dir.path().join(format!("{}.dat", short_write_len));
+            let file_path = temp_dir.path().join(format!("{short_write_len}.dat"));
 
             // simulate creating a file, writing data where the last write is incomplete
             {
index d70ee1250e5083ec50ebb2cdf03ad10ce672263b..db5f31d0f4b617a96459b4aa98d2ff21cc6cdefb 100644 (file)
@@ -488,12 +488,12 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
                         ..Default::default()
                     })?;
                     let addr = Address::from_script(spk.as_script(), network)?;
-                    println!("[address @ {}] {}", spk_i, addr);
+                    println!("[address @ {spk_i}] {addr}");
                     Ok(())
                 }
                 AddressCmd::Index => {
                     for (keychain, derivation_index) in index.last_revealed_indices() {
-                        println!("{:?}: {}", keychain, derivation_index);
+                        println!("{keychain:?}: {derivation_index}");
                     }
                     Ok(())
                 }
@@ -523,7 +523,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
                 title_str: &'a str,
                 items: impl IntoIterator<Item = (&'a str, Amount)>,
             ) {
-                println!("{}:", title_str);
+                println!("{title_str}:");
                 for (name, amount) in items.into_iter() {
                     println!("    {:<10} {:>12} sats", name, amount.to_sat())
                 }
@@ -932,8 +932,8 @@ fn generate_bip86_helper(network: impl Into<NetworkKind>) -> anyhow::Result<()>
     let (internal_descriptor, internal_keymap) =
         <Descriptor<DescriptorPublicKey>>::parse_descriptor(&secp, internal_desc)?;
     println!("Public");
-    println!("{}", descriptor);
-    println!("{}", internal_descriptor);
+    println!("{descriptor}");
+    println!("{internal_descriptor}");
     println!("\nPrivate");
     println!("{}", descriptor.to_string_with_secret(&keymap));
     println!(
index 3043cd5ff3ac1908a5ee210836777bea340262b8..01d11e78b04ea1609d2fde36f3999e6a0280b6fe 100644 (file)
@@ -169,9 +169,9 @@ fn main() -> anyhow::Result<()> {
                         let mut once = BTreeSet::new();
                         move |k, spk_i, _| {
                             if once.insert(k) {
-                                eprint!("\nScanning {}: {} ", k, spk_i);
+                                eprint!("\nScanning {k}: {spk_i} ");
                             } else {
-                                eprint!("{} ", spk_i);
+                                eprint!("{spk_i} ");
                             }
                             io::stdout().flush().expect("must flush");
                         }
@@ -213,7 +213,7 @@ fn main() -> anyhow::Result<()> {
                     .chain_tip(chain_tip.clone())
                     .inspect(|item, progress| {
                         let pc = (100 * progress.consumed()) as f32 / progress.total() as f32;
-                        eprintln!("[ SCANNING {:03.0}% ] {}", pc, item);
+                        eprintln!("[ SCANNING {pc:03.0}% ] {item}");
                     });
 
             request = request.expected_spk_txids(graph.list_expected_spk_txids(
index 9b81055413e4c64c7256d7cef81a7739351c03d2..f41d2536e3d262ce9f5ef310c91e5bae088d9513 100644 (file)
@@ -153,9 +153,9 @@ fn main() -> anyhow::Result<()> {
                         let mut once = BTreeSet::<Keychain>::new();
                         move |keychain, spk_i, _| {
                             if once.insert(keychain) {
-                                eprint!("\nscanning {}: ", keychain);
+                                eprint!("\nscanning {keychain}: ");
                             }
-                            eprint!("{} ", spk_i);
+                            eprint!("{spk_i} ");
                             // Flush early to ensure we print at every iteration.
                             let _ = io::stderr().flush();
                         }
@@ -215,7 +215,7 @@ fn main() -> anyhow::Result<()> {
                     .chain_tip(local_tip.clone())
                     .inspect(|item, progress| {
                         let pc = (100 * progress.consumed()) as f32 / progress.total() as f32;
-                        eprintln!("[ SCANNING {:03.0}% ] {}", pc, item);
+                        eprintln!("[ SCANNING {pc:03.0}% ] {item}");
                         // Flush early to ensure we print at every iteration.
                         let _ = io::stderr().flush();
                     });