diff --git a/contracts/escrow/src/lib.rs b/contracts/escrow/src/lib.rs index 39f9460..9fc13f9 100644 --- a/contracts/escrow/src/lib.rs +++ b/contracts/escrow/src/lib.rs @@ -8,6 +8,14 @@ use soroban_sdk::{ token, Address, Env, Symbol, Vec, }; +// --------------------------------------------------------------------------- +// TTL constants +// --------------------------------------------------------------------------- + +pub const MIN_TTL_LEDGERS: u32 = 2_592_000; // 30 days at 1s/ledger +pub const MAX_TTL_LEDGERS: u32 = 2_592_000; // 30 days +pub const SHORT_TTL_LEDGERS: u32 = 604_800; // 7 days + // --------------------------------------------------------------------------- // Storage keys // --------------------------------------------------------------------------- @@ -125,6 +133,10 @@ fn get_admin(env: &Env) -> Result
{ .ok_or(ContractError::Unauthorized) } +fn bump_instance_ttl(env: &Env) { + env.storage().instance().extend_ttl(MIN_TTL_LEDGERS, MAX_TTL_LEDGERS); +} + // --------------------------------------------------------------------------- // Contract // --------------------------------------------------------------------------- @@ -276,6 +288,14 @@ impl EscrowContract { Ok(()) } + /// Admin utility to manually extend a trade's TTL. + pub fn bump_trade(env: Env, trade_id: u64) { + bump_instance_ttl(&env); + let admin = get_admin(&env); + admin.require_auth(); + env.storage().persistent().extend_ttl(&DataKey::Trade(trade_id), MIN_TTL_LEDGERS, MAX_TTL_LEDGERS); + } + // ----------------------------------------------------------------------- // deposit_to_escrow // ----------------------------------------------------------------------- @@ -430,6 +450,9 @@ impl EscrowContract { } } } + if all_released { + env.storage().persistent().extend_ttl(&DataKey::Trade(trade_id), SHORT_TTL_LEDGERS, SHORT_TTL_LEDGERS); + } if all_released { trade.status = TradeStatus::Completed; env.storage()