diff options
| author | tv <tv@krebsco.de> | 2026-11-16 22:26:45 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 23:32:54 +0100 |
| commit | f9b456c540226f6ba30b508146448c1d35990883 (patch) | |
| tree | 8761d4be2ec30bfee325d7f1450b76528fa75760 | |
| parent | 18387cb68094b167a30371b62beda93627c2c467 (diff) | |
continuum-party: a vote through the node that votes for the party
A party that has a node vote by itself votes by hand only through that node:
`continuum-party vote PROPOSAL yes|no --through` asks the node to cast it
(`POST /admin/events/vote`), by the record the node keeps, without a key or record of
the client's own.
| -rw-r--r-- | src/federation/party.rs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs index 8163fb3..d5fcb2c 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -10,7 +10,8 @@ //! or node list (node IDs); //! * `propose FILE`: proposes the version `FILE` holds (JSON); //! * `vote PROPOSAL yes|no`: votes on the proposal of hash `PROPOSAL` on the current -//! version, by the record; +//! version, by the record; with `--through`, through the node that votes for the +//! party by itself and keeps its record, as such a party votes by hand; //! * `again`: signs again what a move refused; //! * `twice RECORD...`: names, from the records of parties' clients, a party that voted //! twice. @@ -92,7 +93,13 @@ fn command() -> Command { Command::new("vote") .about("Votes on a proposal on the current version, by its hash") .arg(id("proposal")) - .arg(Arg::new("yes").required(true).value_parser(["yes", "no"])), + .arg(Arg::new("yes").required(true).value_parser(["yes", "no"])) + .arg( + Arg::new("through") + .long("through") + .action(ArgAction::SetTrue) + .help("Through the node, which votes for the party and keeps its record"), + ), ) .subcommand(Command::new("again").about("Signs again what a move refused")) .subcommand( @@ -124,6 +131,19 @@ pub(crate) async fn main() -> Result<()> { return Ok(()); } let node = Node::new(&matches)?; + // A party that has a node vote by itself votes by hand only through it. + if name == "vote" && sub.get_flag("through") { + let proposal = sub.get_one::<String>("proposal").expect("required"); + let yes = sub.get_one::<String>("yes").map(String::as_str) == Some("yes"); + let answer = node + .post( + "/admin/events/vote", + &serde_json::json!({"proposal": proposal, "yes": yes}), + ) + .await?; + println!("{} cast", answer["id"].as_str().unwrap_or_default()); + return Ok(()); + } let path = PathBuf::from( matches .get_one::<String>("record") @@ -433,6 +453,15 @@ impl Node { Ok(bytes) } + async fn post(&self, path: &str, body: &JsonValue) -> Result<JsonValue> { + let response = self + .request(reqwest::Method::POST, path)? + .json(body) + .send() + .await?; + Ok(Self::answer(response).await?.json().await?) + } + async fn put(&self, event: &[u8]) -> Result<()> { let response = self .request(reqwest::Method::POST, "/events")? |
