From: Steve Myers Date: Mon, 4 Mar 2024 07:19:03 +0000 (-0600) Subject: ci: bump MSRV to 1.63.0 X-Git-Tag: v0.30.0~8 X-Git-Url: http://internal-gitweb-vhost/?a=commitdiff_plain;h=04994e4f7f1073e7bef29528339369994d4b3666;p=bdk ci: bump MSRV to 1.63.0 Fix related clippy errors --- diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index bc2c8844..a3ae6f16 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -18,9 +18,9 @@ jobs: strategy: matrix: rust: - - version: 1.65.0 # STABLE + - version: stable clippy: true - - version: 1.57.0 # MSRV + - version: 1.63.0 # MSRV features: - default - minimal @@ -60,33 +60,17 @@ jobs: - name: Update toolchain run: rustup update - name: Pin dependencies for MSRV - if: matrix.rust.version == '1.57.0' + if: matrix.rust.version == '1.63.0' run: | - cargo update -p log --precise "0.4.18" - cargo update -p tempfile --precise "3.6.0" - cargo update -p hashlink --precise "0.8.1" cargo update -p regex --precise "1.7.3" - cargo update -p zip:0.6.6 --precise "0.6.3" - cargo update -p rustix --precise "0.37.23" - cargo update -p tokio --precise "1.29.1" - cargo update -p tokio-util --precise "0.7.8" - cargo update -p cc --precise "1.0.81" - cargo update -p rustls:0.20.9 --precise "0.20.8" - cargo update -p rustls:0.21.7 --precise "0.21.1" - cargo update -p flate2:1.0.27 --precise "1.0.26" - cargo update -p reqwest --precise "0.11.18" - cargo update -p h2 --precise "0.3.20" - cargo update -p rustls-webpki:0.100.3 --precise "0.100.1" - cargo update -p rustls-webpki:0.101.6 --precise "0.101.1" - cargo update -p byteorder --precise "1.4.3" - cargo update -p webpki --precise "0.22.2" + cargo update -p home --precise "0.5.5" - name: Build - run: cargo build --features ${{ matrix.features }} --no-default-features + run: cargo build --features bitcoin/std,miniscript/std,${{ matrix.features }} --no-default-features - name: Clippy if: ${{ matrix.rust.clippy }} - run: cargo clippy --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings + run: cargo clippy --all-targets --features bitcoin/std,miniscript/std,${{ matrix.features }} --no-default-features -- -D warnings - name: Test - run: cargo test --features ${{ matrix.features }} --no-default-features + run: cargo test --features bitcoin/std,miniscript/std,${{ matrix.features }} --no-default-features test-readme-examples: name: Test README.md examples @@ -109,7 +93,7 @@ jobs: - name: Update toolchain run: rustup update - name: Test - run: cargo test --features test-md-docs --no-default-features -- doctest::ReadmeDoctests + run: cargo test --features bitcoin/std,miniscript/std,test-md-docs --no-default-features -- doctest::ReadmeDoctests test-blockchains: name: Blockchain ${{ matrix.blockchain.features }} @@ -120,19 +104,19 @@ jobs: blockchain: - name: electrum testprefix: blockchain::electrum::test - features: test-electrum,verify + features: test-electrum,verify,bitcoin/std,miniscript/std - name: rpc testprefix: blockchain::rpc::test - features: test-rpc + features: test-rpc,bitcoin/std,miniscript/std - name: rpc-legacy testprefix: blockchain::rpc::test - features: test-rpc-legacy + features: test-rpc-legacy,bitcoin/std,miniscript/std - name: esplora testprefix: esplora - features: test-esplora,use-esplora-async,verify + features: test-esplora,use-esplora-async,verify,bitcoin/std,miniscript/std - name: esplora testprefix: esplora - features: test-esplora,use-esplora-blocking,verify + features: test-esplora,use-esplora-blocking,verify,bitcoin/std,miniscript/std steps: - name: Checkout uses: actions/checkout@v2 @@ -150,7 +134,7 @@ jobs: toolchain: stable override: true - name: Test - run: cargo test --no-default-features --features ${{ matrix.blockchain.features }} ${{ matrix.blockchain.testprefix }}::bdk_blockchain_tests + run: cargo test --no-default-features --features bitcoin/std,miniscript/std,${{ matrix.blockchain.features }} ${{ matrix.blockchain.testprefix }}::bdk_blockchain_tests check-wasm: name: Check WASM @@ -175,7 +159,7 @@ jobs: - run: sudo apt-get update || exit 1 - run: sudo apt-get install -y libclang-common-10-dev clang-10 libc6-dev-i386 || exit 1 - name: Set default toolchain - run: rustup default 1.65.0 # STABLE + run: rustup default stable - name: Set profile run: rustup set profile minimal - name: Add target wasm32 @@ -183,7 +167,7 @@ jobs: - name: Update toolchain run: rustup update - name: Check - run: cargo check --target wasm32-unknown-unknown --features async-interface,use-esplora-async,dev-getrandom-wasm --no-default-features + run: cargo check --target wasm32-unknown-unknown --features bitcoin/no-std,miniscript/no-std,async-interface,use-esplora-async,dev-getrandom-wasm --no-default-features fmt: name: Rust fmt @@ -207,8 +191,8 @@ jobs: strategy: matrix: rust: - - version: 1.65.0 # STABLE - - version: 1.57.0 # MSRV + - version: stable + - version: 1.63.0 # MSRV steps: - name: Checkout uses: actions/checkout@v3 @@ -229,25 +213,9 @@ jobs: - name: Update toolchain run: rustup update - name: Pin dependencies for MSRV - if: matrix.rust.version == '1.57.0' + if: matrix.rust.version == '1.63.0' run: | - cargo update -p log --precise "0.4.18" - cargo update -p tempfile --precise "3.6.0" - cargo update -p hashlink --precise "0.8.1" - cargo update -p regex --precise "1.7.3" - cargo update -p zip:0.6.6 --precise "0.6.3" - cargo update -p rustix --precise "0.37.23" - cargo update -p tokio --precise "1.29.1" - cargo update -p tokio-util --precise "0.7.8" - cargo update -p cc --precise "1.0.81" - cargo update -p rustls:0.20.9 --precise "0.20.8" - cargo update -p rustls:0.21.7 --precise "0.21.1" - cargo update -p flate2:1.0.27 --precise "1.0.26" - cargo update -p reqwest --precise "0.11.18" - cargo update -p h2 --precise "0.3.20" - cargo update -p rustls-webpki:0.100.3 --precise "0.100.1" - cargo update -p rustls-webpki:0.101.6 --precise "0.101.1" - cargo update -p byteorder --precise "1.4.3" - cargo update -p webpki --precise "0.22.2" + cargo update -p regex --precise "1.7.3" + cargo update -p home --precise "0.5.5" - name: Test run: cargo test --features test-hardware-signer diff --git a/Cargo.toml b/Cargo.toml index ed440c43..a2deaaba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "bdk" -version = "0.29.0" -edition = "2018" +version = "0.30.0" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" repository = "https://github.com/bitcoindevkit/bdk" @@ -10,6 +9,8 @@ description = "A modern, lightweight, descriptor-based wallet library" keywords = ["bitcoin", "wallet", "descriptor", "psbt"] readme = "README.md" license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.63" [dependencies] bdk-macros = "^0.6" @@ -24,11 +25,10 @@ rand = "^0.8" sled = { version = "0.34", optional = true } electrum-client = { version = "0.18", optional = true } esplora-client = { version = "0.6", default-features = false, optional = true } -rusqlite = { version = "0.28.0", optional = true } -ahash = { version = "0.7.6", optional = true } +rusqlite = { version = "0.27.0", optional = true } futures = { version = "0.3", optional = true } async-trait = { version = "0.1", optional = true } -rocksdb = { version = "0.14", default-features = false, features = ["snappy"], optional = true } +rocksdb = { version = "0.18", default-features = false, features = ["snappy"], optional = true } cc = { version = ">=1.0.64", optional = true } socks = { version = "0.3", optional = true } hwi = { version = "0.7", optional = true, features = ["miniscript"] } @@ -56,7 +56,7 @@ default = ["std", "key-value-db", "electrum"] # std feature is always required unless building for wasm32-unknown-unknown target # if building for wasm user must add dependencies bitcoin/no-std,miniscript/no-std std = ["bitcoin/std", "miniscript/std"] -sqlite = ["rusqlite", "ahash"] +sqlite = ["rusqlite"] sqlite-bundled = ["sqlite", "rusqlite/bundled"] compact_filters = ["rocksdb", "socks", "cc"] key-value-db = ["sled"] diff --git a/README.md b/README.md index 42eee279..39a1b8ea 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ CI Status API Docs - Rustc Version 1.57.0+ + Rustc Version 1.63.0+ Chat on Discord

@@ -204,45 +204,11 @@ dual licensed as above, without any additional terms or conditions. ## Minimum Supported Rust Version (MSRV) -This library should compile with any combination of features with Rust 1.57.0. +This library should compile with any combination of features with Rust 1.63.0. To build with the MSRV you will need to pin dependencies as follows: ```shell -# log 0.4.19 has MSRV 1.60.0 -cargo update -p log --precise "0.4.18" -# tempfile 3.7.0 has MSRV 1.63.0 -cargo update -p tempfile --precise "3.6.0" -# required for sqlite feature, hashlink 0.8.2 has MSRV 1.61.0 -cargo update -p hashlink --precise "0.8.1" -# required for compact_filters feature, regex after 1.7.3 has MSRV 1.60.0 cargo update -p regex --precise "1.7.3" -# zip 0.6.3 has MSRV 1.59.0 but still works -cargo update -p zip:0.6.6 --precise "0.6.3" -# rustix 0.38.0 has MSRV 1.65.0 -cargo update -p rustix --precise "0.37.23" -# tokio 1.30 has MSRV 1.63.0+ -cargo update -p tokio --precise "1.29.1" -# tokio-util 0.7.9 doesn't build with MSRV 1.57.0 -cargo update -p tokio-util --precise "0.7.8" -# cc 1.0.82 is throwing error with rust 1.57.0, "error[E0599]: no method named `retain_mut`..." -cargo update -p cc --precise "1.0.81" -# rustls 0.20.9 has MSRV 1.60.0+ -cargo update -p rustls:0.20.9 --precise "0.20.8" -# rustls 0.21.2 has MSRV 1.60.0+ -cargo update -p rustls:0.21.7 --precise "0.21.1" -# flate2 1.0.27 has MSRV 1.63.0+ -cargo update -p flate2:1.0.27 --precise "1.0.26" -# reqwest 0.11.19 has MSRV 1.63.0+ -cargo update -p reqwest --precise "0.11.18" -# h2 0.3.21 has MSRV 1.63.0+ -cargo update -p h2 --precise "0.3.20" -# rustls-webpki 0.100.2 has MSRV 1.60+ -cargo update -p rustls-webpki:0.100.3 --precise "0.100.1" -# rustls-webpki 0.101.6 has MSRV 1.60+ -cargo update -p rustls-webpki:0.101.6 --precise "0.101.1" -# byteorder 1.5.0 has MSRV 1.60.0+ -cargo update -p byteorder --precise "1.4.3" -# webpki 0.22.4 requires `ring:0.17.2` which has MSRV 1.61.0+ -cargo update -p webpki --precise "0.22.2" +cargo update -p home --precise "0.5.5" ``` diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..e3b99604 --- /dev/null +++ b/clippy.toml @@ -0,0 +1 @@ +msrv="1.63.0" \ No newline at end of file diff --git a/examples/compact_filters_balance.rs b/examples/compact_filters_balance.rs index ce875b4d..152ab246 100644 --- a/examples/compact_filters_balance.rs +++ b/examples/compact_filters_balance.rs @@ -34,7 +34,7 @@ fn main() -> Result<(), CompactFiltersError> { let descriptor = "wpkh(tpubD6NzVbkrYhZ4X2yy78HWrr1M9NT8dKeWfzNiQqDdMqqa9UmmGztGGz6TaLFGsLfdft5iu32gxq1T4eMNxExNNWzVCpf9Y6JZi5TnqoC9wJq/*)"; let database = MemoryDatabase::default(); - let wallet = Arc::new(Wallet::new(descriptor, None, Network::Testnet, database).unwrap()); + let wallet = Wallet::new(descriptor, None, Network::Testnet, database).unwrap(); wallet.sync(&blockchain, SyncOptions::default()).unwrap(); info!("balance: {}", wallet.get_balance()?); Ok(()) diff --git a/src/blockchain/compact_filters/sync.rs b/src/blockchain/compact_filters/sync.rs index 1e4e36fb..97c04363 100644 --- a/src/blockchain/compact_filters/sync.rs +++ b/src/blockchain/compact_filters/sync.rs @@ -166,7 +166,7 @@ impl CfSync { let filters = cf_filters .into_iter() .enumerate() - .chain(filters_map.into_iter()) + .chain(filters_map) .collect(); status = self .cf_store diff --git a/src/blockchain/electrum.rs b/src/blockchain/electrum.rs index ad7c9a53..70e8eca3 100644 --- a/src/blockchain/electrum.rs +++ b/src/blockchain/electrum.rs @@ -168,7 +168,7 @@ impl WalletSync for ElectrumBlockchain { let needs_block_height = conftime_req .request() .filter_map(|txid| txid_to_height.get(txid).cloned()) - .filter(|height| block_times.get(height).is_none()) + .filter(|height| block_times.contains_key(height)) .take(chunk_size) .collect::>(); @@ -269,7 +269,7 @@ impl<'a, 'b, D: Database> TxCache<'a, 'b, D> { fn save_txs<'c>(&mut self, txids: impl Iterator) -> Result<(), Error> { let mut need_fetch = vec![]; for txid in txids { - if self.cache.get(txid).is_some() { + if self.cache.contains_key(txid) { continue; } else if let Some(transaction) = self.db.get_raw_tx(txid)? { self.cache.insert(*txid, transaction); @@ -295,7 +295,7 @@ impl<'a, 'b, D: Database> TxCache<'a, 'b, D> { } fn get(&self, txid: Txid) -> Option { - self.cache.get(&txid).map(Clone::clone) + self.cache.get(&txid).cloned() } } diff --git a/src/blockchain/script_sync.rs b/src/blockchain/script_sync.rs index e4c46999..bb149c6b 100644 --- a/src/blockchain/script_sync.rs +++ b/src/blockchain/script_sync.rs @@ -419,7 +419,7 @@ impl<'a, D: BatchDatabase> State<'a, D> { txout: output.clone(), keychain, // Is this UTXO in the spent_utxos set? - is_spent: spent_utxos.get(&outpoint).is_some(), + is_spent: spent_utxos.contains(&outpoint), })?; } } @@ -464,11 +464,10 @@ fn make_txs_consistent(txs: &[TransactionDetails]) -> Vec<&TransactionDetails> { } utxo_index - .into_iter() - .map(|(_, tx)| (tx.txid, tx)) + .into_values() + .map(|tx| (tx.txid, tx)) .collect::>() - .into_iter() - .map(|(_, tx)| tx) + .into_values() .chain(coinbase_txs) .collect() } diff --git a/src/database/mod.rs b/src/database/mod.rs index fd835300..ab5075d1 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -188,6 +188,7 @@ pub(crate) trait DatabaseUtils: Database { .map(|o| o.is_some()) } + #[allow(unused)] fn get_raw_tx_or(&self, txid: &Txid, default: D) -> Result, Error> where D: FnOnce() -> Result, Error>, diff --git a/src/descriptor/mod.rs b/src/descriptor/mod.rs index 1ee43e30..dfb7bcc5 100644 --- a/src/descriptor/mod.rs +++ b/src/descriptor/mod.rs @@ -376,26 +376,26 @@ pub(crate) trait DescriptorMeta { fn is_witness(&self) -> bool; fn is_taproot(&self) -> bool; fn get_extended_keys(&self) -> Result>, DescriptorError>; - fn derive_from_hd_keypaths<'s>( + fn derive_from_hd_keypaths( &self, hd_keypaths: &HdKeyPaths, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option; - fn derive_from_tap_key_origins<'s>( + fn derive_from_tap_key_origins( &self, tap_key_origins: &TapKeyOrigins, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option; - fn derive_from_psbt_key_origins<'s>( + fn derive_from_psbt_key_origins( &self, key_origins: BTreeMap, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option; - fn derive_from_psbt_input<'s>( + fn derive_from_psbt_input( &self, psbt_input: &psbt::Input, utxo: Option, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option; } @@ -430,10 +430,10 @@ impl DescriptorMeta for ExtendedDescriptor { Ok(answer) } - fn derive_from_psbt_key_origins<'s>( + fn derive_from_psbt_key_origins( &self, key_origins: BTreeMap, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option { // Ensure that deriving `xpub` with `path` yields `expected` let verify_key = |xpub: &DescriptorXKey, @@ -520,10 +520,10 @@ impl DescriptorMeta for ExtendedDescriptor { }) } - fn derive_from_hd_keypaths<'s>( + fn derive_from_hd_keypaths( &self, hd_keypaths: &HdKeyPaths, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option { // "Convert" an hd_keypaths map to the format required by `derive_from_psbt_key_origins` let key_origins = hd_keypaths @@ -538,10 +538,10 @@ impl DescriptorMeta for ExtendedDescriptor { self.derive_from_psbt_key_origins(key_origins, secp) } - fn derive_from_tap_key_origins<'s>( + fn derive_from_tap_key_origins( &self, tap_key_origins: &TapKeyOrigins, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option { // "Convert" a tap_key_origins map to the format required by `derive_from_psbt_key_origins` let key_origins = tap_key_origins @@ -551,11 +551,11 @@ impl DescriptorMeta for ExtendedDescriptor { self.derive_from_psbt_key_origins(key_origins, secp) } - fn derive_from_psbt_input<'s>( + fn derive_from_psbt_input( &self, psbt_input: &psbt::Input, utxo: Option, - secp: &'s SecpCtx, + secp: &SecpCtx, ) -> Option { if let Some(derived) = self.derive_from_hd_keypaths(&psbt_input.bip32_derivation, secp) { return Some(derived); diff --git a/src/descriptor/template.rs b/src/descriptor/template.rs index 338af696..704a14a0 100644 --- a/src/descriptor/template.rs +++ b/src/descriptor/template.rs @@ -609,7 +609,7 @@ mod test { if let ExtendedDescriptor::Pkh(pkh) = xdesc.0 { let path: Vec = pkh.into_inner().full_derivation_path().unwrap().into(); - let purpose = path.get(0).unwrap(); + let purpose = path.first().unwrap(); assert_matches!(purpose, Hardened { index: 44 }); let coin_type = path.get(1).unwrap(); assert_matches!(coin_type, Hardened { index: 0 }); @@ -623,7 +623,7 @@ mod test { if let ExtendedDescriptor::Pkh(pkh) = tdesc.0 { let path: Vec = pkh.into_inner().full_derivation_path().unwrap().into(); - let purpose = path.get(0).unwrap(); + let purpose = path.first().unwrap(); assert_matches!(purpose, Hardened { index: 44 }); let coin_type = path.get(1).unwrap(); assert_matches!(coin_type, Hardened { index: 1 }); diff --git a/src/keys/mod.rs b/src/keys/mod.rs index d083f467..ee81e8e8 100644 --- a/src/keys/mod.rs +++ b/src/keys/mod.rs @@ -752,7 +752,7 @@ fn expand_multi_keys, Ctx: ScriptContext>( let (key_map, valid_networks) = key_maps_networks.into_iter().fold( (KeyMap::default(), any_network()), |(mut keys_acc, net_acc), (key, net)| { - keys_acc.extend(key.into_iter()); + keys_acc.extend(key); let net_acc = merge_networks(&net_acc, &net); (keys_acc, net_acc) diff --git a/src/lib.rs b/src/lib.rs index 08431455..93179932 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -206,15 +206,15 @@ extern crate serde_json; #[cfg(feature = "hardware-signer")] pub extern crate hwi; -#[cfg(all(feature = "reqwest", feature = "ureq"))] -compile_error!("Features reqwest and ureq are mutually exclusive and cannot be enabled together"); +#[cfg(all(feature = "use-esplora-async", feature = "use-esplora-blocking"))] +compile_error!("Features use-esplora-async and use-esplora-blocking are mutually exclusive and cannot be enabled together"); #[cfg(all(feature = "async-interface", feature = "electrum"))] compile_error!( "Features async-interface and electrum are mutually exclusive and cannot be enabled together" ); -#[cfg(all(feature = "async-interface", feature = "ureq"))] +#[cfg(all(feature = "async-interface", feature = "use-esplora-blocking"))] compile_error!( "Features async-interface and ureq are mutually exclusive and cannot be enabled together" ); diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index 7ee25908..8eaf3112 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -266,20 +266,18 @@ impl CoinSelectionAlgorithm for OldestFirstCoinSelection { .iter() .map(|wu| wu.utxo.outpoint().txid) // fold is used so we can skip db query for txid that already exist in hashmap acc - .fold(Ok(HashMap::new()), |bh_result_acc, txid| { - bh_result_acc.and_then(|mut bh_acc| { - if bh_acc.contains_key(&txid) { - Ok(bh_acc) - } else { - database.get_tx(&txid, false).map(|details| { - bh_acc.insert( - txid, - details.and_then(|d| d.confirmation_time.map(|ct| ct.height)), - ); - bh_acc - }) - } - }) + .try_fold(HashMap::new(), |mut bh_acc, txid| { + if bh_acc.contains_key(&txid) { + Ok(bh_acc) + } else { + database.get_tx(&txid, false).map(|details| { + bh_acc.insert( + txid, + details.and_then(|d| d.confirmation_time.map(|ct| ct.height)), + ); + bh_acc + }) + } })?; // We put the "required UTXOs" first and make sure the optional UTXOs are sorted from @@ -771,11 +769,7 @@ mod test { } fn get_test_utxos() -> Vec { - vec![ - utxo(100_000, 0), - utxo(FEE_AMOUNT as u64 - 40, 1), - utxo(200_000, 2), - ] + vec![utxo(100_000, 0), utxo(FEE_AMOUNT - 40, 1), utxo(200_000, 2)] } fn setup_database_and_get_oldest_first_test_utxos( @@ -890,7 +884,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 250_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( &database, utxos, @@ -913,7 +907,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( &database, utxos, @@ -936,7 +930,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = LargestFirstCoinSelection::default() + let result = LargestFirstCoinSelection .coin_select( &database, vec![], @@ -960,7 +954,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 500_000 + FEE_AMOUNT; - LargestFirstCoinSelection::default() + LargestFirstCoinSelection .coin_select( &database, vec![], @@ -980,7 +974,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 250_000 + FEE_AMOUNT; - LargestFirstCoinSelection::default() + LargestFirstCoinSelection .coin_select( &database, vec![], @@ -999,7 +993,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 180_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( &database, vec![], @@ -1058,7 +1052,7 @@ mod test { let target_amount = 180_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( &database, vec![], @@ -1081,7 +1075,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( &database, utxos, @@ -1104,7 +1098,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 20_000 + FEE_AMOUNT; - let result = OldestFirstCoinSelection::default() + let result = OldestFirstCoinSelection .coin_select( &database, vec![], @@ -1128,7 +1122,7 @@ mod test { let drain_script = ScriptBuf::default(); let target_amount = 600_000 + FEE_AMOUNT; - OldestFirstCoinSelection::default() + OldestFirstCoinSelection .coin_select( &database, vec![], @@ -1149,7 +1143,7 @@ mod test { let target_amount: u64 = utxos.iter().map(|wu| wu.utxo.txout().value).sum::() - 50; let drain_script = ScriptBuf::default(); - OldestFirstCoinSelection::default() + OldestFirstCoinSelection .coin_select( &database, vec![], diff --git a/src/wallet/export.rs b/src/wallet/export.rs index d7c68f7e..bd6595d7 100644 --- a/src/wallet/export.rs +++ b/src/wallet/export.rs @@ -59,6 +59,7 @@ //! # Ok::<_, bdk::Error>(()) //! ``` +use std::fmt::{Display, Formatter}; use std::str::FromStr; use serde::{Deserialize, Serialize}; @@ -86,9 +87,9 @@ pub struct FullyNodedExport { pub label: String, } -impl ToString for FullyNodedExport { - fn to_string(&self) -> String { - serde_json::to_string(self).unwrap() +impl Display for FullyNodedExport { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", serde_json::to_string(self).unwrap()) } } diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 82feacec..485cb9ce 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -1851,7 +1851,7 @@ pub fn get_funded_wallet( .database .borrow_mut() .set_script_pubkey( - &bitcoin::Address::from_str(&tx_meta.output.get(0).unwrap().to_address) + &bitcoin::Address::from_str(&tx_meta.output.first().unwrap().to_address) .unwrap() .assume_checked() .script_pubkey(), @@ -5266,7 +5266,7 @@ pub(crate) mod test { .values() .map(|(script, version)| TapLeafHash::from_script(script, *version)) .collect(); - let included_script_leaves = vec![script_leaves.pop().unwrap()]; + let included_script_leaves = [script_leaves.pop().unwrap()]; let excluded_script_leaves = script_leaves; assert!( diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index 6197040a..4ecbc311 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -805,9 +805,10 @@ pub struct SignOptions { } /// Customize which taproot script-path leaves the signer should sign. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Default)] pub enum TapLeavesOptions { /// The signer will sign all the leaves it has a key for. + #[default] All, /// The signer won't sign leaves other than the ones specified. Note that it could still ignore /// some of the specified leaves, if it doesn't have the right key to sign them. @@ -818,12 +819,6 @@ pub enum TapLeavesOptions { None, } -impl Default for TapLeavesOptions { - fn default() -> Self { - TapLeavesOptions::All - } -} - #[allow(clippy::derivable_impls)] impl Default for SignOptions { fn default() -> Self { diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index b7eed0d4..fff70407 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -552,7 +552,7 @@ impl<'a, D: BatchDatabase, Cs: CoinSelectionAlgorithm, Ctx: TxBuilderContext> /// /// This will be used to: /// 1. Set the nLockTime for preventing fee sniping. - /// **Note**: This will be ignored if you manually specify a nlocktime using [`TxBuilder::nlocktime`]. + /// **Note**: This will be ignored if you manually specify a nlocktime using [`TxBuilder::nlocktime`]. /// 2. Decide whether coinbase outputs are mature or not. If the coinbase outputs are not /// mature at `current_height`, we ignore them in the coin selection. /// If you want to create a transaction that spends immature coinbase inputs, manually @@ -680,9 +680,10 @@ impl<'a, D: BatchDatabase> TxBuilder<'a, D, DefaultCoinSelectionAlgorithm, BumpF } /// Ordering of the transaction's inputs and outputs -#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)] +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy, Default)] pub enum TxOrdering { /// Randomized (default) + #[default] Shuffle, /// Unchanged Untouched, @@ -690,12 +691,6 @@ pub enum TxOrdering { Bip69Lexicographic, } -impl Default for TxOrdering { - fn default() -> Self { - TxOrdering::Shuffle - } -} - impl TxOrdering { /// Sort transaction inputs and outputs by [`TxOrdering`] variant pub fn sort_tx(&self, tx: &mut Transaction) { @@ -755,9 +750,10 @@ impl RbfValue { } /// Policy regarding the use of change outputs when creating a transaction -#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)] +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy, Default)] pub enum ChangeSpendPolicy { /// Use both change and non-change outputs (default) + #[default] ChangeAllowed, /// Only use change outputs (see [`TxBuilder::only_spend_change`]) OnlyChange, @@ -765,12 +761,6 @@ pub enum ChangeSpendPolicy { ChangeForbidden, } -impl Default for ChangeSpendPolicy { - fn default() -> Self { - ChangeSpendPolicy::ChangeAllowed - } -} - impl ChangeSpendPolicy { pub(crate) fn is_satisfied_by(&self, utxo: &LocalUtxo) -> bool { match self {