add try_finalize to SignOptions
This commit is contained in:
parent
c2e4ba8cbd
commit
e3a17f67d9
@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Signing Taproot PSBTs (key spend and script spend)
|
- Signing Taproot PSBTs (key spend and script spend)
|
||||||
- Support for `tr()` descriptors in the `descriptor!()` macro
|
- Support for `tr()` descriptors in the `descriptor!()` macro
|
||||||
- Add support for Bitcoin Core 23.0 when using the `rpc` blockchain
|
- Add support for Bitcoin Core 23.0 when using the `rpc` blockchain
|
||||||
- Add `remove_partial_sigs` to `SignOptions`
|
- Add `remove_partial_sigs` and `try_finalize` to `SignOptions`
|
||||||
|
|
||||||
## [v0.18.0] - [v0.17.0]
|
## [v0.18.0] - [v0.17.0]
|
||||||
|
|
||||||
|
@ -1050,7 +1050,11 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attempt to finalize
|
// attempt to finalize
|
||||||
self.finalize_psbt(psbt, sign_options)
|
if sign_options.try_finalize {
|
||||||
|
self.finalize_psbt(psbt, sign_options)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the spending policies for the wallet's descriptor
|
/// Return the spending policies for the wallet's descriptor
|
||||||
@ -3911,6 +3915,40 @@ pub(crate) mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_try_finalize_sign_option() {
|
||||||
|
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
|
||||||
|
|
||||||
|
for try_finalize 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;
|
||||||
|
|
||||||
|
let finalized = wallet
|
||||||
|
.sign(
|
||||||
|
&mut psbt,
|
||||||
|
SignOptions {
|
||||||
|
try_finalize: *try_finalize,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
psbt.inputs.iter().for_each(|input| {
|
||||||
|
if *try_finalize {
|
||||||
|
assert!(finalized);
|
||||||
|
assert!(input.final_script_sig.is_some());
|
||||||
|
assert!(input.final_script_witness.is_some());
|
||||||
|
} else {
|
||||||
|
assert!(!finalized);
|
||||||
|
assert!(input.final_script_sig.is_none());
|
||||||
|
assert!(input.final_script_witness.is_none());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sign_nonstandard_sighash() {
|
fn test_sign_nonstandard_sighash() {
|
||||||
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;
|
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;
|
||||||
|
@ -671,6 +671,10 @@ pub struct SignOptions {
|
|||||||
///
|
///
|
||||||
/// Defaults to `true` which will remove partial_sigs after finalizing.
|
/// Defaults to `true` which will remove partial_sigs after finalizing.
|
||||||
pub remove_partial_sigs: bool,
|
pub remove_partial_sigs: bool,
|
||||||
|
/// Whether to try finalizing psbt input after the inputs are signed.
|
||||||
|
///
|
||||||
|
/// Defaults to `true` which will try fianlizing psbt after inputs are signed.
|
||||||
|
pub try_finalize: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::derivable_impls)]
|
#[allow(clippy::derivable_impls)]
|
||||||
@ -681,6 +685,7 @@ impl Default for SignOptions {
|
|||||||
assume_height: None,
|
assume_height: None,
|
||||||
allow_all_sighashes: false,
|
allow_all_sighashes: false,
|
||||||
remove_partial_sigs: true,
|
remove_partial_sigs: true,
|
||||||
|
try_finalize: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user