aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/party.rs33
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")?