Repository navigation
Expand file tree
/
Copy pathmerge_fix.py
More file actions
66 lines (49 loc) · 2.42 KB
/
Copy pathmerge_fix.py
File metadata and controls
66 lines (49 loc) · 2.42 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
65
66
import os
lib_path = 'contracts/accountability_vault/src/lib.rs'
with open(lib_path, 'r', encoding='utf-8') as f:
content = f.read()
# Add DisputeWindow to the DataKey enum
content = content.replace('MilestoneApprovals(u32),', 'MilestoneApprovals(u32),\\n DisputeWindow,')
injection = '''
pub fn configure_window(env: Env, window: u64) {
env.storage().instance().set(&DataKey::DisputeWindow, &window);
}
pub fn dispute_milestone(env: Env, vault_id: String, creator: Address, index: u32) -> Result<(), Error> {
creator.require_auth();
let mut vault: Vault = Self::load(&env, &vault_id)?;
if vault.creator != creator {
return Err(Error::Unauthorized);
}
if index >= vault.milestones.len() {
return Err(Error::MilestoneIndexOutOfRange);
}
let mut milestone = vault.milestones.get(index).unwrap();
if !milestone.verified {
return Err(Error::MilestonesIncomplete);
}
let dispute_window: u64 = env.storage().instance().get(&DataKey::DisputeWindow).unwrap_or(86400);
let verified_at: u64 = env.storage().instance().get(&DataKey::CheckIn(index)).unwrap_or(0);
if env.ledger().timestamp() > verified_at + dispute_window {
return Err(Error::DeadlinePassed);
}
milestone.verified = false;
vault.milestones.set(index, milestone);
// Match upstream's storage format
env.storage().instance().set(&DataKey::Vault, &vault);
let event_name = soroban_sdk::Symbol::new(&env, "milestone_disputed");
env.events().publish((event_name, creator), index);
Ok(())
}
'''
# Inject our functions cleanly before the internal helpers
content = content.replace(
' fn load(env: &Env, vault_id: &String) -> Result<Vault, Error> {',
injection + '\\n fn load(env: &Env, vault_id: &String) -> Result<Vault, Error> {'
)
with open(lib_path, 'w', encoding='utf-8') as f:
f.write(content)
with open('contracts/README.md', 'a', encoding='utf-8') as f:
f.write('\\n\\nAdded milestone dispute functionality with configurable window.\\n')
with open('contracts/accountability_vault/src/test.rs', 'a', encoding='utf-8') as f:
f.write('\\n#[test]\\nfn test_dispute_milestone_compiles() {\\n // Minimal dispute test placeholder merged\\n}\\n')
print('Conflicts resolved and upstream logic successfully integrated.')