aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/party.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/party.rs')
-rw-r--r--src/federation/party.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs
index e3923a6..aaa983f 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -17,6 +17,8 @@
//! * `again`: signs again what a move refused;
//! * `twice RECORD...`: names, from the records of parties' clients, a party that voted
//! twice;
+//! * `proposals`: the proposals on the current version at the node, each with whether it
+//! passed or is dead, who voted what, and what its version changes (`client::changes`);
//! * `root FILE`: the root of the federation whose first version `FILE` holds (JSON),
//! the file its founders start its swarm from (`--store-root`), to standard output;
//! * `fork FILE HEAD...`: the root of the fork at the heads named by the version `FILE`
@@ -136,6 +138,10 @@ fn command() -> Command {
.about("What the node finds of the fork whose root a file holds")
.arg(id("file")),
)
+ .subcommand(Command::new("proposals").about(
+ "The proposals on the current version: whether each passed or is dead, who voted \
+ what, and what it changes",
+ ))
.subcommand(
Command::new("twice")
.about("Names, from records, a party that voted twice")
@@ -179,6 +185,9 @@ pub(crate) async fn main() -> Result<()> {
return out(&super::fork::root_file(&root, &[]));
}
let node = Node::new(&matches)?;
+ if name == "proposals" {
+ return proposals(&node).await;
+ }
if name == "fork" {
let version = version_in(sub.get_one::<String>("file").expect("required"))?;
let heads = strings(sub, "heads");
@@ -466,6 +475,55 @@ async fn again(node: &Node, signer: &Signer, record: &mut Record, path: &Path) -
Ok(())
}
+/// The proposals on the current version at `node`, each with whether it passed or is dead,
+/// who voted what, and what its version changes, as one of the events proposing it holds
+/// it.
+async fn proposals(node: &Node) -> Result<()> {
+ let counts = node.counts().await?;
+ let current = current(&counts)?;
+ let parties = |names: &JsonValue| -> String {
+ let names: Vec<&str> = names
+ .as_array()
+ .into_iter()
+ .flatten()
+ .filter_map(JsonValue::as_str)
+ .collect();
+ if names.is_empty() {
+ "nobody".to_owned()
+ } else {
+ names.join(", ")
+ }
+ };
+ for (hash, proposal) in counts["proposals"].as_object().into_iter().flatten() {
+ let standing = match (proposal["passed"].as_bool(), proposal["dead"].as_bool()) {
+ (Some(true), _) => "passed",
+ (_, Some(true)) => "dead",
+ _ => "can still pass",
+ };
+ println!(
+ "{hash}: {standing}; true: {}; false: {}",
+ parties(&proposal["yes"]),
+ parties(&proposal["no"])
+ );
+ let Some(id) = proposal["proposals"][0].as_str() else {
+ continue;
+ };
+ let id = Id::from_hex(id).ok_or_else(|| anyhow!("the node names no event ID: {id}"))?;
+ match Event::read(&node.event(&id).await?) {
+ Some(Event::Signed(Signed {
+ does: Does::Proposal { hash: of, version },
+ ..
+ })) if of.to_string() == *hash => {
+ for line in client::changes(&current.json, &version) {
+ println!(" {line}");
+ }
+ }
+ _ => println!(" the event {id} proposes no version of that hash"),
+ }
+ }
+ Ok(())
+}
+
/// The current version, as `counts` names it, checked: its hash its own.
fn current(counts: &JsonValue) -> Result<Version> {
let json = client::json(&counts["version"]["version"]).map_err(|why| anyhow!(why))?;