Skip to content

Commit 4c46eb5

Browse files
apoelstranymius
authored andcommitted
Merge rust-bitcoin#978: Backport rust-bitcoin#974 to rust-miniscript@13.x
9e1ced6 chore: remove outdated TODO (nymius) 5248db1 feat: expose `Plan.descriptor` field (nymius) Pull request description: Getting the changes from rust-bitcoin#974 into `rust-miniscript@13.x` is easier and faster than waiting for the next major release. This is a back port of rust-bitcoin#974. ACKs for top commit: apoelstra: ACK 9e1ced6; successfully ran local tests Tree-SHA512: 9885e7bc1ad5cd959ed2fabf0b2534d2de0da195627c7b7407b99ffd5e9a6151c87ea65cbefb19e3d40c8f89abfb3051ada55354dd70b2802305e55d00a1f8db
2 parents 8990b63 + f993094 commit 4c46eb5

6 files changed

Lines changed: 35 additions & 10 deletions

File tree

Cargo-minimal.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ version = "0.0.1"
112112
dependencies = [
113113
"honggfuzz",
114114
"miniscript 12.3.0",
115-
"miniscript 13.0.0",
115+
"miniscript 13.0.1",
116116
"regex",
117117
]
118118

@@ -198,7 +198,7 @@ dependencies = [
198198

199199
[[package]]
200200
name = "miniscript"
201-
version = "13.0.0"
201+
version = "13.0.1"
202202
dependencies = [
203203
"bech32",
204204
"bitcoin",

Cargo-recent.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ version = "0.0.1"
112112
dependencies = [
113113
"honggfuzz",
114114
"miniscript 12.3.0",
115-
"miniscript 13.0.0",
115+
"miniscript 13.0.1",
116116
"regex",
117117
]
118118

@@ -198,7 +198,7 @@ dependencies = [
198198

199199
[[package]]
200200
name = "miniscript"
201-
version = "13.0.0"
201+
version = "13.0.1"
202202
dependencies = [
203203
"bech32",
204204
"bitcoin",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "13.0.0"
3+
version = "13.0.1"
44
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

src/plan.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ pub struct Plan {
217217
pub absolute_timelock: Option<absolute::LockTime>,
218218
/// The relative timelock this plan uses
219219
pub relative_timelock: Option<relative::LockTime>,
220-
221-
pub(crate) descriptor: Descriptor<DefiniteDescriptorKey>,
220+
/// The target descriptor for this plan
221+
pub descriptor: Descriptor<DefiniteDescriptorKey>,
222222
}
223223

224224
impl Plan {
@@ -360,8 +360,6 @@ impl Plan {
360360
data
361361
});
362362

363-
// TODO: TapTree. we need to re-traverse the tree to build it, sigh
364-
365363
let leaf_hash = match data.spend_type {
366364
Some(SpendType::KeySpend { internal_key }) => {
367365
input.tap_internal_key = Some(internal_key);

src/policy/concrete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
346346
///
347347
/// It is **not recommended** to use policy as a stable identifier for a miniscript. You should
348348
/// use the policy compiler once, and then use the miniscript output as a stable identifier. See
349-
/// the compiler document in [`doc/compiler.md`] for more details.
349+
/// the compiler document in `./doc/compiler.md` for more details.
350350
#[cfg(feature = "compiler")]
351351
pub fn compile_to_descriptor<Ctx: ScriptContext>(
352352
&self,

src/psbt/finalizer.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
431431
secp: &Secp256k1<C>,
432432
allow_mall: bool,
433433
) -> Result<(), super::Error> {
434+
// Preserve previously finalized inputs
435+
if psbt.inputs[index].final_script_sig.is_some()
436+
|| psbt.inputs[index].final_script_witness.is_some()
437+
{
438+
return Ok(());
439+
}
440+
434441
let (witness, script_sig) = finalize_input_helper(psbt, index, secp, allow_mall)?;
435442

436443
// Now mutate the psbt input. Note that we cannot error after this point.
@@ -457,6 +464,7 @@ pub(super) fn finalize_input<C: secp256k1::Verification>(
457464

458465
#[cfg(test)]
459466
mod tests {
467+
use bitcoin::{absolute, transaction, Transaction, TxIn};
460468
use hex;
461469

462470
use super::*;
@@ -472,4 +480,23 @@ mod tests {
472480
let expected = Psbt::deserialize(&hex::decode_to_vec("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000107da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae0001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870107232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b20289030108da0400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000").unwrap()).unwrap();
473481
assert_eq!(psbt, expected);
474482
}
483+
484+
#[test]
485+
fn finalize_skips_already_finalized_input() {
486+
let tx = Transaction {
487+
version: transaction::Version::ONE,
488+
lock_time: absolute::LockTime::ZERO,
489+
input: vec![TxIn::default()],
490+
output: vec![],
491+
};
492+
let mut psbt = Psbt::from_unsigned_tx(tx).unwrap();
493+
psbt.inputs[0].final_script_witness = Some(Witness::from_slice(&[vec![1]]));
494+
495+
let expected_input = psbt.inputs[0].clone();
496+
let secp = Secp256k1::verification_only();
497+
498+
psbt.finalize_mut(&secp).unwrap();
499+
500+
assert_eq!(psbt.inputs[0], expected_input);
501+
}
475502
}

0 commit comments

Comments
 (0)