forked from CalloraOrg/Callora-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.py
More file actions
33 lines (26 loc) · 1.07 KB
/
Copy pathpatch.py
File metadata and controls
33 lines (26 loc) · 1.07 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
with open('/tmp/7e15499_revenue_pool.rs', 'r') as f:
lines = f.readlines()
with open('/tmp/emergency_funcs.rs', 'r') as f:
emergency = f.read()
# Replace use statement to add emergency module (events is already there at the bottom, but we'll move it)
for i, line in enumerate(lines):
if line.startswith('use soroban_sdk::{'):
lines[i] = 'pub mod emergency;\npub mod events;\n\n' + line
break
# Remove `mod events;` from the bottom
lines = [line for line in lines if not line.startswith('mod events;')]
# Insert emergency at line 919 (which is index 918)
# But wait, we added lines at the top, so let's find the closing brace by searching for `pub fn chunk_iter`
chunk_iter_idx = -1
for i, line in enumerate(lines):
if line.startswith('pub fn chunk_iter'):
chunk_iter_idx = i
break
impl_end_idx = -1
for i in range(chunk_iter_idx - 1, -1, -1):
if lines[i].strip() == '}':
impl_end_idx = i
break
lines.insert(impl_end_idx, emergency + '\n')
with open('contracts/revenue_pool/src/lib.rs', 'w') as f:
f.write(''.join(lines))