soroban_cli/commands/tx/new/
mod.rs1use clap::Parser;
2use soroban_sdk::xdr::OperationBody;
3
4use super::global;
5
6pub mod account_merge;
7pub mod begin_sponsoring_future_reserves;
8pub mod bump_sequence;
9pub mod change_trust;
10pub mod claim_claimable_balance;
11pub mod clawback;
12pub mod clawback_claimable_balance;
13pub mod create_account;
14pub mod create_claimable_balance;
15pub mod create_passive_sell_offer;
16pub mod end_sponsoring_future_reserves;
17pub mod liquidity_pool_deposit;
18pub mod liquidity_pool_withdraw;
19pub mod manage_buy_offer;
20pub mod manage_data;
21pub mod manage_sell_offer;
22pub mod path_payment_strict_receive;
23pub mod path_payment_strict_send;
24pub mod payment;
25pub mod revoke_sponsorship;
26pub mod set_options;
27pub mod set_trustline_flags;
28
29#[derive(Debug, Parser)]
30#[allow(clippy::doc_markdown)]
31pub enum Cmd {
32 #[command(about = super::help::ACCOUNT_MERGE)]
33 AccountMerge(account_merge::Cmd),
34 #[command(about = super::help::BEGIN_SPONSORING_FUTURE_RESERVES)]
35 BeginSponsoringFutureReserves(begin_sponsoring_future_reserves::Cmd),
36 #[command(about = super::help::BUMP_SEQUENCE)]
37 BumpSequence(bump_sequence::Cmd),
38 #[command(about = super::help::CHANGE_TRUST)]
39 ChangeTrust(change_trust::Cmd),
40 #[command(about = super::help::CLAIM_CLAIMABLE_BALANCE)]
41 ClaimClaimableBalance(claim_claimable_balance::Cmd),
42 #[command(about = super::help::CLAWBACK)]
43 Clawback(clawback::Cmd),
44 #[command(about = super::help::CLAWBACK_CLAIMABLE_BALANCE)]
45 ClawbackClaimableBalance(clawback_claimable_balance::Cmd),
46 #[command(about = super::help::CREATE_ACCOUNT)]
47 CreateAccount(create_account::Cmd),
48 #[command(about = super::help::CREATE_CLAIMABLE_BALANCE)]
49 CreateClaimableBalance(create_claimable_balance::Cmd),
50 #[command(about = super::help::CREATE_PASSIVE_SELL_OFFER)]
51 CreatePassiveSellOffer(create_passive_sell_offer::Cmd),
52 #[command(about = super::help::END_SPONSORING_FUTURE_RESERVES)]
53 EndSponsoringFutureReserves(end_sponsoring_future_reserves::Cmd),
54 #[command(about = super::help::LIQUIDITY_POOL_DEPOSIT)]
55 LiquidityPoolDeposit(liquidity_pool_deposit::Cmd),
56 #[command(about = super::help::LIQUIDITY_POOL_WITHDRAW)]
57 LiquidityPoolWithdraw(liquidity_pool_withdraw::Cmd),
58 #[command(about = super::help::MANAGE_BUY_OFFER)]
59 ManageBuyOffer(manage_buy_offer::Cmd),
60 #[command(about = super::help::MANAGE_DATA)]
61 ManageData(manage_data::Cmd),
62 #[command(about = super::help::MANAGE_SELL_OFFER)]
63 ManageSellOffer(manage_sell_offer::Cmd),
64 #[command(about = super::help::PATH_PAYMENT_STRICT_SEND)]
65 PathPaymentStrictSend(path_payment_strict_send::Cmd),
66 #[command(about = super::help::PATH_PAYMENT_STRICT_RECEIVE)]
67 PathPaymentStrictReceive(path_payment_strict_receive::Cmd),
68 #[command(about = super::help::PAYMENT)]
69 Payment(payment::Cmd),
70 #[command(about = super::help::REVOKE_SPONSORSHIP)]
71 RevokeSponsorship(revoke_sponsorship::Cmd),
72 #[command(about = super::help::SET_OPTIONS)]
73 SetOptions(set_options::Cmd),
74 #[command(about = super::help::SET_TRUSTLINE_FLAGS)]
75 SetTrustlineFlags(set_trustline_flags::Cmd),
76}
77
78#[derive(thiserror::Error, Debug)]
79pub enum Error {
80 #[error(transparent)]
81 Tx(#[from] super::args::Error),
82}
83
84impl TryFrom<&Cmd> for OperationBody {
85 type Error = super::args::Error;
86 fn try_from(cmd: &Cmd) -> Result<Self, Self::Error> {
87 Ok(match cmd {
88 Cmd::AccountMerge(cmd) => cmd.try_into()?,
89 Cmd::BeginSponsoringFutureReserves(cmd) => cmd.try_into()?,
90 Cmd::BumpSequence(cmd) => cmd.into(),
91 Cmd::ChangeTrust(cmd) => cmd.try_into()?,
92 Cmd::ClaimClaimableBalance(cmd) => cmd.try_into()?,
93 Cmd::Clawback(cmd) => cmd.try_into()?,
94 Cmd::ClawbackClaimableBalance(cmd) => cmd.try_into()?,
95 Cmd::CreateAccount(cmd) => cmd.try_into()?,
96 Cmd::CreateClaimableBalance(cmd) => cmd.try_into()?,
97 Cmd::CreatePassiveSellOffer(cmd) => cmd.try_into()?,
98 Cmd::EndSponsoringFutureReserves(cmd) => cmd.into(),
99 Cmd::LiquidityPoolDeposit(cmd) => cmd.try_into()?,
100 Cmd::LiquidityPoolWithdraw(cmd) => cmd.try_into()?,
101 Cmd::ManageBuyOffer(cmd) => cmd.try_into()?,
102 Cmd::ManageData(cmd) => cmd.into(),
103 Cmd::ManageSellOffer(cmd) => cmd.try_into()?,
104 Cmd::PathPaymentStrictSend(cmd) => cmd.try_into()?,
105 Cmd::PathPaymentStrictReceive(cmd) => cmd.try_into()?,
106 Cmd::Payment(cmd) => cmd.try_into()?,
107 Cmd::RevokeSponsorship(cmd) => cmd.try_into()?,
108 Cmd::SetOptions(cmd) => cmd.try_into()?,
109 Cmd::SetTrustlineFlags(cmd) => cmd.try_into()?,
110 })
111 }
112}
113
114impl Cmd {
115 pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
116 let op = OperationBody::try_from(self)?;
117 match self {
118 Cmd::AccountMerge(cmd) => cmd.tx.handle_and_print(op, global_args).await,
119 Cmd::BeginSponsoringFutureReserves(cmd) => {
120 cmd.tx.handle_and_print(op, global_args).await
121 }
122 Cmd::BumpSequence(cmd) => cmd.tx.handle_and_print(op, global_args).await,
123 Cmd::ChangeTrust(cmd) => cmd.tx.handle_and_print(op, global_args).await,
124 Cmd::ClaimClaimableBalance(cmd) => cmd.tx.handle_and_print(op, global_args).await,
125 Cmd::Clawback(cmd) => cmd.tx.handle_and_print(op, global_args).await,
126 Cmd::ClawbackClaimableBalance(cmd) => cmd.tx.handle_and_print(op, global_args).await,
127 Cmd::CreateAccount(cmd) => cmd.tx.handle_and_print(op, global_args).await,
128 Cmd::CreateClaimableBalance(cmd) => cmd.tx.handle_and_print(op, global_args).await,
129 Cmd::CreatePassiveSellOffer(cmd) => cmd.tx.handle_and_print(op, global_args).await,
130 Cmd::EndSponsoringFutureReserves(cmd) => cmd.tx.handle_and_print(op, global_args).await,
131 Cmd::LiquidityPoolDeposit(cmd) => cmd.tx.handle_and_print(op, global_args).await,
132 Cmd::LiquidityPoolWithdraw(cmd) => cmd.tx.handle_and_print(op, global_args).await,
133 Cmd::ManageBuyOffer(cmd) => cmd.tx.handle_and_print(op, global_args).await,
134 Cmd::ManageData(cmd) => cmd.tx.handle_and_print(op, global_args).await,
135 Cmd::ManageSellOffer(cmd) => cmd.tx.handle_and_print(op, global_args).await,
136 Cmd::PathPaymentStrictSend(cmd) => cmd.tx.handle_and_print(op, global_args).await,
137 Cmd::PathPaymentStrictReceive(cmd) => cmd.tx.handle_and_print(op, global_args).await,
138 Cmd::Payment(cmd) => cmd.tx.handle_and_print(op, global_args).await,
139 Cmd::RevokeSponsorship(cmd) => cmd.tx.handle_and_print(op, global_args).await,
140 Cmd::SetOptions(cmd) => cmd.tx.handle_and_print(op, global_args).await,
141 Cmd::SetTrustlineFlags(cmd) => cmd.tx.handle_and_print(op, global_args).await,
142 }?;
143 Ok(())
144 }
145}