1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
crate::ix!();
/**
| Updates a PSBTOutput with information
| from provider.
|
| This fills in the redeem_script, witness_script,
| and hd_keypaths where possible.
|
*/
pub fn update_psbt_output(
provider: &SigningProvider,
psbt: &mut PartiallySignedTransaction,
index: i32) {
let tx: &MutableTransaction = psbt.tx.as_ref().unwrap();
let out: &TxOut = &tx.vout[index as usize];
let psbt_out: &mut PSBTOutput = &mut psbt.outputs[index as usize];
// Fill a SignatureData with output info
let mut sigdata = SignatureData::default();;
psbt_out.fill_signature_data(&mut sigdata);
/**
| Construct a would-be spend of this
| output, to update sigdata with.
|
| Note that ProduceSignature is used to
| fill in metadata (not actual signatures),
| so provider does not need to provide
| any private keys (it can be
| a HidingSigningProvider).
*/
let creator: MutableTransactionSignatureCreator
= MutableTransactionSignatureCreator::new(
tx,
0,
&out.n_value,
SIGHASH_ALL.try_into().unwrap()
);
produce_signature(
provider,
&creator,
&out.script_pub_key,
&mut sigdata
);
// Put redeem_script, witness_script, key
// paths, into PSBTOutput.
psbt_out.from_signature_data(&sigdata);
}