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 bump_sequence;
8pub mod change_trust;
9pub mod create_account;
10pub mod manage_data;
11pub mod payment;
12pub mod set_options;
13pub mod set_trustline_flags;
14
15#[derive(Debug, Parser)]
16#[allow(clippy::doc_markdown)]
17pub enum Cmd {
18 #[command(about = super::help::ACCOUNT_MERGE)]
19 AccountMerge(account_merge::Cmd),
20 #[command(about = super::help::BUMP_SEQUENCE)]
21 BumpSequence(bump_sequence::Cmd),
22 #[command(about = super::help::CHANGE_TRUST)]
23 ChangeTrust(change_trust::Cmd),
24 #[command(about = super::help::CREATE_ACCOUNT)]
25 CreateAccount(create_account::Cmd),
26 #[command(about = super::help::MANAGE_DATA)]
27 ManageData(manage_data::Cmd),
28 #[command(about = super::help::PAYMENT)]
29 Payment(payment::Cmd),
30 #[command(about = super::help::SET_OPTIONS)]
31 SetOptions(set_options::Cmd),
32 #[command(about = super::help::SET_TRUSTLINE_FLAGS)]
33 SetTrustlineFlags(set_trustline_flags::Cmd),
34}
35
36#[derive(thiserror::Error, Debug)]
37pub enum Error {
38 #[error(transparent)]
39 Tx(#[from] super::args::Error),
40}
41
42impl TryFrom<&Cmd> for OperationBody {
43 type Error = super::args::Error;
44 fn try_from(cmd: &Cmd) -> Result<Self, Self::Error> {
45 Ok(match cmd {
46 Cmd::AccountMerge(cmd) => cmd.try_into()?,
47 Cmd::BumpSequence(cmd) => cmd.into(),
48 Cmd::ChangeTrust(cmd) => cmd.try_into()?,
49 Cmd::CreateAccount(cmd) => cmd.try_into()?,
50 Cmd::ManageData(cmd) => cmd.into(),
51 Cmd::Payment(cmd) => cmd.try_into()?,
52 Cmd::SetOptions(cmd) => cmd.try_into()?,
53 Cmd::SetTrustlineFlags(cmd) => cmd.try_into()?,
54 })
55 }
56}
57
58impl Cmd {
59 pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
60 let op = OperationBody::try_from(self)?;
61 match self {
62 Cmd::AccountMerge(cmd) => cmd.tx.handle_and_print(op, global_args).await,
63 Cmd::BumpSequence(cmd) => cmd.tx.handle_and_print(op, global_args).await,
64 Cmd::ChangeTrust(cmd) => cmd.tx.handle_and_print(op, global_args).await,
65 Cmd::CreateAccount(cmd) => cmd.tx.handle_and_print(op, global_args).await,
66 Cmd::ManageData(cmd) => cmd.tx.handle_and_print(op, global_args).await,
67 Cmd::Payment(cmd) => cmd.tx.handle_and_print(op, global_args).await,
68 Cmd::SetOptions(cmd) => cmd.tx.handle_and_print(op, global_args).await,
69 Cmd::SetTrustlineFlags(cmd) => cmd.tx.handle_and_print(op, global_args).await,
70 }?;
71 Ok(())
72 }
73}