forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
67 lines (52 loc) · 2.09 KB
/
Copy pathlib.rs
File metadata and controls
67 lines (52 loc) · 2.09 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
67
use soroban_sdk::{Env, Address};
use crate::{types::EscrowParticipant, super::storage, super::events};
pub fn request_reminder(env: Env, split_id: String, participant: Address) {
participant.require_auth();
let mut escrow = storage::get_escrow(&env, &split_id).expect("Escrow not found");
let mut found = false;
let mut updated_participants = soroban_sdk::Vec::new(&env);
for i in 0..escrow.participants.len() {
let mut p = escrow.participants.get(i).unwrap();
if p.address == participant && p.amount_paid < p.amount_owed {
p.reminder_requested = true;
events::emit_reminder_requested(&env, participant.clone(), &split_id);
found = true;
}
updated_participants.push_back(p);
}
if !found {
panic!("Participant not found or already paid");
}
escrow.participants = updated_participants;
storage::set_escrow(&env, &split_id, &escrow);
}
pub fn cancel_reminder(env: Env, split_id: String, participant: Address) {
participant.require_auth();
let mut escrow = storage::get_escrow(&env, &split_id).expect("Escrow not found");
let mut found = false;
let mut updated_participants = soroban_sdk::Vec::new(&env);
for i in 0..escrow.participants.len() {
let mut p = escrow.participants.get(i).unwrap();
if p.address == participant {
p.reminder_requested = false;
events::emit_reminder_cancelled(&env, participant.clone(), &split_id);
found = true;
}
updated_participants.push_back(p);
}
if !found {
panic!("Participant not found");
}
escrow.participants = updated_participants;
storage::set_escrow(&env, &split_id, &escrow);
}
pub fn get_reminder_requested(env: Env, split_id: String, participant: Address) -> bool {
let escrow = storage::get_escrow(&env, &split_id).expect("Escrow not found");
for i in 0..escrow.participants.len() {
let p = escrow.participants.get(i).unwrap();
if p.address == participant {
return p.reminder_requested;
}
}
false
}