aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/openapi.yaml40
-rw-r--r--src/api/events.rs55
2 files changed, 73 insertions, 22 deletions
diff --git a/docs/openapi.yaml b/docs/openapi.yaml
index 1bb69e3..c99cb65 100644
--- a/docs/openapi.yaml
+++ b/docs/openapi.yaml
@@ -1649,6 +1649,46 @@ paths:
$ref: '#/components/responses/Error'
'404':
$ref: '#/components/responses/Error'
+ /admin/events/vote:
+ post:
+ tags: [Events]
+ summary: Vote by hand, through the node that votes for its party
+ description: |
+ A vote by hand through this node, which votes for its party by itself
+ (`--store-vote-key`) and keeps its party's one record of its votes: `yes` on the
+ proposal of hash `proposal` on the current version, by that record (one `true` at
+ a time, never `true` and `false` on one proposal, a `true` only for a version) and,
+ with a `true` on a version naming a checkpoint, by the voters' rule (it changes
+ nothing else, and its heads leave out nothing the node held for a while before it
+ was proposed). Signed with the party's key the node keeps, recorded, and put.
+ Needs `write` on `_continuum`.
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ type: object
+ required: [proposal, yes]
+ properties:
+ proposal:
+ type: string
+ yes:
+ type: boolean
+ responses:
+ '200':
+ description: Cast; `id` is the vote's.
+ content:
+ application/json:
+ schema:
+ type: object
+ required: [id]
+ properties:
+ id:
+ type: string
+ '400':
+ $ref: '#/components/responses/Error'
+ '422':
+ $ref: '#/components/responses/Error'
/admin/remakes:
get:
tags: [Remakes]
diff --git a/src/api/events.rs b/src/api/events.rs
index 65c6238..8eb243d 100644
--- a/src/api/events.rs
+++ b/src/api/events.rs
@@ -16,9 +16,6 @@ use serde_json::{Value as JsonValue, json};
use super::auth::AuthenticatedUser;
use super::{ApiError, error_response, store_status};
-use crate::document::events;
-use crate::document::typed::{TimestampFormat, Val};
-use crate::document::{ScalarValue, store};
use crate::federation::fold::Federation;
use crate::federation::jcs::Json as Jcs;
use crate::federation::store::Id;
@@ -33,6 +30,7 @@ pub(super) fn router() -> Router<AppState> {
.route("/events/{id}", get(event))
.route("/admin/events/drop", post(drop_taken))
.route("/admin/events/allow", post(allow))
+ .route("/admin/events/vote", post(vote))
}
/// The answer while the node holds no store.
@@ -221,29 +219,42 @@ async fn put(
Some(Offered::Held) => "held",
Some(Offered::Waiting) => "waiting",
};
- let written = state
- .mutate_doc_for(
- Some(user),
- crate::document::signatures::Sign::Protocol,
- move |doc| {
- if events::bytes(doc, &id).is_none() {
- store::write_val_path(
- doc,
- &events::event(&id),
- &Val::Scalar(ScalarValue::Bytes(bytes)),
- store::Writing::sticky(TimestampFormat::default()),
- )?;
- }
- Ok::<(), store::StoreError>(())
- },
- )
- .await;
- match written {
- Ok(_) => Json(json!({"id": id.to_string(), "event": became})).into_response(),
+ match crate::federation::held::write(&state, Some(user), bytes).await {
+ Ok(()) => Json(json!({"id": id.to_string(), "event": became})).into_response(),
Err(error) => store_status(error, "Failed to put an event").into_response(),
}
}
+/// A vote by hand.
+#[derive(Deserialize)]
+struct ByHand {
+ proposal: String,
+ yes: bool,
+}
+
+/// `POST /admin/events/vote`: a vote by hand through this node, which votes for its party
+/// by itself and keeps its party's one record: `yes` on the proposal of that hash on the
+/// current version, by the record, and with a `true` by the voters' rule; signed with the
+/// party's key the node keeps, recorded, and put.
+async fn vote(
+ State(state): State<AppState>,
+ Extension(AuthenticatedUser(user)): Extension<AuthenticatedUser>,
+ Json(by_hand): Json<ByHand>,
+) -> Response {
+ let Some(proposal) = Id::from_hex(&by_hand.proposal) else {
+ return error_response(StatusCode::BAD_REQUEST, "not a proposal's hash", None);
+ };
+ let cast = match state.holding.vote_by_hand(proposal, by_hand.yes) {
+ Ok(cast) => cast,
+ Err(why) => return error_response(StatusCode::UNPROCESSABLE_ENTITY, why, None),
+ };
+ let id = Id::of(&cast);
+ match crate::federation::held::write(&state, Some(user), cast).await {
+ Ok(()) => Json(json!({"id": id.to_string()})).into_response(),
+ Err(error) => store_status(error, "Failed to put a vote").into_response(),
+ }
+}
+
/// The events an operator names.
#[derive(Deserialize)]
struct Named {