Skip to content

Commit 05ca47f

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. I renamed "PsbtExt::update_desc" to "PsbtExt::update_input_with_descriptor" which uses the same logic as update_with_descriptor internally but additionally does some sanity checks. I removed scanning logic for update_desc because you can do it with find_derivation_index_for_spk.
1 parent f3198dc commit 05ca47f

File tree

3 files changed

+527
-107
lines changed

3 files changed

+527
-107
lines changed

integration_test/src/test_desc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bitcoin::util::{psbt, sighash};
1313
use bitcoin::{self, Amount, OutPoint, SchnorrSig, Script, Transaction, TxIn, TxOut, Txid};
1414
use bitcoincore_rpc::{json, Client, RpcApi};
1515
use miniscript::miniscript::iter;
16-
use miniscript::psbt::PsbtExt;
16+
use miniscript::psbt::{PsbtInputExt, PsbtExt};
1717
use miniscript::{Descriptor, DescriptorTrait, Miniscript, ToPublicKey};
1818
use miniscript::{MiniscriptKey, ScriptContext};
1919
use std::collections::BTreeMap;
@@ -109,10 +109,10 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
109109
script_pubkey: addr.script_pubkey(),
110110
});
111111
let mut input = psbt::Input::default();
112+
input.update_with_descriptor_unchecked(&desc).unwrap();
112113
input.witness_utxo = Some(witness_utxo.clone());
113114
psbt.inputs.push(input);
114115
psbt.outputs.push(psbt::Output::default());
115-
psbt.update_desc(0, &desc, None).unwrap();
116116

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

src/descriptor/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,19 @@ pub enum DescriptorType {
260260
Tr,
261261
}
262262

263+
impl DescriptorType {
264+
/// Whether this is a segwit descriptor.
265+
///
266+
/// Returns true whether it is "native" segwit or "wrapped" p2sh segwit
267+
pub fn is_segwit(&self) -> bool {
268+
use self::DescriptorType::*;
269+
match self {
270+
Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti | Tr => true,
271+
Bare | Sh | Pkh | ShSortedMulti => false,
272+
}
273+
}
274+
}
275+
263276
impl<Pk: MiniscriptKey> Descriptor<Pk> {
264277
// Keys
265278

0 commit comments

Comments
 (0)