Skip to content

Commit 2c73c41

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): enhance code readability and multisig iteration
Remove unnecessary blank line in cashaddr module's test section and refactor multisig script parsing to use iterator methods instead of index-based loops for better readability and safer iteration. Issue: BTC-2652 Co-authored-by: llm-git <[email protected]>
1 parent 88176a6 commit 2c73c41

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

packages/wasm-utxo/src/address/cashaddr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ mod tests {
457457
///
458458
/// Using bech32 crate's `ByteIterExt::bytes_to_fes()` or checksum functions would fail these tests
459459
/// because they implement Bech32/Bech32m logic, not CashAddr logic.
460-
461460
// Test vector: 20-byte P2PKH payload
462461
const TEST_HASH_20: &str = "F5BF48B397DAE70BE82B3CCA4793F8EB2B6CDAC9";
463462

packages/wasm-utxo/src/fixed_script_wallet/wallet_scripts/checkmultisig.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ pub fn parse_multisig_script_2_of_3(script: &ScriptBuf) -> Result<PubTriple, Str
5151

5252
// Extract the three public keys
5353
let mut keys = Vec::new();
54-
for i in 1..4 {
55-
match &instructions[i] {
54+
for (idx, instruction) in instructions.iter().enumerate().skip(1).take(3) {
55+
match instruction {
5656
Instruction::PushBytes(bytes) => {
5757
let key = CompressedPublicKey::from_slice(bytes.as_bytes()).map_err(|e| {
5858
format!(
5959
"Failed to parse compressed public key at position {}: {}",
60-
i, e
60+
idx, e
6161
)
6262
})?;
6363
keys.push(key);
6464
}
6565
_ => {
6666
return Err(format!(
6767
"Instruction at position {} should be a push bytes instruction",
68-
i
68+
idx
6969
));
7070
}
7171
}

0 commit comments

Comments
 (0)