forked from Liquifact/Liquifact-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_init_simple.py
More file actions
64 lines (49 loc) · 1.77 KB
/
Copy pathfix_init_simple.py
File metadata and controls
64 lines (49 loc) · 1.77 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
62
63
64
#!/usr/bin/env python3
"""Simpler approach: find the line with ); and add 3 None lines before it."""
import os
from pathlib import Path
import re
def process_file(filepath):
with open(filepath, 'r') as f:
lines = f.readlines()
new_lines = []
in_init = False
init_start = -1
for i, line in enumerate(lines):
if 'client.init(' in line:
in_init = True
init_start = i
if in_init and line.strip() == ');':
# Found the end of init call
# Count how many &None, appear in this init block
init_text = ''.join(lines[init_start:i+1])
none_count = init_text.count('&None,')
# We need 14 None values total
needed = 14 - none_count
if needed > 0:
# Add the needed lines before the );
indent = ' '
for _ in range(needed):
new_lines.append(f'{indent}&None,\n')
in_init = False
new_lines.append(line)
new_content = ''.join(new_lines)
with open(filepath, 'r') as f:
old_content = f.read()
if new_content != old_content:
with open(filepath, 'w') as f:
f.write(new_content)
return True
return False
test_dir = Path('/workspaces/Liquifact-contracts/escrow/src')
fixed_count = 0
for rs_file in sorted(test_dir.rglob('*.rs')):
if rs_file.name.startswith('fix_init'):
continue
try:
if process_file(rs_file):
print(f"Fixed {rs_file.relative_to(test_dir.parent)}")
fixed_count += 1
except Exception as e:
print(f"Error processing {rs_file}: {e}")
print(f"\nTotal files fixed: {fixed_count}")