forked from CalloraOrg/Callora-Contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_settlement.py
More file actions
27 lines (23 loc) · 956 Bytes
/
Copy pathpatch_settlement.py
File metadata and controls
27 lines (23 loc) · 956 Bytes
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
with open('/tmp/7e15499_settlement_lib.rs', 'r') as f:
content = f.read()
# Replace mod types
content = content.replace('mod types;\npub use types::*;\n', 'mod types;\npub use types::*;\npub mod batch;\n')
# Add batch_settle inside impl CalloraSettlement
batch_settle_code = """
pub fn batch_settle(
env: Env,
settlements: soroban_sdk::Vec<batch::SettleInput>,
) -> soroban_sdk::Vec<batch::SettleOutcome> {
batch::batch_settle(&env, settlements)
}
"""
impl_end_idx = content.rfind('}')
if impl_end_idx != -1:
# Need to find the end of `impl CalloraSettlement`.
# Let's search for the last `}` before `mod events;`
events_idx = content.find('mod events;')
if events_idx != -1:
impl_end_idx = content.rfind('}', 0, events_idx)
content = content[:impl_end_idx] + batch_settle_code + content[impl_end_idx:]
with open('contracts/settlement/src/lib.rs', 'w') as f:
f.write(content)