Skip to content

Commit f16ea27

Browse files
OttoAllmendingerllm-git
andcommitted
fix(wasm-utxo): resolve Clippy warnings across multiple files
Fixed various Clippy warnings throughout the codebase: - Replaced `.map(Into::into)` with direct assignment - Avoided unnecessary cloning in tap_script_sigs and wallet key caching - Used copy instead of clone for XpubTriple - Used LeafVersion's to_consensus() value directly without casting - Added #[allow(clippy::too_many_arguments)] where appropriate - Used div_ceil instead of manual ceiling division - Simplified network_upgrade_at_height with iterator methods - Fixed sighash_type usage Issue: BTC-2650 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 3b710f5 commit f16ea27

6 files changed

Lines changed: 19 additions & 17 deletions

File tree

packages/wasm-utxo/src/bip322/bitgo_psbt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ pub fn add_bip322_input(
182182
// Key path spending (MuSig2 with user/bitgo)
183183
let internal_key = script.spend_info.internal_key();
184184
inner_psbt.inputs[input_index].tap_internal_key = Some(internal_key);
185-
inner_psbt.inputs[input_index].tap_merkle_root =
186-
script.spend_info.merkle_root().map(Into::into);
185+
inner_psbt.inputs[input_index].tap_merkle_root = script.spend_info.merkle_root();
187186
inner_psbt.inputs[input_index].tap_key_origins = create_tap_bip32_derivation(
188187
wallet_keys,
189188
chain,
@@ -209,6 +208,7 @@ pub fn add_bip322_input(
209208
/// * `wallet_keys` - The wallet's root keys
210209
/// * `network` - The network
211210
/// * `tag` - Optional custom tag for message hashing
211+
#[allow(clippy::too_many_arguments)]
212212
pub fn verify_bip322_tx_input(
213213
tx: &Transaction,
214214
input_index: usize,

packages/wasm-utxo/src/fixed_script_wallet/bitgo_psbt/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ impl BitGoPsbt {
19861986

19871987
// Copy tap_script_sigs (Taproot script path signatures)
19881988
for (key, sig) in &cloned_input.tap_script_sigs {
1989-
target_input.tap_script_sigs.insert(key.clone(), *sig);
1989+
target_input.tap_script_sigs.insert(*key, *sig);
19901990
}
19911991

19921992
// Copy tap_key_sig (Taproot key path signature)
@@ -2106,7 +2106,7 @@ impl BitGoPsbt {
21062106
.psbt()
21072107
.inputs
21082108
.get(**input_index)
2109-
.map(|input| p2tr_musig2_input::Musig2Input::is_musig2_input(input))
2109+
.map(p2tr_musig2_input::Musig2Input::is_musig2_input)
21102110
.unwrap_or(false);
21112111

21122112
// Don't report "key not found" errors - those are normal for inputs
@@ -2205,7 +2205,7 @@ impl BitGoPsbt {
22052205

22062206
// Copy tap_script_sigs (Taproot script path signatures)
22072207
for (key, sig) in &cloned_input.tap_script_sigs {
2208-
target_input.tap_script_sigs.insert(key.clone(), *sig);
2208+
target_input.tap_script_sigs.insert(*key, *sig);
22092209
}
22102210

22112211
// Copy tap_key_sig (Taproot key path signature)
@@ -2485,6 +2485,7 @@ impl BitGoPsbt {
24852485
/// # Returns
24862486
/// - `Ok(EcdsaSignature)` containing the signature and sighash type
24872487
/// - `Err(String)` if sighash computation fails
2488+
#[allow(clippy::too_many_arguments)]
24882489
fn sign_p2sh_p2pk_input_zcash<C: secp256k1::Signing>(
24892490
psbt: &Psbt,
24902491
input_index: usize,
@@ -2621,7 +2622,7 @@ impl BitGoPsbt {
26212622
input_index,
26222623
redeem_script,
26232624
value,
2624-
ecdsa_sig.sighash_type as u32,
2625+
ecdsa_sig.sighash_type,
26252626
branch_id,
26262627
version_group_id,
26272628
expiry_height,
@@ -2645,7 +2646,7 @@ impl BitGoPsbt {
26452646
input_index,
26462647
redeem_script,
26472648
value,
2648-
ecdsa_sig.sighash_type as u32,
2649+
ecdsa_sig.sighash_type,
26492650
Some(fork_id),
26502651
)
26512652
.map_err(|e| format!("Failed to compute FORKID sighash: {}", e))?;

packages/wasm-utxo/src/fixed_script_wallet/wallet_keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl RootWalletKeys {
102102
{
103103
let cache = self.derivation_cache.borrow();
104104
if let Some(cached) = cache.get(&cache_key) {
105-
return Ok(cached.clone());
105+
return Ok(*cached);
106106
}
107107
}
108108

@@ -128,7 +128,7 @@ impl RootWalletKeys {
128128
if cache.len() >= DERIVATION_CACHE_MAX_SIZE {
129129
cache.clear();
130130
}
131-
cache.insert(cache_key, derived.clone());
131+
cache.insert(cache_key, derived);
132132
}
133133

134134
Ok(derived)

packages/wasm-utxo/src/inscriptions/reveal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn create_inscription_reveal_data(
9797
output_script: output_script.to_bytes(),
9898
reveal_transaction_vsize: reveal_vsize,
9999
tap_leaf_script: TapLeafScript {
100-
leaf_version: LeafVersion::TapScript.to_consensus() as u8,
100+
leaf_version: LeafVersion::TapScript.to_consensus(),
101101
script: script.to_bytes(),
102102
control_block: control_block.serialize(),
103103
},
@@ -238,7 +238,7 @@ fn estimate_reveal_vsize(script: &ScriptBuf, control_block: &ControlBlock) -> us
238238
let total_weight = base_weight + segwit_overhead + witness_weight;
239239

240240
// Virtual size = ceil(weight / 4)
241-
(total_weight + 3) / 4
241+
total_weight.div_ceil(4)
242242
}
243243

244244
#[cfg(test)]

packages/wasm-utxo/src/wasm/bip322.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Bip322Namespace {
4646
/// # Returns
4747
/// The index of the added input
4848
#[wasm_bindgen]
49+
#[allow(clippy::too_many_arguments)]
4950
pub fn add_bip322_input(
5051
psbt: &mut super::fixed_script_wallet::BitGoPsbt,
5152
message: &str,
@@ -97,6 +98,7 @@ impl Bip322Namespace {
9798
/// # Throws
9899
/// Throws an error if verification fails
99100
#[wasm_bindgen]
101+
#[allow(clippy::too_many_arguments)]
100102
pub fn verify_bip322_tx_input(
101103
tx: &super::transaction::WasmTransaction,
102104
input_index: u32,

packages/wasm-utxo/src/zcash/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ impl NetworkUpgrade {
123123
/// Returns `None` if the height is before Overwinter activation.
124124
pub fn network_upgrade_at_height(height: u32, is_mainnet: bool) -> Option<NetworkUpgrade> {
125125
// Iterate in reverse chronological order
126-
for &upgrade in NetworkUpgrade::ALL.iter().rev() {
127-
if height >= upgrade.activation_height(is_mainnet) {
128-
return Some(upgrade);
129-
}
130-
}
131-
None
126+
NetworkUpgrade::ALL
127+
.iter()
128+
.rev()
129+
.find(|&&upgrade| height >= upgrade.activation_height(is_mainnet))
130+
.copied()
132131
}
133132

134133
/// Get the consensus branch ID for a given block height

0 commit comments

Comments
 (0)