forked from StellarSend/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescrow.rs
More file actions
109 lines (102 loc) · 3.38 KB
/
Copy pathescrow.rs
File metadata and controls
109 lines (102 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "escrow_status", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum EscrowStatus {
Active,
Released,
Refunded,
Cancelled,
}
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct EscrowRow {
pub id: Uuid,
pub depositor_id: Uuid,
pub depositor_account: String,
pub beneficiary_account: String,
pub asset_code: String,
pub asset_issuer: Option<String>,
pub amount: String,
pub unlock_time: DateTime<Utc>,
pub arbiter_account: Option<String>,
pub status: EscrowStatus,
pub onchain_escrow_id: Option<String>,
pub funding_tx_hash: Option<String>,
pub release_tx_hash: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Escrow {
pub id: Uuid,
pub depositor_id: Uuid,
pub depositor_account: String,
pub beneficiary_account: String,
pub asset_code: String,
pub asset_issuer: Option<String>,
pub amount: String,
pub unlock_time: DateTime<Utc>,
pub arbiter_account: Option<String>,
pub status: EscrowStatus,
pub onchain_escrow_id: Option<String>,
pub funding_tx_hash: Option<String>,
pub release_tx_hash: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl From<EscrowRow> for Escrow {
fn from(row: EscrowRow) -> Self {
Self {
id: row.id,
depositor_id: row.depositor_id,
depositor_account: row.depositor_account,
beneficiary_account: row.beneficiary_account,
asset_code: row.asset_code,
asset_issuer: row.asset_issuer,
amount: row.amount,
unlock_time: row.unlock_time,
arbiter_account: row.arbiter_account,
status: row.status,
onchain_escrow_id: row.onchain_escrow_id,
funding_tx_hash: row.funding_tx_hash,
release_tx_hash: row.release_tx_hash,
created_at: row.created_at,
updated_at: row.updated_at,
}
}
}
/// Request body for POST /api/escrows. The client funds the escrow with its
/// own signed transaction (`create_escrow` on-chain); this records it.
#[derive(Debug, Deserialize)]
pub struct CreateEscrowRequest {
pub depositor_account: String,
pub beneficiary_account: String,
pub asset_code: String,
pub asset_issuer: Option<String>,
pub amount: String,
pub unlock_time: DateTime<Utc>,
pub arbiter_account: Option<String>,
pub onchain_escrow_id: Option<String>,
pub funding_tx_hash: Option<String>,
}
/// Who is attempting to trigger the escrow action — determines which rules
/// apply (mirrors the contract's own authorization rules).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EscrowActor {
Depositor,
Beneficiary,
Arbiter,
}
/// Request body for POST /api/escrows/:id/release and /refund.
#[derive(Debug, Deserialize)]
pub struct EscrowActionRequest {
/// Which party is invoking this action (validated against the escrow's
/// recorded accounts).
pub actor: EscrowActor,
/// The Stellar account of the caller (must match the role claimed by
/// `actor`).
pub account: String,
}