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
97 lines (76 loc) · 2.74 KB
/
Copy pathlib.rs
File metadata and controls
97 lines (76 loc) · 2.74 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![no_std]
use soroban_sdk::{contract, contractimpl, Address, Env, String, Vec};
mod events;
mod storage;
mod types;
#[cfg(test)]
mod test;
pub use events::*;
pub use storage::*;
pub use types::*;
#[contract]
pub struct ReminderContract;
#[contractimpl]
impl ReminderContract {
pub fn create_reminder_escrow(
env: Env,
split_id: String,
participants: Vec<EscrowParticipant>,
) {
let escrow = ReminderEscrow {
split_id: split_id.clone(),
participants,
};
storage::set_escrow(&env, &split_id, &escrow);
}
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 = 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 = 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
}
}