-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathmod.rs
More file actions
82 lines (71 loc) · 2.33 KB
/
Copy pathmod.rs
File metadata and controls
82 lines (71 loc) · 2.33 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
use std::sync::Arc;
use axum::{extract::Request, http::StatusCode, response::IntoResponse, Json, Router};
// mod address;
mod block;
mod fee;
mod governance;
mod loan;
mod masternode;
// mod oracle;
// mod poolpairs;
// mod prices;
// mod rawtx;
mod cache;
mod common;
mod query;
mod response;
mod stats;
mod tokens;
mod transactions;
use defichain_rpc::Client;
use serde::{Deserialize, Serialize};
use crate::{Result, Services};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
struct NotFound {
status_code: u16,
message: String,
error: &'static str,
}
async fn not_found(req: Request<axum::body::Body>) -> impl IntoResponse {
let method = req.method().clone();
let path = req.uri().path().to_string();
let message = format!("Cannot {} {}", method, path);
(
StatusCode::NOT_FOUND,
Json(NotFound {
status_code: StatusCode::NOT_FOUND.as_u16(),
message,
error: "Not found",
}),
)
}
pub struct AppContext {
services: Arc<Services>,
client: Arc<Client>,
}
pub async fn ocean_router(services: &Arc<Services>, client: Arc<Client>) -> Result<Router> {
let context = Arc::new(AppContext {
client,
services: services.clone(),
});
let network = ain_cpp_imports::get_network();
Ok(Router::new().nest(
format!("/v0/{network}").as_str(),
Router::new()
// .nest("/address/", address::router(Arc::clone(&context)))
.nest("/governance", governance::router(Arc::clone(&context)))
.nest("/loans", loan::router(Arc::clone(&context)))
.nest("/fee", fee::router(Arc::clone(&context)))
.nest("/masternodes", masternode::router(Arc::clone(&context)))
// .nest("/oracles", oracle::router(Arc::clone(&context)))
// .nest("/poolpairs", poolpairs::router(Arc::clone(&context)))
// .nest("/prices", prices::router(Arc::clone(&context)))
// .nest("/rawtx", rawtx::router(Arc::clone(&context)))
.nest("/stats", stats::router(Arc::clone(&context)))
.nest("/tokens", tokens::router(Arc::clone(&context)))
.nest("/transactions", transactions::router(Arc::clone(&context)))
.nest("/blocks", block::router(Arc::clone(&context)))
.fallback(not_found),
))
}