Skip to content

Commit f6ec973

Browse files
committed
Fix CI: clippy warnings, formatting, and remove missing examples
1 parent c4b7d6e commit f6ec973

File tree

6 files changed

+74
-65
lines changed

6 files changed

+74
-65
lines changed

Cargo.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,3 @@ tempfile = "3.8"
3434
name = "validate_transactions"
3535
path = "examples/validate_transactions.rs"
3636

37-
[[example]]
38-
name = "batch_validation"
39-
path = "examples/batch_validation.rs"
40-
41-
[[example]]
42-
name = "compliance_report"
43-
path = "examples/compliance_report.rs"
44-
45-
[[bench]]
46-
name = "validator_benchmark"
47-
harness = false

src/fraud_patterns.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,7 @@ impl FraudDetector {
286286

287287
fn add_to_history(&mut self, transaction: Transaction) {
288288
if let Some(account) = transaction.from_account.clone() {
289-
self.history
290-
.entry(account)
291-
.or_default()
292-
.push(transaction);
289+
self.history.entry(account).or_default().push(transaction);
293290
}
294291
}
295292

src/geographic_risk.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ impl CountryRisk {
3434

3535
/// Check if enhanced due diligence is required
3636
pub fn requires_edd(&self) -> bool {
37-
matches!(self.risk_level, CountryRiskLevel::High | CountryRiskLevel::Prohibited)
37+
matches!(
38+
self.risk_level,
39+
CountryRiskLevel::High | CountryRiskLevel::Prohibited
40+
)
3841
}
3942
}
4043

@@ -46,7 +49,7 @@ pub struct JurisdictionRisk {
4649
pub is_offshore: bool,
4750
pub is_fatf_greylist: bool,
4851
pub is_fatf_blacklist: bool,
49-
pub transparency_score: u8, // 0-100
52+
pub transparency_score: u8, // 0-100
5053
pub regulatory_strength: u8, // 0-100
5154
pub overall_risk: CountryRiskLevel,
5255
}
@@ -117,10 +120,7 @@ impl GeographicRiskScorer {
117120
country_name: "North Korea".to_string(),
118121
risk_level: CountryRiskLevel::Prohibited,
119122
risk_score: 100,
120-
factors: vec![
121-
"FATF Blacklist".to_string(),
122-
"UN Sanctions".to_string(),
123-
],
123+
factors: vec!["FATF Blacklist".to_string(), "UN Sanctions".to_string()],
124124
fatf_status: Some("Blacklist".to_string()),
125125
sanctions_programs: vec!["OFAC North Korea".to_string(), "UN Sanctions".to_string()],
126126
});
@@ -144,7 +144,10 @@ impl GeographicRiskScorer {
144144
country_name: "Myanmar".to_string(),
145145
risk_level: CountryRiskLevel::High,
146146
risk_score: 80,
147-
factors: vec!["FATF Greylist".to_string(), "Targeted Sanctions".to_string()],
147+
factors: vec![
148+
"FATF Greylist".to_string(),
149+
"Targeted Sanctions".to_string(),
150+
],
148151
fatf_status: Some("Greylist".to_string()),
149152
sanctions_programs: vec![],
150153
});
@@ -154,7 +157,10 @@ impl GeographicRiskScorer {
154157
country_name: "Yemen".to_string(),
155158
risk_level: CountryRiskLevel::High,
156159
risk_score: 75,
157-
factors: vec!["Conflict Zone".to_string(), "Targeted Sanctions".to_string()],
160+
factors: vec![
161+
"Conflict Zone".to_string(),
162+
"Targeted Sanctions".to_string(),
163+
],
158164
fatf_status: None,
159165
sanctions_programs: vec![],
160166
});
@@ -243,7 +249,8 @@ impl GeographicRiskScorer {
243249

244250
/// Add a jurisdiction risk entry
245251
pub fn add_jurisdiction_risk(&mut self, risk: JurisdictionRisk) {
246-
self.jurisdiction_risks.insert(risk.jurisdiction.clone(), risk);
252+
self.jurisdiction_risks
253+
.insert(risk.jurisdiction.clone(), risk);
247254
}
248255

249256
/// Get country risk by ISO code
@@ -257,7 +264,11 @@ impl GeographicRiskScorer {
257264
}
258265

259266
/// Calculate transaction risk based on origin and destination countries
260-
pub fn calculate_transaction_risk(&self, origin: &str, destination: &str) -> TransactionGeographicRisk {
267+
pub fn calculate_transaction_risk(
268+
&self,
269+
origin: &str,
270+
destination: &str,
271+
) -> TransactionGeographicRisk {
261272
let origin_risk = self.get_country_risk(origin);
262273
let dest_risk = self.get_country_risk(destination);
263274

@@ -267,11 +278,11 @@ impl GeographicRiskScorer {
267278
// Use the higher of the two risks, weighted
268279
let combined_score = ((origin_score as u16 * 40 + dest_score as u16 * 60) / 100) as u8;
269280

270-
let is_prohibited = origin_risk.map_or(false, |r| r.is_prohibited())
271-
|| dest_risk.map_or(false, |r| r.is_prohibited());
281+
let is_prohibited = origin_risk.is_some_and(|r| r.is_prohibited())
282+
|| dest_risk.is_some_and(|r| r.is_prohibited());
272283

273-
let requires_edd = origin_risk.map_or(false, |r| r.requires_edd())
274-
|| dest_risk.map_or(false, |r| r.requires_edd());
284+
let requires_edd = origin_risk.is_some_and(|r| r.requires_edd())
285+
|| dest_risk.is_some_and(|r| r.requires_edd());
275286

276287
let risk_level = if is_prohibited {
277288
CountryRiskLevel::Prohibited

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
3333
pub mod aml_compliance;
3434
pub mod fraud_patterns;
35-
pub mod sanctions;
3635
pub mod geographic_risk;
3736
pub mod network_analysis;
37+
pub mod sanctions;
3838

3939
pub use aml_compliance::{AMLChecker, AMLResult, KYCValidationResult, KYCValidator};
4040
pub use fraud_patterns::{FraudDetector, FraudScore, FraudThresholds, RiskLevel};
41-
pub use sanctions::{SanctionsScreener, SanctionsResult, SanctionsList};
42-
pub use geographic_risk::{GeographicRiskScorer, CountryRisk, JurisdictionRisk};
43-
pub use network_analysis::{TransactionGraph, NetworkAnalyzer, SuspiciousPattern};
41+
pub use geographic_risk::{CountryRisk, GeographicRiskScorer, JurisdictionRisk};
42+
pub use network_analysis::{NetworkAnalyzer, SuspiciousPattern, TransactionGraph};
43+
pub use sanctions::{SanctionsList, SanctionsResult, SanctionsScreener};
4444

4545
use chrono::{DateTime, Duration, Timelike, Utc};
4646
use regex::Regex;
@@ -605,11 +605,7 @@ mod tests {
605605
fn create_valid_transaction() -> Transaction {
606606
// Create timestamp at 12 PM UTC (business hours) to minimize time-based risk
607607
let now = Utc::now();
608-
let timestamp = now
609-
.date_naive()
610-
.and_hms_opt(12, 0, 0)
611-
.unwrap()
612-
.and_utc();
608+
let timestamp = now.date_naive().and_hms_opt(12, 0, 0).unwrap().and_utc();
613609

614610
Transaction {
615611
transaction_id: "TXN-001".to_string(),
@@ -638,7 +634,11 @@ mod tests {
638634
eprintln!("Risk breakdown: {:?}", result.risk_breakdown);
639635
}
640636

641-
assert!(result.is_valid, "Transaction should be valid. Errors: {:?}, Fraud score: {}", result.errors, result.fraud_score);
637+
assert!(
638+
result.is_valid,
639+
"Transaction should be valid. Errors: {:?}, Fraud score: {}",
640+
result.errors, result.fraud_score
641+
);
642642
assert!(result.errors.is_empty());
643643
}
644644

src/network_analysis.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! Provides graph-based analysis for detecting suspicious transaction patterns.
44
5-
use chrono::{DateTime, Duration, Utc};
5+
use chrono::{DateTime, Utc};
66
use serde::{Deserialize, Serialize};
77
use std::collections::{HashMap, HashSet};
88

@@ -29,6 +29,7 @@ pub enum SuspiciousPattern {
2929

3030
/// Transaction node in the graph
3131
#[derive(Debug, Clone)]
32+
#[allow(dead_code)]
3233
struct TransactionNode {
3334
account_id: String,
3435
total_inflow: f64,
@@ -59,6 +60,7 @@ impl TransactionNode {
5960
self.incoming_accounts.len() >= 5 && self.outgoing_accounts.len() <= 2
6061
}
6162

63+
#[allow(dead_code)]
6264
fn is_distributor(&self) -> bool {
6365
// Few incoming, many outgoing
6466
self.incoming_accounts.len() <= 2 && self.outgoing_accounts.len() >= 5
@@ -76,6 +78,7 @@ impl TransactionNode {
7678

7779
/// Edge in the transaction graph
7880
#[derive(Debug, Clone)]
81+
#[allow(dead_code)]
7982
struct TransactionEdge {
8083
from_account: String,
8184
to_account: String,
@@ -136,13 +139,16 @@ impl TransactionGraph {
136139

137140
// Update edge
138141
let edge_key = (from_account.to_string(), to_account.to_string());
139-
let edge = self.edges.entry(edge_key.clone()).or_insert_with(|| TransactionEdge {
140-
from_account: from_account.to_string(),
141-
to_account: to_account.to_string(),
142-
total_amount: 0.0,
143-
transaction_count: 0,
144-
timestamps: Vec::new(),
145-
});
142+
let edge = self
143+
.edges
144+
.entry(edge_key.clone())
145+
.or_insert_with(|| TransactionEdge {
146+
from_account: from_account.to_string(),
147+
to_account: to_account.to_string(),
148+
total_amount: 0.0,
149+
transaction_count: 0,
150+
timestamps: Vec::new(),
151+
});
146152
edge.total_amount += amount;
147153
edge.transaction_count += 1;
148154
edge.timestamps.push(timestamp);
@@ -226,7 +232,7 @@ impl TransactionGraph {
226232
let mut results = Vec::new();
227233
let threshold_margin = self.reporting_threshold * 0.15; // 15% below threshold
228234

229-
for (account_id, node) in &self.nodes {
235+
for account_id in self.nodes.keys() {
230236
// Get all outgoing transaction amounts for this account
231237
let mut suspicious_amounts = Vec::new();
232238

@@ -347,13 +353,7 @@ impl NetworkAnalyzer {
347353
}
348354

349355
/// Add transaction to the analyzer
350-
pub fn add_transaction(
351-
&mut self,
352-
from: &str,
353-
to: &str,
354-
amount: f64,
355-
timestamp: DateTime<Utc>,
356-
) {
356+
pub fn add_transaction(&mut self, from: &str, to: &str, amount: f64, timestamp: DateTime<Utc>) {
357357
self.graph.add_transaction(from, to, amount, timestamp);
358358
}
359359

src/sanctions.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ impl SanctionsResult {
5656
/// Get highest confidence match
5757
pub fn highest_confidence(&self) -> Option<&SanctionsMatch> {
5858
self.matches.iter().max_by(|a, b| {
59-
a.confidence.partial_cmp(&b.confidence).unwrap_or(std::cmp::Ordering::Equal)
59+
a.confidence
60+
.partial_cmp(&b.confidence)
61+
.unwrap_or(std::cmp::Ordering::Equal)
6062
})
6163
}
6264

6365
/// Get matches above threshold
6466
pub fn matches_above_threshold(&self, threshold: f32) -> Vec<&SanctionsMatch> {
65-
self.matches.iter().filter(|m| m.confidence >= threshold).collect()
67+
self.matches
68+
.iter()
69+
.filter(|m| m.confidence >= threshold)
70+
.collect()
6671
}
6772
}
6873

@@ -216,8 +221,10 @@ impl SanctionsScreener {
216221

217222
// Partial match (contains)
218223
if entity.name.contains(&name_upper) || name_upper.contains(&entity.name) {
219-
let partial_conf = 0.7 + (0.2 * (name_upper.len().min(entity.name.len()) as f32
220-
/ name_upper.len().max(entity.name.len()) as f32));
224+
let partial_conf = 0.7
225+
+ (0.2
226+
* (name_upper.len().min(entity.name.len()) as f32
227+
/ name_upper.len().max(entity.name.len()) as f32));
221228

222229
if !matches.iter().any(|m| m.entry_id == entity.id) {
223230
matches.push(SanctionsMatch {
@@ -234,7 +241,11 @@ impl SanctionsScreener {
234241
}
235242

236243
// Sort by confidence
237-
matches.sort_by(|a, b| b.confidence.partial_cmp(&a.confidence).unwrap_or(std::cmp::Ordering::Equal));
244+
matches.sort_by(|a, b| {
245+
b.confidence
246+
.partial_cmp(&a.confidence)
247+
.unwrap_or(std::cmp::Ordering::Equal)
248+
});
238249

239250
SanctionsResult {
240251
screened_value: name.to_string(),
@@ -261,9 +272,7 @@ impl SanctionsScreener {
261272
let max_len = len1.max(len2);
262273

263274
// Simple character-based similarity
264-
let common_chars: usize = s1.chars()
265-
.filter(|c| s2.contains(*c))
266-
.count();
275+
let common_chars: usize = s1.chars().filter(|c| s2.contains(*c)).count();
267276

268277
let char_similarity = common_chars as f32 / max_len as f32;
269278

@@ -324,7 +333,10 @@ mod tests {
324333
let result = screener.screen("ENTITY ONE");
325334

326335
assert!(result.is_match);
327-
assert!(result.matches.iter().any(|m| m.match_type == MatchType::Alias));
336+
assert!(result
337+
.matches
338+
.iter()
339+
.any(|m| m.match_type == MatchType::Alias));
328340
}
329341

330342
#[test]
@@ -377,7 +389,7 @@ mod tests {
377389
screener.set_fuzzy_threshold(0.95); // Very strict
378390

379391
let result = screener.screen("SANCTIONED ENTTY ONE"); // Typo
380-
// Should have lower confidence due to typo
392+
// Should have lower confidence due to typo
381393
if result.is_match {
382394
assert!(result.matches[0].confidence < 1.0);
383395
}

0 commit comments

Comments
 (0)