Skip to content

Commit

Permalink
use timestamp instead of time period for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvja committed Aug 23, 2024
1 parent 8d0696d commit ab94450
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions solana/bridge-escrow/programs/bridge-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub mod bridge_escrow {

let current_timestamp = Clock::get()?.unix_timestamp as u64;

require!(current_timestamp < new_intent.timeout_timestamp_in_sec, ErrorCode::InvalidTimeout);

intent.intent_id = new_intent.intent_id;
intent.user = new_intent.user_in;
intent.token_in = new_intent.token_in;
Expand Down Expand Up @@ -384,6 +386,9 @@ pub mod bridge_escrow {

/// If the intent has not been solved, then the funds can withdrawn by the user
/// after the timeout period has passed.
///
/// TODO: The funds should only be withdrawn if the message is sent through IBC that
/// the request got timed out.
pub fn on_timeout(
ctx: Context<OnTimeout>,
_intent_id: String,
Expand Down
11 changes: 8 additions & 3 deletions solana/bridge-escrow/programs/bridge-escrow/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;
use std::thread::sleep;
use std::time::Duration;
use std::time::{Duration, SystemTime, UNIX_EPOCH};

use anchor_client::solana_client::rpc_client::RpcClient;
use anchor_client::solana_client::rpc_config::RpcSendTransactionConfig;
Expand Down Expand Up @@ -278,14 +278,19 @@ fn escrow_bridge_program() -> Result<()> {
)
.0;

let current_timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();

let new_intent = IntentPayload {
intent_id: intent_id.clone(),
user_in: user.pubkey(),
token_in,
amount_in: TRANSFER_AMOUNT,
token_out: token_out.to_string(),
amount_out: amount_out.to_string(),
timeout_timestamp_in_sec: 10000,
timeout_timestamp_in_sec: current_timestamp + 10000,
winner_solver: solver.pubkey(),
single_domain: true,
};
Expand Down Expand Up @@ -405,7 +410,7 @@ fn escrow_bridge_program() -> Result<()> {
amount_in: TRANSFER_AMOUNT,
token_out: token_out.to_string(),
amount_out: amount_out.to_string(),
timeout_timestamp_in_sec: 10000,
timeout_timestamp_in_sec: current_timestamp + 10000,
winner_solver: solver.pubkey(),
single_domain: false,
};
Expand Down

0 comments on commit ab94450

Please sign in to comment.