-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrisk_engine.py
More file actions
61 lines (55 loc) · 1.62 KB
/
risk_engine.py
File metadata and controls
61 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# risk_engine.py
def score_wallet_risk(wallet_data: dict) -> dict:
"""
Simple heuristic scoring engine.
Input: wallet_data dict dari xrpl_handler.validate_wallet
Output: {score, level, reasons, model}
"""
score = 0
reasons = []
# Baki XRP
balance_xrp = float(wallet_data.get("balance_xrp", 0) or 0)
if balance_xrp < 1:
score += 15
reasons.append(f"Very low balance ({balance_xrp:.6f} XRP).")
elif balance_xrp > 20:
score -= 5
reasons.append("Healthy balance (>20 XRP).")
else:
reasons.append("Moderate balance.")
# Owner count
owner_count = int(wallet_data.get("owner_count", 0) or 0)
if owner_count > 100:
score += 10
reasons.append(f"High owner count ({owner_count}).")
elif owner_count == 0:
score -= 2
reasons.append("No owned objects (simple account).")
# Flags
flags = int(wallet_data.get("flags", 0) or 0)
if flags & 0x00400000:
score += 60
reasons.append("GlobalFreeze set.")
if flags & 0x00080000:
score += 25
reasons.append("DisallowXRP set.")
if flags & 0x00010000:
score += 5
reasons.append("RequireDestTag set.")
if flags & 0x00020000:
reasons.append("DefaultRipple enabled.")
# Clamp 0–100
score = max(0, min(100, score))
# Kategori
if score <= 20:
level = "Low Risk"
elif score <= 60:
level = "Medium Risk"
else:
level = "High Risk"
return {
"score": int(score),
"level": level,
"reasons": reasons,
"model": "heuristic-stub"
}