Skip to content

Commit 4615555

Browse files
committed
psbt: Add psbt::finalize_extract() shortcut
And drop the `finalize` boolean option for psbt::sign()/psbt::extract(), the intention is clearer with the named functions (psbt::sign_extract() is available too).
1 parent 4784eee commit 4615555

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/stdlib/btc.minsc

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ fn psbt::finalize_witness($psbt, $input_witnesses) = psbt::update($psbt, [
6868
)
6969
]);
7070

71-
fn psbt::sign_extract($psbt, $keys) =
72-
psbt::extract(psbt::finalize(psbt::sign($psbt, $keys)));
71+
fn psbt::finalize_extract($psbt) = psbt::extract(psbt::finalize($psbt));
72+
fn psbt::sign_extract($psbt, $keys) = psbt::extract(psbt::finalize(psbt::sign($psbt, $keys)));
7373

7474
//
7575
// Script utilities

src/stdlib/psbt.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,16 @@ pub mod fns {
110110
Ok((psbt, errors).into())
111111
}
112112

113-
// psbt::sign(Psbt, Xpriv|Array<Xpriv>|Array<SinglePk:SingleSk> sign_keys, Bool finalize=false) -> Psbt
113+
// psbt::sign(Psbt, Xpriv|Array<Xpriv>|Array<SinglePk:SingleSk> sign_keys) -> Psbt
114114
//
115115
// Attempt to sign all transaction inputs, raising an error if any fail.
116116
pub fn sign(args: Array, _: &ScopeRef) -> Result<Value> {
117-
let (mut psbt, keys, finalize): (_, _, Option<bool>) = args.args_into()?;
117+
let (mut psbt, keys) = args.args_into()?;
118118

119119
let (_signed, failed) = sign_psbt(&mut psbt, keys)?;
120120
ensure!(failed.is_empty(), Error::PsbtSigning(failed));
121121
// XXX check signed?
122122

123-
if finalize.unwrap_or(false) {
124-
psbt.finalize_mut(&EC).map_err(Error::PsbtFinalize)?;
125-
}
126-
127123
Ok(psbt.into())
128124
}
129125

@@ -139,15 +135,12 @@ pub mod fns {
139135
Ok((psbt, signed, failed).into())
140136
}
141137

142-
/// psbt::extract(Psbt, Bool finalize=false) -> Transaction
138+
/// psbt::extract(Psbt) -> Transaction
143139
///
144-
/// Extract the PSBT finalized transaction. Will run the Miniscript interpreter sanity checks.
145-
/// Also possible using `tx(Psbt)` (without the `finalize` option, for pre-finalized PSBT only)
140+
/// Extract the PSBT finalized transaction (The PSBT must already be finalized).
141+
/// Will run the Miniscript interpreter sanity checks. Also possible using `tx(Psbt)`.
146142
pub fn extract(args: Array, _: &ScopeRef) -> Result<Value> {
147-
let (mut psbt, finalize): (Psbt, Option<bool>) = args.args_into()?;
148-
if finalize.unwrap_or(false) {
149-
psbt.finalize_mut(&EC).map_err(Error::PsbtFinalize)?;
150-
}
143+
let psbt: Psbt = args.arg_into()?;
151144
// Uses rust-miniscript's PsbtExt::extract(), which only works with Miniscript-compatible Scripts
152145
Ok(psbt.extract(&EC)?.into())
153146
}

0 commit comments

Comments
 (0)