Skip to content

Commit 9f55699

Browse files
VictorLuxclaude
andcommitted
fix: Resolve 21 Rust 1.93.0 Clippy lints in zipherx-storage
- Rename from_str() to parse() on TxType/TxStatus to avoid clippy::should_implement_trait (conflicts with std FromStr) - Add #[allow(clippy::too_many_arguments)] on insert_note/insert_transaction - Replace redundant closures |row| row_to_note(row) with row_to_note - Replace redundant closures |row| row_to_tx_record(row) with row_to_tx_record - Replace repeat().take() with repeat_n() in delta_cmu serialization - Replace manual modulo checks with .is_multiple_of() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent adf5daf commit 9f55699

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

crates/zipherx-storage/src/database.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl WalletDatabase {
203203

204204
/// Insert a shielded note. Nullifier is SHA-256 hashed before storage (VUL-009).
205205
/// Uses INSERT OR IGNORE to handle duplicate CMUs from rescanning.
206+
#[allow(clippy::too_many_arguments)]
206207
pub fn insert_note(
207208
&self,
208209
account_id: i64,
@@ -270,7 +271,7 @@ impl WalletDatabase {
270271
conn.query_row(
271272
"SELECT * FROM notes WHERE nullifier = ?1",
272273
params![hashed_nf],
273-
|row| row_to_note(row),
274+
row_to_note,
274275
)
275276
.optional()
276277
.map_err(Into::into)
@@ -282,7 +283,7 @@ impl WalletDatabase {
282283
let mut stmt =
283284
conn.prepare("SELECT * FROM notes WHERE account_id = ?1 AND is_spent = 0")?;
284285
let notes = stmt
285-
.query_map(params![account_id], |row| row_to_note(row))?
286+
.query_map(params![account_id], row_to_note)?
286287
.collect::<Result<Vec<_>, _>>()?;
287288
Ok(notes)
288289
}
@@ -292,7 +293,7 @@ impl WalletDatabase {
292293
let conn = recover_lock(self.conn.lock());
293294
let mut stmt = conn.prepare("SELECT * FROM notes WHERE account_id = ?1")?;
294295
let notes = stmt
295-
.query_map(params![account_id], |row| row_to_note(row))?
296+
.query_map(params![account_id], row_to_note)?
296297
.collect::<Result<Vec<_>, _>>()?;
297298
Ok(notes)
298299
}
@@ -698,6 +699,7 @@ impl WalletDatabase {
698699
// ---------------------------------------------------------------
699700

700701
/// Insert or replace a transaction record.
702+
#[allow(clippy::too_many_arguments)]
701703
pub fn insert_transaction(
702704
&self,
703705
txid: &str,
@@ -739,7 +741,7 @@ impl WalletDatabase {
739741
conn.query_row(
740742
"SELECT * FROM transaction_history WHERE txid = ?1",
741743
params![txid],
742-
|row| row_to_tx_record(row),
744+
row_to_tx_record,
743745
)
744746
.optional()
745747
.map_err(Into::into)
@@ -766,7 +768,7 @@ impl WalletDatabase {
766768
ORDER BY height DESC, id DESC",
767769
)?;
768770
let all_records: Vec<TransactionRecord> = stmt
769-
.query_map([], |row| row_to_tx_record(row))?
771+
.query_map([], row_to_tx_record)?
770772
.collect::<Result<Vec<_>, _>>()?;
771773

772774
// Build set of txids where we SPENT notes (from notes table — authoritative).
@@ -987,7 +989,7 @@ impl WalletDatabase {
987989
let mut stmt =
988990
conn.prepare("SELECT * FROM transaction_history WHERE status = 'pending'")?;
989991
let records = stmt
990-
.query_map([], |row| row_to_tx_record(row))?
992+
.query_map([], row_to_tx_record)?
991993
.collect::<Result<Vec<_>, _>>()?;
992994
Ok(records)
993995
}
@@ -2488,14 +2490,14 @@ fn row_to_tx_record(row: &rusqlite::Row<'_>) -> Result<TransactionRecord, rusqli
24882490
Ok(TransactionRecord {
24892491
id: row.get("id")?,
24902492
txid: row.get("txid")?,
2491-
tx_type: TxType::from_str(&tx_type_str).unwrap_or(TxType::Received),
2493+
tx_type: TxType::parse(&tx_type_str).unwrap_or(TxType::Received),
24922494
amount: row.get::<_, i64>("amount")? as u64,
24932495
fee: row.get::<_, i64>("fee")? as u64,
24942496
address: row.get("address")?,
24952497
memo: row.get("memo")?,
24962498
confirmations: row.get::<_, i64>("confirmations")? as u32,
24972499
timestamp: row.get::<_, Option<i64>>("timestamp")?.map(|t| t as u64),
2498-
status: TxStatus::from_str(&status_str).unwrap_or(TxStatus::Pending),
2500+
status: TxStatus::parse(&status_str).unwrap_or(TxStatus::Pending),
24992501
height: row.get::<_, i64>("height")? as u64,
25002502
})
25012503
}

crates/zipherx-storage/src/delta_cmu.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl DeltaCMUStore {
494494
};
495495
record.extend_from_slice(root_bytes);
496496
if root.len() < 32 {
497-
record.extend(std::iter::repeat(0u8).take(32 - root.len()));
497+
record.extend(std::iter::repeat_n(0u8, 32 - root.len()));
498498
}
499499
// 4 bytes padding
500500
record.extend_from_slice(&[0u8; 4]);
@@ -601,7 +601,7 @@ impl DeltaCMUStore {
601601

602602
let mut file = fs::File::open(&path)?;
603603
let file_size = file.metadata()?.len() as usize;
604-
if file_size % NULLIFIER_RECORD_SIZE != 0 {
604+
if !file_size.is_multiple_of(NULLIFIER_RECORD_SIZE) {
605605
return Err(StorageError::QueryFailed(format!(
606606
"Nullifiers file corrupt: {} bytes not divisible by {}",
607607
file_size, NULLIFIER_RECORD_SIZE
@@ -643,7 +643,7 @@ impl DeltaCMUStore {
643643
return Ok(0);
644644
}
645645
let size = fs::metadata(&path)?.len() as usize;
646-
if size % NULLIFIER_RECORD_SIZE != 0 {
646+
if !size.is_multiple_of(NULLIFIER_RECORD_SIZE) {
647647
return Ok(0);
648648
}
649649
Ok(size / NULLIFIER_RECORD_SIZE)
@@ -739,9 +739,9 @@ fn detect_record_size(file_size: usize) -> usize {
739739
if file_size == 0 {
740740
return OUTPUT_RECORD_SIZE; // empty file — use v2 for new writes
741741
}
742-
if file_size % OUTPUT_RECORD_SIZE == 0 {
742+
if file_size.is_multiple_of(OUTPUT_RECORD_SIZE) {
743743
OUTPUT_RECORD_SIZE // v2 format
744-
} else if file_size % OUTPUT_RECORD_SIZE_V1 == 0 {
744+
} else if file_size.is_multiple_of(OUTPUT_RECORD_SIZE_V1) {
745745
OUTPUT_RECORD_SIZE_V1 // legacy v1 format
746746
} else {
747747
0 // corrupt
@@ -773,28 +773,28 @@ fn serialize_output_record(output: &DeltaOutput) -> Vec<u8> {
773773
let cmu_len = output.cmu.len().min(32);
774774
record.extend_from_slice(&output.cmu[..cmu_len]);
775775
if cmu_len < 32 {
776-
record.extend(std::iter::repeat(0u8).take(32 - cmu_len));
776+
record.extend(std::iter::repeat_n(0u8, 32 - cmu_len));
777777
}
778778

779779
// EPK — pad to 32
780780
let epk_len = output.epk.len().min(32);
781781
record.extend_from_slice(&output.epk[..epk_len]);
782782
if epk_len < 32 {
783-
record.extend(std::iter::repeat(0u8).take(32 - epk_len));
783+
record.extend(std::iter::repeat_n(0u8, 32 - epk_len));
784784
}
785785

786786
// Ciphertext — pad to 580
787787
let ct_len = output.ciphertext.len().min(580);
788788
record.extend_from_slice(&output.ciphertext[..ct_len]);
789789
if ct_len < 580 {
790-
record.extend(std::iter::repeat(0u8).take(580 - ct_len));
790+
record.extend(std::iter::repeat_n(0u8, 580 - ct_len));
791791
}
792792

793793
// Txid — pad to 32 (v2 field)
794794
let txid_len = output.txid.len().min(32);
795795
record.extend_from_slice(&output.txid[..txid_len]);
796796
if txid_len < 32 {
797-
record.extend(std::iter::repeat(0u8).take(32 - txid_len));
797+
record.extend(std::iter::repeat_n(0u8, 32 - txid_len));
798798
}
799799

800800
debug_assert_eq!(record.len(), OUTPUT_RECORD_SIZE);
@@ -816,13 +816,13 @@ fn serialize_nullifier_record(nf: &DeltaNullifier) -> Vec<u8> {
816816
let txid_len = nf.txid.len().min(32);
817817
record.extend_from_slice(&nf.txid[..txid_len]);
818818
if txid_len < 32 {
819-
record.extend(std::iter::repeat(0u8).take(32 - txid_len));
819+
record.extend(std::iter::repeat_n(0u8, 32 - txid_len));
820820
}
821821

822822
let nf_len = nf.nullifier.len().min(32);
823823
record.extend_from_slice(&nf.nullifier[..nf_len]);
824824
if nf_len < 32 {
825-
record.extend(std::iter::repeat(0u8).take(32 - nf_len));
825+
record.extend(std::iter::repeat_n(0u8, 32 - nf_len));
826826
}
827827

828828
debug_assert_eq!(record.len(), NULLIFIER_RECORD_SIZE);

crates/zipherx-storage/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl TxType {
112112
}
113113
}
114114

115-
pub fn from_str(s: &str) -> Option<Self> {
115+
pub fn parse(s: &str) -> Option<Self> {
116116
match s {
117117
"sent" => Some(Self::Sent),
118118
"received" => Some(Self::Received),
@@ -146,7 +146,7 @@ impl TxStatus {
146146
}
147147
}
148148

149-
pub fn from_str(s: &str) -> Option<Self> {
149+
pub fn parse(s: &str) -> Option<Self> {
150150
match s {
151151
"pending" => Some(Self::Pending),
152152
"confirmed" => Some(Self::Confirmed),

0 commit comments

Comments
 (0)