partner_chains_smart_contracts_commands/
register.rs

1use crate::{GenesisUtxo, PaymentFilePath, option_to_json, transaction_submitted_json};
2use partner_chains_cardano_offchain::register::{run_deregister, run_register};
3use sidechain_domain::{
4	AdaBasedStaking, CandidateRegistration, MainchainSignature, PermissionedCandidateData,
5	SidechainSignature, StakePoolPublicKey, UtxoId,
6};
7
8/// Command for registering a candidate on the main chain
9#[derive(Clone, Debug, clap::Parser)]
10pub struct RegisterCmd {
11	#[clap(flatten)]
12	common_arguments: crate::CommonArguments,
13	#[clap(flatten)]
14	/// Genesis UTXO
15	genesis_utxo: GenesisUtxo,
16	#[arg(long)]
17	/// UTXO that will be spend when executing registration transaction, part of the registration message
18	registration_utxo: UtxoId,
19	#[clap(flatten)]
20	/// Path to the payment key file
21	payment_key_file: PaymentFilePath,
22	#[arg(long, alias = "sidechain-public-keys")]
23	/// Candidate public keys in format PARTNER_CHAINS_KEY_HEX:AURA_KEY_HEX:GRANDPA_KEY_HEX or PARTNER_CHAINS_KEY_HEX,KEY_ID_1:KEY_1_HEX,...,KEY_ID_N:KEY_N_HEX
24	partner_chain_public_keys: PermissionedCandidateData,
25	#[arg(long, alias = "sidechain-signature")]
26	/// Hex string of bytes of the registration message signature by partner-chain key, obtained by 'registration-signatures' command
27	partner_chain_signature: SidechainSignature,
28	#[arg(long)]
29	/// Hex string representing bytes of the Stake Pool Verification Key
30	spo_public_key: StakePoolPublicKey,
31	#[arg(long)]
32	/// Hex string of bytes of the registration message signature by main chain key, obtained by 'registration-signatures' command
33	spo_signature: MainchainSignature,
34}
35
36impl RegisterCmd {
37	/// Registers a candidate on the main chain.
38	pub async fn execute(self) -> crate::SubCmdResult {
39		let payment_key = self.payment_key_file.read_key()?;
40		let client = self.common_arguments.get_ogmios_client().await?;
41		let candidate_registration = CandidateRegistration {
42			stake_ownership: AdaBasedStaking {
43				pub_key: self.spo_public_key,
44				signature: self.spo_signature,
45			},
46			partner_chain_pub_key: self.partner_chain_public_keys.sidechain_public_key,
47			partner_chain_signature: self.partner_chain_signature,
48			own_pkh: payment_key.to_pub_key_hash(),
49			registration_utxo: self.registration_utxo,
50			keys: self.partner_chain_public_keys.keys,
51		};
52
53		let result = run_register(
54			self.genesis_utxo.into(),
55			&candidate_registration,
56			&payment_key,
57			&client,
58			self.common_arguments.retries(),
59		)
60		.await?;
61		Ok(option_to_json(result.map(transaction_submitted_json)))
62	}
63}
64
65#[derive(Clone, Debug, clap::Parser)]
66/// Command for deregistering a candidate on the main chain
67pub struct DeregisterCmd {
68	#[clap(flatten)]
69	common_arguments: crate::CommonArguments,
70	#[clap(flatten)]
71	/// Genesis UTXO
72	genesis_utxo: GenesisUtxo,
73	#[clap(flatten)]
74	/// Path to the payment key file
75	payment_key_file: PaymentFilePath,
76	#[arg(long)]
77	/// Hex string representing bytes of the Stake Pool Verification Key
78	spo_public_key: StakePoolPublicKey,
79}
80
81impl DeregisterCmd {
82	/// Deregisters a candidate on the main chain.
83	pub async fn execute(self) -> crate::SubCmdResult {
84		let payment_signing_key = self.payment_key_file.read_key()?;
85		let client = self.common_arguments.get_ogmios_client().await?;
86
87		let result = run_deregister(
88			self.genesis_utxo.into(),
89			&payment_signing_key,
90			self.spo_public_key,
91			&client,
92			self.common_arguments.retries(),
93		)
94		.await?;
95		Ok(option_to_json(result.map(transaction_submitted_json)))
96	}
97}