forked from StellarSend/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
108 lines (105 loc) · 5.3 KB
/
Copy pathmod.rs
File metadata and controls
108 lines (105 loc) · 5.3 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
pub mod accounts;
pub mod auth;
pub mod escrows;
pub mod keeper;
pub mod payment_requests;
pub mod payments;
pub mod rates;
pub mod subscriptions;
pub mod transactions;
use crate::AppState;
use axum::{
routing::{get, post},
Router,
};
use std::sync::Arc;
/// Assemble the complete application router with all sub-routers mounted.
pub fn build_router(state: Arc<AppState>) -> Router {
Router::new()
// ── Health ──────────────────────────────────────────────────────────
.route("/health", get(health_check))
// ── Auth ────────────────────────────────────────────────────────────
.route("/api/auth/register", post(auth::register))
.route("/api/auth/login", post(auth::login))
// ── Payments ────────────────────────────────────────────────────────
.route("/api/payments/quote", post(payments::get_quote))
.route("/api/payments/send", post(payments::send_payment))
.route("/api/payments/batch", post(payments::send_batch_payment))
.route("/api/payments/:id", get(payments::get_payment))
// ── Transactions ────────────────────────────────────────────────────
.route("/api/transactions", get(transactions::list_transactions))
.route("/api/transactions/:id", get(transactions::get_transaction))
// ── Accounts ────────────────────────────────────────────────────────
.route(
"/api/accounts/:address",
get(accounts::get_account),
)
.route(
"/api/accounts/:address/balances",
get(accounts::get_balances),
)
// ── Rates ───────────────────────────────────────────────────────────
.route("/api/rates", get(rates::get_rate))
// ── Subscriptions (recurring payments) ─────────────────────────────
.route(
"/api/subscriptions",
get(subscriptions::list_subscriptions).post(subscriptions::create_subscription),
)
.route("/api/subscriptions/:id", get(subscriptions::get_subscription))
.route(
"/api/subscriptions/:id/cancel",
post(subscriptions::cancel_subscription),
)
// ── Payment requests / invoicing ────────────────────────────────────
.route(
"/api/payment-requests",
get(payment_requests::list_payment_requests).post(payment_requests::create_payment_request),
)
.route(
"/api/payment-requests/:id",
get(payment_requests::get_payment_request),
)
.route(
"/api/payment-requests/:id/fulfill",
post(payment_requests::fulfill_payment_request),
)
.route(
"/api/payment-requests/:id/cancel",
post(payment_requests::cancel_payment_request),
)
// ── Escrow / conditional transfers ──────────────────────────────────
.route(
"/api/escrows",
get(escrows::list_escrows).post(escrows::create_escrow),
)
.route("/api/escrows/:id", get(escrows::get_escrow))
.route("/api/escrows/:id/release/build", post(escrows::build_release_escrow))
.route("/api/escrows/:id/release", post(escrows::release_escrow))
.route("/api/escrows/:id/refund/build", post(escrows::build_refund_escrow))
.route("/api/escrows/:id/refund", post(escrows::refund_escrow))
// ── Keeper (manual trigger for the recurring-payment background job) ─
.route("/api/keeper/run-subscriptions", post(keeper::run_subscriptions))
.with_state(state)
}
/// GET /health — lightweight liveness probe.
///
/// Includes each background loop's last-tick unix timestamp (`null` if it
/// has never ticked — e.g. the keeper loop when `KEEPER_ENABLED=false`) so
/// an operator can tell those loops are actually still alive, not just that
/// the HTTP server is (#50) — the process staying up says nothing about
/// whether the loops backing it are.
async fn health_check(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
) -> axum::Json<serde_json::Value> {
axum::Json(serde_json::json!({
"success": true,
"data": {
"status": "ok",
"service": "stellarsend-backend",
"background_loops": {
"keeper_last_tick_at": state.loop_health.keeper_last_tick_at(),
"reconciliation_last_tick_at": state.loop_health.reconciliation_last_tick_at(),
}
}
}))
}