Skip to content

Commit

Permalink
Add PsbtInputExt::update_with_descriptor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LLFourn committed Apr 21, 2022
1 parent b702885 commit c8c19b1
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 107 deletions.
4 changes: 2 additions & 2 deletions integration_test/src/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bitcoin::util::{psbt, sighash};
use bitcoin::{self, Amount, OutPoint, SchnorrSig, Script, Transaction, TxIn, TxOut, Txid};
use bitcoincore_rpc::{json, Client, RpcApi};
use miniscript::miniscript::iter;
use miniscript::psbt::PsbtExt;
use miniscript::psbt::{PsbtInputExt, PsbtExt};
use miniscript::{Descriptor, DescriptorTrait, Miniscript, ToPublicKey};
use miniscript::{MiniscriptKey, ScriptContext};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -109,10 +109,10 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: &str) -> Witnes
script_pubkey: addr.script_pubkey(),
});
let mut input = psbt::Input::default();
input.update_with_descriptor_unchecked(&desc).unwrap();
input.witness_utxo = Some(witness_utxo.clone());
psbt.inputs.push(input);
psbt.outputs.push(psbt::Output::default());
psbt.update_desc(0, &desc, None).unwrap();

// --------------------------------------------
// Sign the transactions with all keys
Expand Down
13 changes: 13 additions & 0 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ pub enum DescriptorType {
Tr,
}

impl DescriptorType {
/// Whether this is a segwit descriptor.
///
/// Returns true whether it is "native" segwit or "wrapped" p2sh segwit
pub fn is_segwit(&self) -> bool {
use self::DescriptorType::*;
match self {
Wpkh | ShWpkh | Wsh | ShWsh | ShWshSortedMulti | WshSortedMulti | Tr => true,
Bare | Sh | Pkh | ShSortedMulti => false,
}
}
}

impl<Pk: MiniscriptKey> Descriptor<Pk> {
// Keys

Expand Down
Loading

0 comments on commit c8c19b1

Please # to comment.