From: 志宇 Date: Thu, 10 Jul 2025 03:04:24 +0000 (+0000) Subject: chore: Make clippy happy X-Git-Tag: bitcoind_rpc-0.21.0~12^2~1 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/-electrum/static/gitweb.js?a=commitdiff_plain;h=cb7a980b846685bbe38d7ff9b12d11cbf529df76;p=bdk chore: Make clippy happy --- diff --git a/crates/bitcoind_rpc/examples/filter_iter.rs b/crates/bitcoind_rpc/examples/filter_iter.rs index b4ca0bff..61422f64 100644 --- a/crates/bitcoind_rpc/examples/filter_iter.rs +++ b/crates/bitcoind_rpc/examples/filter_iter.rs @@ -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(()) } diff --git a/crates/bitcoind_rpc/src/lib.rs b/crates/bitcoind_rpc/src/lib.rs index 0f3b6930..250ff430 100644 --- a/crates/bitcoind_rpc/src/lib.rs +++ b/crates/bitcoind_rpc/src/lib.rs @@ -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" ); } } diff --git a/crates/bitcoind_rpc/tests/test_emitter.rs b/crates/bitcoind_rpc/tests/test_emitter.rs index c6b0c86a..9bfa1289 100644 --- a/crates/bitcoind_rpc/tests/test_emitter.rs +++ b/crates/bitcoind_rpc/tests/test_emitter.rs @@ -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}", ); } diff --git a/crates/chain/src/indexer/keychain_txout.rs b/crates/chain/src/indexer/keychain_txout.rs index 44ebc796..dceb25a9 100644 --- a/crates/chain/src/indexer/keychain_txout.rs +++ b/crates/chain/src/indexer/keychain_txout.rs @@ -594,7 +594,7 @@ impl KeychainTxOutIndex { 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 KeychainTxOutIndex { 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}"); } } } diff --git a/crates/chain/src/rusqlite_impl.rs b/crates/chain/src/rusqlite_impl.rs index a994ae18..38f76b12 100644 --- a/crates/chain/src/rusqlite_impl.rs +++ b/crates/chain/src/rusqlite_impl.rs @@ -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> { - 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}"), } } } diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 806b14c0..713b6268 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -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 TxGraph { 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); diff --git a/crates/chain/tests/test_indexed_tx_graph.rs b/crates/chain/tests/test_indexed_tx_graph.rs index ee95dde7..ca0eaf67 100644 --- a/crates/chain/tests/test_indexed_tx_graph.rs +++ b/crates/chain/tests/test_indexed_tx_graph.rs @@ -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( diff --git a/crates/chain/tests/test_local_chain.rs b/crates/chain/tests/test_local_chain.rs index a0b8220e..8adbce4a 100644 --- a/crates/chain/tests/test_local_chain.rs +++ b/crates/chain/tests/test_local_chain.rs @@ -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",); } } diff --git a/crates/chain/tests/test_tx_graph.rs b/crates/chain/tests/test_tx_graph.rs index 0a9a567b..685b62c6 100644 --- a/crates/chain/tests/test_tx_graph.rs +++ b/crates/chain/tests/test_tx_graph.rs @@ -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::>(), - "{}: 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" ); } } diff --git a/crates/core/src/spk_client.rs b/crates/core/src/spk_client.rs index dc6f36dc..6f45aed5 100644 --- a/crates/core/src/spk_client.rs +++ b/crates/core/src/spk_client.rs @@ -26,13 +26,13 @@ impl 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}'"), } } } diff --git a/crates/electrum/src/bdk_electrum_client.rs b/crates/electrum/src/bdk_electrum_client.rs index dde9efeb..b0b30ea6 100644 --- a/crates/electrum/src/bdk_electrum_client.rs +++ b/crates/electrum/src/bdk_electrum_client.rs @@ -512,7 +512,7 @@ impl BdkElectrumClient { 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), ], ); diff --git a/crates/electrum/tests/test_electrum.rs b/crates/electrum/tests/test_electrum.rs index 5302e62f..ec226ab6 100644 --- a/crates/electrum/tests/test_electrum.rs +++ b/crates/electrum/tests/test_electrum.rs @@ -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}", ); } diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 6c4966bf..60588376 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -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 { diff --git a/crates/file_store/src/lib.rs b/crates/file_store/src/lib.rs index 8703b1a4..8b76473d 100644 --- a/crates/file_store/src/lib.rs +++ b/crates/file_store/src/lib.rs @@ -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}"), } } } diff --git a/crates/file_store/src/store.rs b/crates/file_store/src/store.rs index 12843589..da1fda0b 100644 --- a/crates/file_store/src/store.rs +++ b/crates/file_store/src/store.rs @@ -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 { diff --git a/examples/example_cli/src/lib.rs b/examples/example_cli/src/lib.rs index d70ee125..db5f31d0 100644 --- a/examples/example_cli/src/lib.rs +++ b/examples/example_cli/src/lib.rs @@ -488,12 +488,12 @@ pub fn handle_commands( ..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( title_str: &'a str, items: impl IntoIterator, ) { - 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) -> anyhow::Result<()> let (internal_descriptor, internal_keymap) = >::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!( diff --git a/examples/example_electrum/src/main.rs b/examples/example_electrum/src/main.rs index 3043cd5f..01d11e78 100644 --- a/examples/example_electrum/src/main.rs +++ b/examples/example_electrum/src/main.rs @@ -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( diff --git a/examples/example_esplora/src/main.rs b/examples/example_esplora/src/main.rs index 9b810554..f41d2536 100644 --- a/examples/example_esplora/src/main.rs +++ b/examples/example_esplora/src/main.rs @@ -153,9 +153,9 @@ fn main() -> anyhow::Result<()> { let mut once = BTreeSet::::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(); });