Skip to content

Commit

Permalink
Updating psbt_sign_finalize example with planning module
Browse files Browse the repository at this point in the history
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
  • Loading branch information
Harshil-Jani committed Aug 16, 2023
1 parent 48cebb1 commit 25f8bf5
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions examples/psbt_sign_finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ fn main() {
// transaction's inputs and outputs.
let s = format!(
"wsh(t:or_c(pk({}),v:thresh(1,pkh({}),a:pkh({}),a:pkh({}))))",
keys[0], keys[1], keys[2], keys[3]
keys[0], // key A
keys[1], // key B
keys[2], // key C
keys[3], // key D
);
let bridge_descriptor = Descriptor::from_str(&s).expect("parse descriptor string");
let descriptor = Descriptor::from_str(&s).expect("parse descriptor string");

assert!(bridge_descriptor.sanity_check().is_ok());
assert!(descriptor.sanity_check().is_ok());
println!("descriptor pubkey script: {}", descriptor.script_pubkey());
println!(
"Bridge pubkey script: {}",
bridge_descriptor.script_pubkey()
);
println!(
"Bridge address: {}",
bridge_descriptor.address(Network::Regtest).unwrap()
"descriptor address: {}",
descriptor.address(Network::Regtest).unwrap()
);
println!(
"Weight for witness satisfaction cost {}",
bridge_descriptor.max_weight_to_satisfy().unwrap()
descriptor.max_weight_to_satisfy().unwrap()
);

let master_private_key_str = "cQhdvB3McbBJdx78VSSumqoHQiSXs75qwLptqwxSQBNBMDxafvaw";
Expand Down Expand Up @@ -105,7 +105,7 @@ fn main() {

let amount = 100000000;

let (outpoint, witness_utxo) = get_vout(&depo_tx, &bridge_descriptor.script_pubkey());
let (outpoint, witness_utxo) = get_vout(&depo_tx, &descriptor.script_pubkey());

let all_assets = Descriptor::<DescriptorPublicKey>::from_str(&s)
.unwrap()
Expand Down Expand Up @@ -137,7 +137,7 @@ fn main() {
});

psbt.unsigned_tx.output.push(TxOut {
script_pubkey: bridge_descriptor.script_pubkey(),
script_pubkey: descriptor.script_pubkey(),
value: amount * 4 / 5,
});

Expand All @@ -152,16 +152,14 @@ fn main() {
println!("{:#?}", asset);

// Obtain the Plan based on available Assets
let plan = bridge_descriptor.clone().plan(&asset).unwrap();
let plan = descriptor.clone().plan(&asset).unwrap();

// Creating a PSBT Input
let mut input = psbt::Input::default();

// Update the PSBT input from the result which we have obtained from the Plan.
plan.update_psbt_input(&mut input);
input
.update_with_descriptor_unchecked(&bridge_descriptor)
.unwrap();
input.update_with_descriptor_unchecked(&descriptor).unwrap();
input.witness_utxo = Some(witness_utxo.clone());

// Push the PSBT Input and declare an PSBT Output Structure
Expand Down

0 comments on commit 25f8bf5

Please sign in to comment.