-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathadmin.rs
37 lines (32 loc) · 1.1 KB
/
admin.rs
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
use axum::response::IntoResponse;
use axum::response::Response;
use axum::routing::get;
use axum::Json;
use axum::{extract::State, routing::post, Router};
use raiko_ballot::Ballot;
use raiko_lib::proof_type::ProofType;
use std::collections::BTreeMap;
use crate::interfaces::HostResult;
use raiko_reqactor::Actor;
pub fn create_router() -> Router<Actor> {
Router::new()
.route("/pause", post(pause))
.route("/set_ballot", post(set_ballot))
.route("/get_ballot", get(get_ballot))
}
async fn pause(State(actor): State<Actor>) -> HostResult<&'static str> {
actor.pause().await.map_err(|e| anyhow::anyhow!(e))?;
Ok("System paused successfully")
}
async fn set_ballot(
State(actor): State<Actor>,
Json(probs): Json<BTreeMap<ProofType, f64>>,
) -> HostResult<&'static str> {
let ballot = Ballot::new(probs).map_err(|e| anyhow::anyhow!(e))?;
actor.set_ballot(ballot).await;
Ok("Ballot set successfully")
}
async fn get_ballot(State(actor): State<Actor>) -> Response {
let ballot = actor.get_ballot().await.probabilities().to_owned();
Json(ballot).into_response()
}