forked from CalloraOrg/Callora-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_revenue_pool.py
More file actions
42 lines (31 loc) · 1.38 KB
/
Copy pathpatch_revenue_pool.py
File metadata and controls
42 lines (31 loc) · 1.38 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
import re
with open('contracts/revenue_pool/src/lib.rs', 'r') as f:
current = f.read()
with open('/tmp/0c40fd7_revenue_pool.rs', 'r') as f:
old = f.read()
# Extract from pub fn propose_emergency_drain to the end of the impl block
# Find the start index
start_idx = current.find(' pub fn propose_emergency_drain')
if start_idx == -1:
print("Could not find propose_emergency_drain")
exit(1)
# Find the end index of the impl block (the last closing brace before EOF or next item)
# In current lib.rs, it is just before `}` at the end of the file.
end_idx = current.rfind('}')
if end_idx == -1:
print("Could not find end of impl block")
exit(1)
emergency_funcs = current[start_idx:end_idx]
# Replace use statement
old = old.replace('use soroban_sdk::{', 'pub mod emergency;\npub mod events;\n\nuse soroban_sdk::{')
# Add constants
old = old.replace('const ADMIN_KEY: &str = "admin";', 'const LIFETIME_THRESHOLD: u32 = 17_280 * 7;\nconst BUMP_AMOUNT: u32 = 17_280 * 30;\nconst ADMIN_KEY: &str = "admin";')
# Inject emergency_funcs before the closing brace of impl RevenuePool
impl_end_idx = old.rfind('}')
if impl_end_idx == -1:
print("Could not find impl RevenuePool block")
exit(1)
new_old = old[:impl_end_idx] + "\n" + emergency_funcs + "\n" + old[impl_end_idx:]
with open('contracts/revenue_pool/src/lib.rs', 'w') as f:
f.write(new_old)
print("Merged successfully")