Skip to content

Commit 023f13b

Browse files
committed
Fix stale variable names and comments
At some stage, it appears, we have changed from using a `HashMap` to a `BTreeMap` but the variable names and comments still refer to hash map. Note also that these comments are "what" comments (as opposed to "why" comments) so they are not adding an value anyways. Fix stale code by doing: - Remove the "what" comments. - Rename local variables from `hash_map` to plain old `map`
1 parent cef9d46 commit 023f13b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/psbt/finalizer.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ fn construct_tap_witness(
3636
) -> Result<Vec<Vec<u8>>, InputError> {
3737
// When miniscript tries to finalize the PSBT, it doesn't have the full descriptor (which contained a pkh() fragment)
3838
// 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();
4040
let psbt_inputs = &sat.psbt.inputs;
4141
for psbt_input in psbt_inputs {
4242
// We need to satisfy or dissatisfy any given key. `tap_key_origin` is the only field of PSBT Input which consist of
4343
// all the keys added on a descriptor and thus we get keys from it.
4444
let public_keys = psbt_input.tap_key_origins.keys();
4545
for key in public_keys {
4646
let bitcoin_key = *key;
47-
// Convert PubKeyHash into Hash::hash160
4847
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);
5149
}
5250
}
5351
assert!(spk.is_v1_p2tr());
@@ -72,7 +70,7 @@ fn construct_tap_witness(
7270
script,
7371
&ExtParams::allow_all(),
7472
) {
75-
Ok(ms) => ms.substitute_raw_pkh(&hash_map),
73+
Ok(ms) => ms.substitute_raw_pkh(&map),
7674
Err(..) => continue, // try another script
7775
};
7876
let mut wit = if allow_mall {
@@ -142,19 +140,15 @@ pub(super) fn prevouts(psbt: &Psbt) -> Result<Vec<&bitcoin::TxOut>, super::Error
142140
// we want to move the script is probably already created
143141
// and we want to satisfy it in any way possible.
144142
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();
147144
let psbt_inputs = &psbt.inputs;
148145
for psbt_input in psbt_inputs {
149146
// Use BIP32 Derviation to get set of all possible keys.
150147
let public_keys = psbt_input.bip32_derivation.keys();
151148
for key in public_keys {
152-
// Convert bitcoin::secp256k1::PublicKey into just bitcoin::PublicKey
153149
let bitcoin_key = bitcoin::PublicKey::new(*key);
154-
// Convert PubKeyHash into Hash::hash160
155150
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);
158152
}
159153
}
160154

@@ -214,7 +208,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
214208
witness_script,
215209
&ExtParams::allow_all(),
216210
)?;
217-
Ok(Descriptor::new_wsh(ms.substitute_raw_pkh(&hash_map))?)
211+
Ok(Descriptor::new_wsh(ms.substitute_raw_pkh(&map))?)
218212
} else {
219213
Err(InputError::MissingWitnessScript)
220214
}
@@ -241,7 +235,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
241235
witness_script,
242236
&ExtParams::allow_all(),
243237
)?;
244-
Ok(Descriptor::new_sh_wsh(ms.substitute_raw_pkh(&hash_map))?)
238+
Ok(Descriptor::new_sh_wsh(ms.substitute_raw_pkh(&map))?)
245239
} else {
246240
Err(InputError::MissingWitnessScript)
247241
}
@@ -285,7 +279,7 @@ fn get_descriptor(psbt: &Psbt, index: usize) -> Result<Descriptor<PublicKey>, In
285279
&script_pubkey,
286280
&ExtParams::allow_all(),
287281
)?;
288-
Ok(Descriptor::new_bare(ms.substitute_raw_pkh(&hash_map))?)
282+
Ok(Descriptor::new_bare(ms.substitute_raw_pkh(&map))?)
289283
}
290284
}
291285

0 commit comments

Comments
 (0)