aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/events.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/events.rs')
-rw-r--r--src/api/events.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/api/events.rs b/src/api/events.rs
index 1d275f9..55b29f1 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -32,6 +32,7 @@ pub(super) fn router() -> Router<AppState> {
.route("/events/counts", get(counts))
.route("/events/refused", get(refused))
.route("/events/fork", post(check_fork))
+ .route("/events/back", post(check_back))
.route("/events/{id}", get(event))
.route("/admin/events/drop", post(drop_taken))
.route("/admin/events/allow", post(allow))
@@ -486,6 +487,36 @@ async fn make_fork(State(state): State<AppState>, Json(forking): Json<Forking>)
}
}
+/// A `true` a party's client is about to sign: its party, the proposal's hash, and the
+/// events it would build on.
+#[derive(Deserialize)]
+struct Backing {
+ party: String,
+ proposal: String,
+ on: Vec<String>,
+}
+
+/// `POST /events/back`: whether this node takes a `true` of `party` on the proposal of
+/// hash `proposal` on the current version, built on the events `on`, as far as the party's
+/// other votes go (`vote::takes_true`); `why` where it doesn't. A party's client asks
+/// before it signs and records one: nothing signed comes here, so the node gets nothing
+/// to pass on, and a vote every node would refuse is never cast.
+async fn check_back(State(state): State<AppState>, Json(backing): Json<Backing>) -> Response {
+ let Some(proposal) = Id::from_hex(&backing.proposal) else {
+ return error_response(StatusCode::BAD_REQUEST, "not a proposal's hash", None);
+ };
+ let on = match read_ids(&backing.on) {
+ Ok(on) => on,
+ Err(error) => return error.into_response(),
+ };
+ with_store(&state, |store| {
+ match crate::federation::vote::takes_true(store, &backing.party, &proposal, &on) {
+ Ok(()) => json!({"takes": true, "why": null}),
+ Err(why) => json!({"takes": false, "why": why}),
+ }
+ })
+}
+
/// `POST /events/fork`: what this node finds of the fork whose root is the body's first
/// line, as the file its founders start from holds it: whether it builds that root at
/// its heads, and why not; what it holds that those heads lack; what the fork's version