@@ -36,18 +36,16 @@ fn construct_tap_witness(
36
36
) -> Result < Vec < Vec < u8 > > , InputError > {
37
37
// When miniscript tries to finalize the PSBT, it doesn't have the full descriptor (which contained a pkh() fragment)
38
38
// and instead resorts to parsing the raw script sig, which is translated into a "expr_raw_pkh" internally.
39
- let mut hash_map : BTreeMap < hash160:: Hash , bitcoin:: key:: XOnlyPublicKey > = BTreeMap :: new ( ) ;
39
+ let mut map : BTreeMap < hash160:: Hash , bitcoin:: key:: XOnlyPublicKey > = BTreeMap :: new ( ) ;
40
40
let psbt_inputs = & sat. psbt . inputs ;
41
41
for psbt_input in psbt_inputs {
42
42
// We need to satisfy or dissatisfy any given key. `tap_key_origin` is the only field of PSBT Input which consist of
43
43
// all the keys added on a descriptor and thus we get keys from it.
44
44
let public_keys = psbt_input. tap_key_origins . keys ( ) ;
45
45
for key in public_keys {
46
46
let bitcoin_key = * key;
47
- // Convert PubKeyHash into Hash::hash160
48
47
let hash = bitcoin_key. to_pubkeyhash ( SigType :: Schnorr ) ;
49
- // Insert pair in HashMap
50
- hash_map. insert ( hash, bitcoin_key) ;
48
+ map. insert ( hash, bitcoin_key) ;
51
49
}
52
50
}
53
51
assert ! ( spk. is_v1_p2tr( ) ) ;
@@ -72,7 +70,7 @@ fn construct_tap_witness(
72
70
script,
73
71
& ExtParams :: allow_all ( ) ,
74
72
) {
75
- Ok ( ms) => ms. substitute_raw_pkh ( & hash_map ) ,
73
+ Ok ( ms) => ms. substitute_raw_pkh ( & map ) ,
76
74
Err ( ..) => continue , // try another script
77
75
} ;
78
76
let mut wit = if allow_mall {
@@ -142,19 +140,15 @@ pub(super) fn prevouts(psbt: &Psbt) -> Result<Vec<&bitcoin::TxOut>, super::Error
142
140
// we want to move the script is probably already created
143
141
// and we want to satisfy it in any way possible.
144
142
fn get_descriptor ( psbt : & Psbt , index : usize ) -> Result < Descriptor < PublicKey > , InputError > {
145
- // Create a HashMap <Hash(Pk),Pk>
146
- let mut hash_map: BTreeMap < hash160:: Hash , PublicKey > = BTreeMap :: new ( ) ;
143
+ let mut map: BTreeMap < hash160:: Hash , PublicKey > = BTreeMap :: new ( ) ;
147
144
let psbt_inputs = & psbt. inputs ;
148
145
for psbt_input in psbt_inputs {
149
146
// Use BIP32 Derviation to get set of all possible keys.
150
147
let public_keys = psbt_input. bip32_derivation . keys ( ) ;
151
148
for key in public_keys {
152
- // Convert bitcoin::secp256k1::PublicKey into just bitcoin::PublicKey
153
149
let bitcoin_key = bitcoin:: PublicKey :: new ( * key) ;
154
- // Convert PubKeyHash into Hash::hash160
155
150
let hash = bitcoin_key. pubkey_hash ( ) . to_raw_hash ( ) ;
156
- // Insert pair in HashMap
157
- hash_map. insert ( hash, bitcoin_key) ;
151
+ map. insert ( hash, bitcoin_key) ;
158
152
}
159
153
}
160
154
@@ -214,7 +208,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
214
208
witness_script,
215
209
& ExtParams :: allow_all ( ) ,
216
210
) ?;
217
- Ok ( Descriptor :: new_wsh ( ms. substitute_raw_pkh ( & hash_map ) ) ?)
211
+ Ok ( Descriptor :: new_wsh ( ms. substitute_raw_pkh ( & map ) ) ?)
218
212
} else {
219
213
Err ( InputError :: MissingWitnessScript )
220
214
}
@@ -241,7 +235,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
241
235
witness_script,
242
236
& ExtParams :: allow_all ( ) ,
243
237
) ?;
244
- Ok ( Descriptor :: new_sh_wsh ( ms. substitute_raw_pkh ( & hash_map ) ) ?)
238
+ Ok ( Descriptor :: new_sh_wsh ( ms. substitute_raw_pkh ( & map ) ) ?)
245
239
} else {
246
240
Err ( InputError :: MissingWitnessScript )
247
241
}
@@ -285,7 +279,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
285
279
& script_pubkey,
286
280
& ExtParams :: allow_all ( ) ,
287
281
) ?;
288
- Ok ( Descriptor :: new_bare ( ms. substitute_raw_pkh ( & hash_map ) ) ?)
282
+ Ok ( Descriptor :: new_bare ( ms. substitute_raw_pkh ( & map ) ) ?)
289
283
}
290
284
}
291
285
0 commit comments