Skip to content
Open
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
23 changes: 23 additions & 0 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -125,6 +133,10 @@ fn get_admin(env: &Env) -> Result<Address, ContractError> {
.ok_or(ContractError::Unauthorized)
}

fn bump_instance_ttl(env: &Env) {
env.storage().instance().extend_ttl(MIN_TTL_LEDGERS, MAX_TTL_LEDGERS);
}

// ---------------------------------------------------------------------------
// Contract
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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
// -----------------------------------------------------------------------
Expand Down Expand Up @@ -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()
Expand Down