Skip to content

Commit 3cb78d8

Browse files
committed
Add PsbtInputExt::update_with_descriptor
This populates all relevant fields in a PSBT input according to a descriptor. Includes previously not yet implemented logic for populating bip32_derivation and tap_key_origins. Also optionally checks the witness_utxo and non_witness_utxo. I renamed "PsbtExt::update_desc" to "PsbtExt::update_inp_with_descriptor" which calls update_with_descriptor internally but retrieves the vout for the input for the non_witness_utxo check automatically. I removed the derivation range functionality because it didn't feel useful (and if it is then it probably belongs in a separate function).
1 parent ef8c048 commit 3cb78d8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

integration_test/src/test_desc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
112112
input.witness_utxo = Some(witness_utxo.clone());
113113
psbt.inputs.push(input);
114114
psbt.outputs.push(psbt::Output::default());
115-
psbt.update_desc(0, &desc, None).unwrap();
115+
psbt.update_inp_with_descriptor(0, &desc).unwrap();
116116

117117
// --------------------------------------------
118118
// Sign the transactions with all keys

src/psbt/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,19 @@ pub trait PsbtExt {
516516
secp: &Secp256k1<C>,
517517
) -> Result<bitcoin::Transaction, Error>;
518518

519-
/// Update a PSBT with the derived descriptor.
519+
/// Update a PSBT with a descriptor.
520520
///
521-
/// Internally, uses [`PsbtInputExt::update_with_descriptor`] and checks that the `witness_utxo`
521+
/// Internally, calls [`update_with_descriptor`] on the input and checks that the `witness_utxo`
522522
/// and `non_witness_utxo` have the correct `script_pubkey` if applicable.
523+
///
524+
/// The `descriptor` **must not have any wildcards** in it otherwise an error will be returned
525+
/// however it can (and should) have extended keys in it.
526+
///
527+
/// [`update_with_descriptor`]: PsbtInputExt::update_with_descriptor
523528
fn update_inp_with_descriptor(
524529
&mut self,
525530
input_index: usize,
526-
desc: &Descriptor<DescriptorPublicKey>,
531+
descriptor: &Descriptor<DescriptorPublicKey>,
527532
) -> Result<(), UtxoUpdateError>;
528533

529534
/// Get the sighash message(data to sign) at input index `idx` based on the sighash
@@ -806,7 +811,8 @@ pub trait PsbtInputExt {
806811
/// spend it.
807812
///
808813
/// If the descriptor contains wilcards or otherwise cannot be transformed into a concrete
809-
/// descriptor an error will returned.
814+
/// descriptor an error will returned. The descriptor *can* (and should) have extended keys in
815+
/// it so PSBT fields like `bip32_derivation` and `tap_key_origins` can be populated.
810816
///
811817
/// You can make sure the descriptor is consistent with the `witness_utxo` and/or
812818
/// `non_witness_utxo` fields of the PSBT by setting `check_witness_utxo` and

0 commit comments

Comments
 (0)