1
1
use axum:: {
2
+ body:: Body ,
2
3
extract:: { Path , State } ,
3
- response :: { IntoResponse , Response } ,
4
- Json ,
4
+ http :: Response ,
5
+ response :: IntoResponse ,
5
6
} ;
6
7
7
- use crate :: shared_state:: { AppState , SharedState } ;
8
- use crate :: { AppError , StdResult } ;
8
+ use crate :: shared_state:: SharedState ;
9
+ use crate :: AppError ;
9
10
10
11
pub async fn epoch_settings ( State ( state) : State < SharedState > ) -> Result < String , AppError > {
11
12
let app_state = state. read ( ) . await ;
@@ -17,7 +18,7 @@ pub async fn epoch_settings(State(state): State<SharedState>) -> Result<String,
17
18
pub async fn snapshot (
18
19
Path ( key) : Path < String > ,
19
20
State ( state) : State < SharedState > ,
20
- ) -> Result < Response , AppError > {
21
+ ) -> Result < Response < Body > , AppError > {
21
22
let app_state = state. read ( ) . await ;
22
23
23
24
app_state
@@ -34,24 +35,42 @@ pub async fn snapshots(State(state): State<SharedState>) -> Result<String, AppEr
34
35
Ok ( snapshots)
35
36
}
36
37
37
- pub async fn msds ( State ( state) : State < SharedState > ) -> Result < Json < String > , AppError > {
38
- todo ! ( )
38
+ pub async fn msds ( State ( state) : State < SharedState > ) -> Result < String , AppError > {
39
+ let app_state = state. read ( ) . await ;
40
+ let msds = app_state. get_msds ( ) . await ?;
41
+
42
+ Ok ( msds)
39
43
}
40
44
41
45
pub async fn msd (
42
46
Path ( key) : Path < String > ,
43
47
State ( state) : State < SharedState > ,
44
- ) -> Result < Json < String > , AppError > {
45
- todo ! ( )
48
+ ) -> Result < Response < Body > , AppError > {
49
+ let app_state = state. read ( ) . await ;
50
+
51
+ app_state
52
+ . get_msd ( & key)
53
+ . await ?
54
+ . map ( |s| s. into_response ( ) )
55
+ . ok_or_else ( || AppError :: NotFound ( format ! ( "mithril stake distribution epoch={key}" ) ) )
46
56
}
47
57
48
- pub async fn certificates ( State ( state) : State < SharedState > ) -> Result < Json < String > , AppError > {
49
- todo ! ( )
58
+ pub async fn certificates ( State ( state) : State < SharedState > ) -> Result < String , AppError > {
59
+ let app_state = state. read ( ) . await ;
60
+ let certificates = app_state. get_certificates ( ) . await ?;
61
+
62
+ Ok ( certificates)
50
63
}
51
64
52
65
pub async fn certificate (
53
66
Path ( key) : Path < String > ,
54
67
State ( state) : State < SharedState > ,
55
- ) -> Result < Json < String > , AppError > {
56
- todo ! ( )
68
+ ) -> Result < Response < Body > , AppError > {
69
+ let app_state = state. read ( ) . await ;
70
+
71
+ app_state
72
+ . get_certificate ( & key)
73
+ . await ?
74
+ . map ( |s| s. into_response ( ) )
75
+ . ok_or_else ( || AppError :: NotFound ( format ! ( "certificate hash={key}" ) ) )
57
76
}
0 commit comments