diff options
Diffstat (limited to 'src/federation/party.rs')
| -rw-r--r-- | src/federation/party.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs index ecd75a9..cb9eb54 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -4,7 +4,9 @@ //! keeps its party's record (`--record`, `client::Record`), by which it votes, written //! before a vote is sent. //! -//! * `init PARTY`: begins a record of `PARTY`, on the version current now; +//! * `init PARTY`: begins a record of `PARTY`, on the version current now; with `--root +//! FILE`, from the file the store's swarm starts from, for a party that never voted in +//! it: the record casts on every version, the first too; //! * `write PATH VALUE`: writes `VALUE` (JSON) at `PATH`; //! * `keys KEY...`, `nodes NODE...`: writes the party's key set (`authorized_keys` lines) //! or node list (node IDs); @@ -76,7 +78,13 @@ fn command() -> Command { .subcommand( Command::new("init") .about("Begins a record") - .arg(id("party")), + .arg(id("party")) + .arg( + Arg::new("root") + .long("root") + .value_name("FILE") + .help("From the file the store's swarm starts from, for a party that never voted in it"), + ), ) .subcommand( Command::new("write") @@ -224,10 +232,22 @@ pub(crate) async fn main() -> Result<()> { bail!("{} holds a record already", path.display()); } let party = sub.get_one::<String>("party").expect("required"); - let (store, _) = node.summary().await?; - let record = Record::begin(store, party, &node.current().await?); + let record = match sub.get_one::<String>("root") { + Some(file) => { + let bytes = std::fs::read(file).with_context(|| format!("Reading {file}"))?; + let (root, kept) = super::fork::read_root_file(&bytes); + if let Err(refused) = Store::<Federation>::new(root.clone(), kept) { + bail!("no store's root: {}", refused.0); + } + Record::before(Id::of(&root), party) + } + None => { + let (store, _) = node.summary().await?; + Record::begin(store, party, &node.current().await?) + } + }; record.save(&path).map_err(|why| anyhow!(why))?; - println!("began a record of {party}, of the store {store}"); + println!("began a record of {party}, of the store {}", record.store); return Ok(()); } let mut record = Record::load(&path).map_err(|why| anyhow!(why))?; |
