solmail_program/state/
escrow.rs1use crate::error::SolMailError;
2
3pub const ESCROW_ORDER_SIZE: usize = 75;
5
6#[repr(C, packed)]
8#[derive(Clone, Copy, Debug)]
9pub struct EscrowOrder {
10 pub payer: [u8; 32],
12 pub amount: u64,
14 pub mail_id: [u64; 2],
16 pub created_at: i64,
18 pub timeout_at: i64,
20 pub is_usdc: bool,
22 pub delivered: bool,
24 pub bump: u8,
26}
27
28const _: () = assert!(core::mem::size_of::<EscrowOrder>() == ESCROW_ORDER_SIZE);
29
30impl EscrowOrder {
31 pub fn from_bytes(data: &[u8]) -> Result<&Self, SolMailError> {
33 if data.len() < ESCROW_ORDER_SIZE {
34 return Err(SolMailError::InvalidInstructionData);
35 }
36 Ok(unsafe { &*(data.as_ptr() as *const Self) })
38 }
39
40 pub fn from_bytes_mut(data: &mut [u8]) -> Result<&mut Self, SolMailError> {
42 if data.len() < ESCROW_ORDER_SIZE {
43 return Err(SolMailError::InvalidInstructionData);
44 }
45 Ok(unsafe { &mut *(data.as_mut_ptr() as *mut Self) })
47 }
48
49 pub fn mail_id_bytes(&self) -> [u8; 16] {
51 let mut bytes = [0u8; 16];
52 bytes[..8].copy_from_slice(&self.mail_id[0].to_le_bytes());
53 bytes[8..].copy_from_slice(&self.mail_id[1].to_le_bytes());
54 bytes
55 }
56
57 pub fn is_timed_out(&self, current_time: i64) -> bool {
59 current_time >= self.timeout_at
60 }
61}