referrerpolicy=no-referrer-when-downgrade

polkadot_voter_bags/
main.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Make the set of voting bag thresholds to be used in `voter_bags.rs`.
18//!
19//! Generally speaking this script can be run once per runtime and never
20//! touched again. It can be reused to regenerate a wholly different
21//! quantity of bags, or if the existential deposit changes, etc.
22
23use clap::{Parser, ValueEnum};
24use generate_bags::generate_thresholds;
25use std::path::{Path, PathBuf};
26use westend_runtime::Runtime as WestendRuntime;
27
28#[derive(Clone, Debug, ValueEnum)]
29#[value(rename_all = "PascalCase")]
30enum Runtime {
31	Westend,
32}
33
34impl Runtime {
35	fn generate_thresholds_fn(
36		&self,
37	) -> Box<dyn FnOnce(usize, &Path, u128, u128) -> Result<(), std::io::Error>> {
38		match self {
39			Runtime::Westend => Box::new(generate_thresholds::<WestendRuntime>),
40		}
41	}
42}
43
44#[derive(Debug, Parser)]
45struct Opt {
46	/// How many bags to generate.
47	#[arg(long, default_value_t = 200)]
48	n_bags: usize,
49
50	/// Which runtime to generate.
51	#[arg(long, ignore_case = true, value_enum, default_value_t = Runtime::Westend)]
52	runtime: Runtime,
53
54	/// Where to write the output.
55	output: PathBuf,
56
57	/// The total issuance of the native currency.
58	#[arg(short, long)]
59	total_issuance: u128,
60
61	/// The minimum account balance (i.e. existential deposit) for the native currency.
62	#[arg(short, long)]
63	minimum_balance: u128,
64}
65
66fn main() -> Result<(), std::io::Error> {
67	let Opt { n_bags, output, runtime, total_issuance, minimum_balance } = Opt::parse();
68
69	runtime.generate_thresholds_fn()(n_bags, &output, total_issuance, minimum_balance)
70}