ghost-node/utils/generate-bags/src/main.rs

56 lines
1.6 KiB
Rust
Raw Normal View History

//! Make the set of voting bag thresholds to be used in `voter_bags.rs`.
//!
//! Generally speaking this script can be run once per runtime never touched
//! again. It can be resued to generate a wholly different quantity of bags,
//! or if the existential deposit changes, etc.
use clap::{Parser, ValueEnum};
use generate_bags::generate_thresholds;
use std::path::{Path, PathBuf};
use casper_runtime::Runtime as CasperRuntime;
#[derive(Clone, Debug, ValueEnum)]
#[value(rename_all = "kebab-case")]
enum Runtime {
Casper,
}
impl Runtime {
fn generate_thresholds_fn(
&self,
) -> Box<dyn FnOnce(usize, &Path, u128, u128) -> Result<(), std::io::Error>> {
match self {
Runtime::Casper => Box::new(generate_thresholds::<CasperRuntime>),
}
}
}
#[derive(Debug, Parser)]
struct Opt {
/// How many bags to generate.
#[arg(long, default_value_t = 200)]
n_bags: usize,
/// Which runtime to generate.
#[arg(long, ignore_case = true, value_enum, default_value_t = Runtime::Casper)]
runtime: Runtime,
/// Where to write the output.
#[arg(short, long, value_name="FILE")]
output: PathBuf,
/// The total issuance of the native currency (`value` * 10^18).
#[arg(short, long)]
total_issuance: u128,
/// The minimum account balance (i.e. existential deposit) for the native
/// currency. (`value` * 10^18)
#[arg(short, long)]
minimum_balance: u128,
}
fn main() -> Result<(), std::io::Error> {
let Opt { n_bags, output, runtime, total_issuance, minimum_balance } = Opt::parse();
runtime.generate_thresholds_fn()(n_bags, &output, total_issuance, minimum_balance)
}