partner_chains_smart_contracts_commands/
versioning.rs

1use crate::{GenesisUtxo, PaymentFilePath, option_to_json};
2use partner_chains_cardano_offchain::{
3	plutus_script::PlutusScript, versioning_system::upsert_script,
4};
5use sidechain_domain::PlutusScriptCbor;
6
7#[derive(Clone, Debug, clap::Parser)]
8/// Command for upserting the versioned script on the mainchain
9pub struct UpsertScriptCmd {
10	#[clap(flatten)]
11	common_arguments: crate::CommonArguments,
12	#[arg(long)]
13	/// Script ID
14	script_id: u32,
15	#[arg(long)]
16	/// CBOR encoded Plutus V2 script
17	plutus_script: PlutusScriptCbor,
18	#[clap(flatten)]
19	/// Path to the payment key file
20	payment_key_file: PaymentFilePath,
21	#[clap(flatten)]
22	/// Genesis UTXO
23	genesis_utxo: GenesisUtxo,
24}
25
26impl UpsertScriptCmd {
27	/// Creates or updates a versioning utxo with reference script
28	pub async fn execute(self) -> crate::SubCmdResult {
29		let payment_key = self.payment_key_file.read_key()?;
30
31		let client = self.common_arguments.get_ogmios_client().await?;
32
33		let result = upsert_script(
34			PlutusScript::v2_from_cbor(&self.plutus_script.0)?,
35			self.script_id,
36			self.genesis_utxo.into(),
37			&payment_key,
38			&client,
39			&self.common_arguments.retries(),
40		)
41		.await?;
42
43		Ok(option_to_json(result))
44	}
45}