partner_chains_smart_contracts_commands/
bridge.rs1use crate::{GenesisUtxo, PaymentFilePath, transaction_submitted_json};
2use partner_chains_cardano_offchain::bridge::{
3 create_validator_utxos, deposit_with_ics_spend, deposit_without_ics_input, init_ics_scripts,
4};
5use sidechain_domain::AssetId;
6use sp_runtime::AccountId32;
7use std::num::NonZero;
8
9#[derive(Clone, Debug, clap::Subcommand)]
10pub enum BridgeCmd {
12 Init(BridgeInitCmd),
14 CreateUtxos(BridgeCreateUtxosCmd),
16 Deposit(BridgeDepositCmd),
18}
19
20impl BridgeCmd {
21 pub async fn execute(self) -> crate::SubCmdResult {
23 match self {
24 Self::Init(cmd) => cmd.execute().await,
25 Self::CreateUtxos(cmd) => cmd.execute().await,
26 Self::Deposit(cmd) => cmd.execute().await,
27 }
28 }
29}
30
31#[derive(Clone, Debug, clap::Parser)]
32pub struct BridgeInitCmd {
34 #[clap(flatten)]
35 common_arguments: crate::CommonArguments,
36 #[clap(flatten)]
37 payment_key_file: PaymentFilePath,
39 #[clap(flatten)]
40 genesis_utxo: GenesisUtxo,
42}
43
44impl BridgeInitCmd {
45 pub async fn execute(self) -> crate::SubCmdResult {
46 let payment_key = self.payment_key_file.read_key()?;
47 let client = self.common_arguments.get_ogmios_client().await?;
48 let result = init_ics_scripts(
49 self.genesis_utxo.into(),
50 &payment_key,
51 &client,
52 &self.common_arguments.retries(),
53 )
54 .await?;
55 Ok(serde_json::json!(result))
56 }
57}
58
59#[derive(Clone, Debug, clap::Parser)]
60pub struct BridgeCreateUtxosCmd {
62 #[clap(flatten)]
63 common_arguments: crate::CommonArguments,
64 #[clap(flatten)]
65 payment_key_file: PaymentFilePath,
67 #[clap(flatten)]
68 genesis_utxo: GenesisUtxo,
70 #[arg(long)]
71 amount: NonZero<u64>,
73}
74
75impl BridgeCreateUtxosCmd {
76 pub async fn execute(self) -> crate::SubCmdResult {
77 let payment_key = self.payment_key_file.read_key()?;
78 let client = self.common_arguments.get_ogmios_client().await?;
79 let result = create_validator_utxos(
80 self.genesis_utxo.into(),
81 self.amount,
82 &payment_key,
83 &client,
84 &self.common_arguments.retries(),
85 )
86 .await?;
87 Ok(serde_json::json!(result))
88 }
89}
90
91#[derive(Clone, Debug, clap::Parser)]
92pub struct BridgeDepositCmd {
94 #[clap(flatten)]
95 common_arguments: crate::CommonArguments,
96 #[arg(long)]
97 token: AssetId,
99 #[arg(long)]
100 amount: NonZero<u64>,
102 #[arg(long)]
103 pc_address: AccountId32,
105 #[arg(long)]
106 simple: bool,
108 #[clap(flatten)]
109 payment_key_file: PaymentFilePath,
111 #[clap(flatten)]
112 genesis_utxo: GenesisUtxo,
114}
115
116impl BridgeDepositCmd {
117 pub async fn execute(self) -> crate::SubCmdResult {
119 let payment_key = self.payment_key_file.read_key()?;
120 let client = self.common_arguments.get_ogmios_client().await?;
121 let tx_hash = if self.simple {
122 deposit_without_ics_input(
123 self.genesis_utxo.into(),
124 self.token,
125 self.amount,
126 self.pc_address.as_ref(),
127 &payment_key,
128 &client,
129 &self.common_arguments.retries(),
130 )
131 .await?
132 } else {
133 deposit_with_ics_spend(
134 self.genesis_utxo.into(),
135 self.token,
136 self.amount,
137 self.pc_address.as_ref(),
138 &payment_key,
139 &client,
140 &self.common_arguments.retries(),
141 )
142 .await?
143 };
144 Ok(transaction_submitted_json(tx_hash))
145 }
146}