From 8bf77c8f079eb623e3a4875f77a8ecb7354e2403 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Thu, 6 May 2021 13:56:38 +0200 Subject: [PATCH 01/10] Bump version to 0.7.0-rc.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dabfd62b..fa19d868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.6.1-dev" +version = "0.7.0-rc.1" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 47f26447daccd4b691590bf7776cbc52bc934418 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Thu, 6 May 2021 17:11:43 +0200 Subject: [PATCH 02/10] continue signing when finding already finalized inputs --- src/psbt/mod.rs | 19 +++++++++++++++++++ src/wallet/mod.rs | 10 +++++++--- src/wallet/signer.rs | 14 +++++++++++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/psbt/mod.rs b/src/psbt/mod.rs index d83f18a3..ff950db7 100644 --- a/src/psbt/mod.rs +++ b/src/psbt/mod.rs @@ -99,4 +99,23 @@ mod test { }; let _ = wallet.sign(&mut psbt, options).unwrap(); } + + #[test] + fn test_psbt_sign_with_finalized() { + let psbt_bip: PSBT = deserialize(&base64::decode(PSBT_STR).unwrap()).unwrap(); + let (wallet, _, _) = get_funded_wallet(get_test_wpkh()); + let send_to = wallet.get_address(AddressIndex::New).unwrap(); + let mut builder = wallet.build_tx(); + builder.add_recipient(send_to.script_pubkey(), 10_000); + let (mut psbt, _) = builder.finish().unwrap(); + + // add a finalized input + psbt.inputs.push(psbt_bip.inputs[0].clone()); + psbt.global + .unsigned_tx + .input + .push(psbt_bip.global.unsigned_tx.input[0].clone()); + + let _ = wallet.sign(&mut psbt, SignOptions::default()).unwrap(); + } } diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index ac32cb63..53522695 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -861,10 +861,14 @@ where // this helps us doing our job later self.add_input_hd_keypaths(psbt)?; - // If we aren't allowed to use `witness_utxo`, ensure that every input has the - // `non_witness_utxo` + // If we aren't allowed to use `witness_utxo`, ensure that every input but finalized one + // has the `non_witness_utxo` if !sign_options.trust_witness_utxo - && psbt.inputs.iter().any(|i| i.non_witness_utxo.is_none()) + && psbt + .inputs + .iter() + .filter(|i| i.final_script_witness.is_none() && i.final_script_sig.is_none()) + .any(|i| i.non_witness_utxo.is_none()) { return Err(Error::Signer(signer::SignerError::MissingNonWitnessUtxo)); } diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index 04f4d2ad..76ffc3d7 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -206,6 +206,12 @@ impl Signer for DescriptorXKey { return Err(SignerError::InputIndexOutOfRange); } + if psbt.inputs[input_index].final_script_sig.is_some() + || psbt.inputs[input_index].final_script_witness.is_some() + { + return Ok(()); + } + let (public_key, full_path) = match psbt.inputs[input_index] .bip32_derivation .iter() @@ -261,10 +267,16 @@ impl Signer for PrivateKey { secp: &SecpCtx, ) -> Result<(), SignerError> { let input_index = input_index.unwrap(); - if input_index >= psbt.inputs.len() { + if input_index >= psbt.inputs.len() || input_index >= psbt.global.unsigned_tx.input.len() { return Err(SignerError::InputIndexOutOfRange); } + if psbt.inputs[input_index].final_script_sig.is_some() + || psbt.inputs[input_index].final_script_witness.is_some() + { + return Ok(()); + } + let pubkey = self.public_key(&secp); if psbt.inputs[input_index].partial_sigs.contains_key(&pubkey) { return Ok(()); From fad0fe9f300618aac4e19cac1430f47c084671ab Mon Sep 17 00:00:00 2001 From: Tobin Harding Date: Thu, 6 May 2021 16:11:06 +1000 Subject: [PATCH 03/10] Update create transaction example code The transaction builder changed a while ago, looks like some of the example code did not get updated. Update the transaction creation code to use a mutable builder. --- src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f5323b1a..4e9b1d11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,12 +125,15 @@ //! wallet.sync(noop_progress(), None)?; //! //! let send_to = wallet.get_address(New)?; -//! let (psbt, details) = wallet.build_tx() -//! .add_recipient(send_to.script_pubkey(), 50_000) -//! .enable_rbf() -//! .do_not_spend_change() -//! .fee_rate(FeeRate::from_sat_per_vb(5.0)) -//! .finish()?; +//! let (psbt, details) = { +//! let mut builder = wallet.build_tx(); +//! builder +//! .add_recipient(send_to.script_pubkey(), 50_000) +//! .enable_rbf() +//! .do_not_spend_change() +//! .fee_rate(FeeRate::from_sat_per_vb(5.0)) +//! builder.finish()? +//! }; //! //! println!("Transaction details: {:#?}", details); //! println!("Unsigned PSBT: {}", base64::encode(&serialize(&psbt))); From 85aadaccd2ac60471e61025563d630abf84cd5db Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 14:17:46 +0200 Subject: [PATCH 04/10] Update changelog in preparation of `v0.7.0` --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 718b949b..e871332f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v0.7.0] - [v0.6.0] + ### Policy #### Changed Removed `fill_satisfaction` method in favor of enum parameter in `extract_policy` method @@ -338,3 +340,4 @@ final transaction is created by calling `finish` on the builder. [v0.5.0]: https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0 [v0.5.1]: https://github.com/bitcoindevkit/bdk/compare/v0.5.0...v0.5.1 [v0.6.0]: https://github.com/bitcoindevkit/bdk/compare/v0.5.1...v0.6.0 +[v0.6.0]: https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0 From 3c7a1f59181140bd158640940cb3d245c8c1fb1f Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 14:19:00 +0200 Subject: [PATCH 05/10] Bump `testutils-macros` to `v0.6.0` --- testutils-macros/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testutils-macros/Cargo.toml b/testutils-macros/Cargo.toml index ca3b22a2..f78b7f9d 100644 --- a/testutils-macros/Cargo.toml +++ b/testutils-macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk-testutils-macros" -version = "0.5.0" +version = "0.6.0" authors = ["Alekos Filini "] edition = "2018" homepage = "https://bitcoindevkit.org" From d0733e94965894db2442c0a016a10367813812fe Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 14:19:58 +0200 Subject: [PATCH 06/10] Bump version in `src/lib.rs` --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4e9b1d11..0e7f8287 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ //! interact with the bitcoin P2P network. //! //! ```toml -//! bdk = "0.6.0" +//! bdk = "0.7.0" //! ``` //! //! ## Sync the balance of a descriptor From 934ec366d94a3a3bbdac5333ed36311dfda392e8 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 14:20:23 +0200 Subject: [PATCH 07/10] Use the released `testutils-macros` --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fa19d868..3fb78f9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ test-md-docs = ["electrum"] [dev-dependencies] bdk-testutils = "0.4" -bdk-testutils-macros = { path = "testutils-macros"} +bdk-testutils-macros = "0.6" serial_test = "0.4" lazy_static = "1.4" env_logger = "0.7" From 766570abfde68c9a9ef4b00db60db61cec561280 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 14:20:58 +0200 Subject: [PATCH 08/10] Bump version to 0.7.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3fb78f9a..752dc36b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.7.0-rc.1" +version = "0.7.0" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 8f06e458722e289a5fa8f3fc54b7cf73793018a8 Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 15:10:28 +0200 Subject: [PATCH 09/10] Bump version to 0.7.1-dev --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 752dc36b..687e016c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bdk" -version = "0.7.0" +version = "0.7.1-dev" edition = "2018" authors = ["Alekos Filini ", "Riccardo Casatta "] homepage = "https://bitcoindevkit.org" From 3897e297400b2dab430032e9fd0501e0c1b9839a Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 12 May 2021 15:11:20 +0200 Subject: [PATCH 10/10] Fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e871332f..e92c0283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -340,4 +340,4 @@ final transaction is created by calling `finish` on the builder. [v0.5.0]: https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0 [v0.5.1]: https://github.com/bitcoindevkit/bdk/compare/v0.5.0...v0.5.1 [v0.6.0]: https://github.com/bitcoindevkit/bdk/compare/v0.5.1...v0.6.0 -[v0.6.0]: https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0 +[v0.7.0]: https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0