Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions contracts/inheritance-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,39 @@ impl InheritanceContract {
Ok(())
}

/// Check if a plan has timed out (grace period elapsed).
/// Returns true if current_time >= last_ping + grace_period, false otherwise.
/// This is a read-only query method that does not modify state.
pub fn is_plan_timed_out(env: Env, owner: Address) -> Result<bool, Error> {
let key = DataKey::Plan(owner.clone());
if !env.storage().persistent().has(&key) {
return Err(Error::PlanNotFound);
}

let plan: Plan = env.storage().persistent().get(&key).unwrap();
Self::extend_plan_ttl(&env, &key);

let current_time = env.ledger().timestamp();
let timeout_deadline = plan.last_ping + plan.grace_period;

Ok(current_time >= timeout_deadline)
}

/// Get the timeout deadline timestamp for a plan.
/// Returns the timestamp when the grace period expires (last_ping + grace_period).
/// This is a read-only query method for external monitoring.
pub fn get_timeout_deadline(env: Env, owner: Address) -> Result<u64, Error> {
let key = DataKey::Plan(owner.clone());
if !env.storage().persistent().has(&key) {
return Err(Error::PlanNotFound);
}

let plan: Plan = env.storage().persistent().get(&key).unwrap();
Self::extend_plan_ttl(&env, &key);

Ok(plan.last_ping + plan.grace_period)
}

/// Retrieve the current inheritance plan data.
/// Contributors: Query plan storage, dynamically projects the accumulated yield.
pub fn get_plan(env: Env, owner: Address) -> Result<InheritancePlan, Error> {
Expand Down
Loading