partner_chains_smart_contracts_commands/
assemble_tx.rs

1use crate::transaction_submitted_json;
2use partner_chains_cardano_offchain::assemble_and_submit_tx::assemble_and_submit_tx;
3use partner_chains_cardano_offchain::csl::{transaction_from_bytes, vkey_witness_from_bytes};
4use sidechain_domain::{TransactionCbor, VKeyWitnessCbor};
5
6#[derive(Clone, Debug, clap::Parser)]
7/// Command for assembling transaction with additional witnesses, and submitting it to the chain
8pub struct AssembleAndSubmitCmd {
9	#[clap(flatten)]
10	common_arguments: crate::CommonArguments,
11	#[arg(long, value_parser = TransactionCbor::decode_hex)]
12	/// Hex-encoded transaction CBOR (with or without 0x prefix)
13	transaction: TransactionCbor,
14	#[arg(short, long, num_args = 1.., value_delimiter = ' ', value_parser = VKeyWitnessCbor::decode_hex)]
15	/// Witnesses of the transaction. Each witness is a hex-encoded CBOR (with or without 0x prefix), encoding a 1 element list containing a 2 elements list [[public_key, signature]].
16	witnesses: Vec<VKeyWitnessCbor>,
17}
18
19impl AssembleAndSubmitCmd {
20	/// Deserialises the transaction and witnesses, combines them and submits the transaction to the chain.
21	pub async fn execute(self) -> crate::SubCmdResult {
22		let client = self.common_arguments.get_ogmios_client().await?;
23
24		let transaction = transaction_from_bytes(self.transaction.0)?;
25
26		let witnesses = self
27			.witnesses
28			.iter()
29			.map(|w| vkey_witness_from_bytes(w.0.clone().into_iter().skip(2).collect()))
30			.collect::<Result<Vec<_>, _>>()?;
31
32		let tx_hash = assemble_and_submit_tx(
33			transaction,
34			witnesses,
35			&client,
36			&self.common_arguments.retries(),
37		)
38		.await?;
39		Ok(transaction_submitted_json(tx_hash))
40	}
41}