forked from SiLioLabs/PayFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrace.rs
More file actions
52 lines (43 loc) · 1.55 KB
/
Copy pathgrace.rs
File metadata and controls
52 lines (43 loc) · 1.55 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
use crate::{DataKey, SUBSCRIPTION_TTL_LEDGERS};
use soroban_sdk::Env;
pub fn get_grace_period(env: &Env) -> u64 {
if let Some(seconds) = env.storage().instance().get(&DataKey::GracePeriod) {
let lower = SUBSCRIPTION_TTL_LEDGERS / 2;
let upper = SUBSCRIPTION_TTL_LEDGERS;
env.storage().instance().extend_ttl(lower, upper);
seconds
} else {
0
}
}
/// Proposes a new contract-wide grace period.
pub fn propose_grace_period(env: &Env, seconds: u64) {
assert!(seconds <= u64::MAX / 2, "grace period too large");
crate::admin::require_admin(env);
env.storage()
.temporary()
.set(&DataKey::PendingGracePeriod, &seconds);
env.storage()
.temporary()
.extend_ttl(&DataKey::PendingGracePeriod, 17280, 17280);
crate::events::publish_grace_period_proposed(env, seconds);
}
/// Commits a pending grace period proposal.
pub fn commit_grace_period(env: &Env) {
crate::admin::require_admin(env);
let seconds: u64 = env
.storage()
.temporary()
.get(&DataKey::PendingGracePeriod)
.unwrap_or_else(|| env.panic_with_error(crate::errors::ContractError::NoPendingProposal));
env.storage()
.temporary()
.remove(&DataKey::PendingGracePeriod);
env.storage()
.instance()
.set(&DataKey::GracePeriod, &seconds);
let lower = SUBSCRIPTION_TTL_LEDGERS / 2;
let upper = SUBSCRIPTION_TTL_LEDGERS;
env.storage().instance().extend_ttl(lower, upper);
crate::events::publish_grace_period_committed(env, seconds);
}