Merkle tree operations (#164)

merkle tree operations added
This commit is contained in:
tyshko-rostyslav 2023-05-23 09:08:47 +02:00 committed by GitHub
parent d68dc1ad8e
commit fcd4854037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View File

@ -16,4 +16,21 @@ pub(crate) enum Commands {
#[arg(short, long)]
config: PathBuf,
},
SetTree {
tree_height: usize,
},
SetLeaf {
index: usize,
#[arg(short, long)]
file: PathBuf,
},
SetMultipleLeaves {
index: usize,
#[arg(short, long)]
file: PathBuf,
},
ResetMultipleLeaves {
#[arg(short, long)]
file: PathBuf,
},
}

View File

@ -1,7 +1,7 @@
use std::{fs::File, io::Read, path::Path};
use clap::Parser;
use color_eyre::Result;
use color_eyre::{Report, Result};
use commands::Commands;
use rln::public::RLN;
use state::State;
@ -51,6 +51,37 @@ fn main() -> Result<()> {
)?);
Ok(())
}
Some(Commands::SetTree { tree_height }) => {
state
.rln
.ok_or(Report::msg("no RLN initialized"))?
.set_tree(*tree_height)?;
Ok(())
}
Some(Commands::SetLeaf { index, file }) => {
let input_data = File::open(&file)?;
state
.rln
.ok_or(Report::msg("no RLN initialized"))?
.set_leaf(*index, input_data)?;
Ok(())
}
Some(Commands::SetMultipleLeaves { index, file }) => {
let input_data = File::open(&file)?;
state
.rln
.ok_or(Report::msg("no RLN initialized"))?
.set_leaves_from(*index, input_data)?;
Ok(())
}
Some(Commands::ResetMultipleLeaves { file }) => {
let input_data = File::open(&file)?;
state
.rln
.ok_or(Report::msg("no RLN initialized"))?
.init_tree_with_leaves(input_data)?;
Ok(())
}
None => Ok(()),
}
}