partner_chains_smart_contracts_commands/
d_parameter.rs

1use crate::{GenesisUtxo, PaymentFilePath, option_to_json};
2use partner_chains_cardano_offchain::d_param::upsert_d_param;
3use sidechain_domain::DParameter;
4
5#[derive(Clone, Debug, clap::Parser)]
6/// Command for upserting the D-parameter on the main chain
7pub struct UpsertDParameterCmd {
8	#[clap(flatten)]
9	common_arguments: crate::CommonArguments,
10	#[arg(long)]
11	/// Number of permissioned candidates
12	permissioned_candidates_count: u16,
13	#[arg(long)]
14	/// Number of registered candidates
15	registered_candidates_count: u16,
16	#[clap(flatten)]
17	/// Path to the payment key file
18	payment_key_file: PaymentFilePath,
19	#[clap(flatten)]
20	/// Genesis UTXO
21	genesis_utxo: GenesisUtxo,
22}
23
24impl UpsertDParameterCmd {
25	/// Creates the D-parameter and upserts it on the main chain.
26	pub async fn execute(self) -> crate::SubCmdResult {
27		let payment_key = self.payment_key_file.read_key()?;
28		let d_param = DParameter {
29			num_permissioned_candidates: self.permissioned_candidates_count,
30			num_registered_candidates: self.registered_candidates_count,
31		};
32		let client = self.common_arguments.get_ogmios_client().await?;
33
34		let result = upsert_d_param(
35			self.genesis_utxo.into(),
36			&d_param,
37			&payment_key,
38			&client,
39			&self.common_arguments.retries(),
40		)
41		.await?;
42
43		Ok(option_to_json(result))
44	}
45}