-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathfix_reporting.py
More file actions
52 lines (42 loc) · 1.94 KB
/
fix_reporting.py
File metadata and controls
52 lines (42 loc) · 1.94 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
import re
import os
file_path = '/home/chukwuemekadr/Documents/Drips/Wave4/Remitwise-Contracts/reporting/src/lib.rs'
with open(file_path, 'r') as f:
content = f.read()
# Fix _internal functions return types and Ok() wrapping
functions = [
'get_remittance_summary_internal',
'get_savings_report_internal',
'get_bill_compliance_report_internal',
'get_insurance_report_internal',
'calculate_health_score_internal'
]
return_types = {
'get_remittance_summary_internal': 'Result<RemittanceSummary, ReportingError>',
'get_savings_report_internal': 'Result<SavingsReport, ReportingError>',
'get_bill_compliance_report_internal': 'Result<BillComplianceReport, ReportingError>',
'get_insurance_report_internal': 'Result<InsuranceReport, ReportingError>',
'calculate_health_score_internal': 'Result<HealthScore, ReportingError>'
}
for func in functions:
# Update return type
pattern = rf'fn {func}\(\s*([^)]*)\s*\)\s*->\s*[^ {{]+'
content = re.sub(pattern, f'fn {func}(\\1) -> {return_types[func]}', content)
# Fix Ok(...) wrapping with missing closing parenthesis
content = re.sub(r'Ok\(([^{}]+\{[^{}]+\})\s*\}', r'Ok(\1)\n }', content)
# Fix public methods that were wrapping already Result-returning internal methods
public_methods = [
'get_savings_report',
'get_bill_compliance_report',
'get_insurance_report',
'calculate_health_score'
]
for method in public_methods:
pattern = rf'Ok\(Self::{method}_internal\(([^)]*)\)\)'
content = re.sub(pattern, f'Self::{method_name}_internal(\\1)' if 'method_name' in locals() else f'Self::{method}_internal(\\1)', content)
# Specific fix for calculate_health_score return type if needed
# It returns HealthScore, let's check.
# pub fn calculate_health_score(env: Env, user: Address, total_remittance: i128) -> HealthScore
# It should probably return Result<HealthScore, ReportingError> too if internal does.
with open(file_path, 'w') as f:
f.write(content)