forked from Crowdfunding-DApp/stellar-raise-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_initialize_calls.py
More file actions
55 lines (44 loc) · 1.91 KB
/
fix_initialize_calls.py
File metadata and controls
55 lines (44 loc) · 1.91 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
#!/usr/bin/env python3
import re
# Read the file
with open('contracts/crowdfund/src/test.rs', 'r') as f:
content = f.read()
# Pattern 1: Single-line initialize calls with 8 args
# client.initialize(&creator, &token_address, &goal, &deadline, &1_000, &None, &None, &None)
pattern1 = r'client\.initialize\(&creator, &token_address, &goal, &deadline, &(\d+|min_contribution), &None, &None, &None\)'
replacement1 = r'client.initialize(&admin, &creator, &token_address, &goal, &deadline, &\1, &None, &None, &None, &None)'
content = re.sub(pattern1, replacement1, content)
# Pattern 2: Multi-line initialize calls starting with client.initialize(
# Need to handle these more carefully
lines = content.split('\n')
new_lines = []
i = 0
while i < len(lines):
line = lines[i]
# Check if this is a multi-line initialize call
if 'client.initialize(' in line or 'client.try_initialize(' in line:
# Collect all lines until we find the closing )
call_lines = [line]
j = i + 1
paren_count = line.count('(') - line.count(')')
while j < len(lines) and paren_count > 0:
call_lines.append(lines[j])
paren_count += lines[j].count('(') - lines[j].count(')')
j += 1
# Join the call lines
full_call = '\n'.join(call_lines)
# Check if it starts with &creator (old format)
if re.search(r'initialize\(\s*&creator,', full_call):
# Insert &admin, before &creator
full_call = re.sub(r'(initialize\()\s*(&creator,)', r'\1\n &admin,\n \2', full_call)
# Split back into lines and add to new_lines
new_lines.extend(full_call.split('\n'))
i = j
else:
new_lines.append(line)
i += 1
content = '\n'.join(new_lines)
# Write back
with open('contracts/crowdfund/src/test.rs', 'w') as f:
f.write(content)
print("Fixed initialize calls")