partner_chains_smart_contracts_commands/
sign_tx.rs

1use crate::PaymentFilePath;
2use partner_chains_cardano_offchain::sign_tx::sign_tx;
3use serde_json::json;
4use sidechain_domain::TransactionCbor;
5
6#[derive(Clone, Debug, clap::Parser)]
7/// Command for signing a cardano transaction
8pub struct SignTxCmd {
9	#[arg(long, value_parser = TransactionCbor::decode_hex)]
10	/// Hex-encoded transaction CBOR (with or without 0x prefix)
11	transaction: TransactionCbor,
12	#[clap(flatten)]
13	/// Path to the Cardano Signing Key file that you want to sign the transaction with
14	payment_key_file: PaymentFilePath,
15}
16
17impl SignTxCmd {
18	/// Signs a cardano transaction
19	pub async fn execute(self) -> crate::SubCmdResult {
20		let payment_key = self.payment_key_file.read_key()?;
21
22		let vkey_witness = sign_tx(self.transaction.0, &payment_key)?;
23
24		let json = json!(
25			{
26				"type": "TxWitness ConwayEra",
27				"description": "",
28				"cborHex": hex::encode(vkey_witness)
29			}
30		);
31		Ok(json)
32	}
33}