]> Untitled Git - bdk/commitdiff
add remove_partial_sigs to SignOptions
authorKaFai Choi <kafai@river.com>
Sun, 29 May 2022 03:53:37 +0000 (10:53 +0700)
committerKaFai Choi <kafai@river.com>
Wed, 6 Jul 2022 10:10:36 +0000 (17:10 +0700)
CHANGELOG.md
src/wallet/mod.rs
src/wallet/signer.rs

index 7eaf9bffd19bf5398afe75c08b029e6b50f13dca..e89ad8ddc932b43ee345bc8a94cb5bc5e2f94ed0 100644 (file)
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   - Signing Taproot PSBTs (key spend and script spend)
   - Support for `tr()` descriptors in the `descriptor!()` macro
 - Add support for Bitcoin Core 23.0 when using the `rpc` blockchain
+- Add `remove_partial_sigs` to `SignOptions`
 
 ## [v0.18.0] - [v0.17.0]
 
index 6d2ff385eda5fada4cc8863cb6239deeaabe6066..5adcf831223632799ad31bc73d5d7b642b68572c 100644 (file)
@@ -1161,6 +1161,9 @@ where
                             let psbt_input = &mut psbt.inputs[n];
                             psbt_input.final_script_sig = Some(tmp_input.script_sig);
                             psbt_input.final_script_witness = Some(tmp_input.witness);
+                            if sign_options.remove_partial_sigs {
+                                psbt_input.partial_sigs.clear();
+                            }
                         }
                         Err(e) => {
                             debug!("satisfy error {:?} for input {}", e, n);
@@ -3878,6 +3881,36 @@ pub(crate) mod test {
         )
     }
 
+    #[test]
+    fn test_remove_partial_sigs_after_finalize_sign_option() {
+        let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
+
+        for remove_partial_sigs in &[true, false] {
+            let addr = wallet.get_address(New).unwrap();
+            let mut builder = wallet.build_tx();
+            builder.drain_to(addr.script_pubkey()).drain_wallet();
+            let mut psbt = builder.finish().unwrap().0;
+
+            assert!(wallet
+                .sign(
+                    &mut psbt,
+                    SignOptions {
+                        remove_partial_sigs: *remove_partial_sigs,
+                        ..Default::default()
+                    },
+                )
+                .unwrap());
+
+            psbt.inputs.iter().for_each(|input| {
+                if *remove_partial_sigs {
+                    assert!(input.partial_sigs.is_empty())
+                } else {
+                    assert!(!input.partial_sigs.is_empty())
+                }
+            });
+        }
+    }
+
     #[test]
     fn test_sign_nonstandard_sighash() {
         let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;
index 96e3034e077f855b216dfe4c53e8211c085cfd42..2267aae39b9e8964295e0ab67015843017405f9a 100644 (file)
@@ -667,6 +667,10 @@ pub struct SignOptions {
     ///
     /// Defaults to `false` which will only allow signing using `SIGHASH_ALL`.
     pub allow_all_sighashes: bool,
+    /// Whether to remove partial_sigs from psbt inputs while finalizing psbt.
+    ///
+    /// Defaults to `true` which will remove partial_sigs after finalizing.
+    pub remove_partial_sigs: bool,
 }
 
 #[allow(clippy::derivable_impls)]
@@ -676,6 +680,7 @@ impl Default for SignOptions {
             trust_witness_utxo: false,
             assume_height: None,
             allow_all_sighashes: false,
+            remove_partial_sigs: true,
         }
     }
 }