Skip to main content

soroban_cli/commands/tx/new/
payment.rs

1use clap::Parser;
2
3use crate::{commands::tx, config::address, tx::builder, xdr};
4
5#[derive(Parser, Debug, Clone)]
6#[group(skip)]
7pub struct Cmd {
8    #[command(flatten)]
9    pub tx: tx::Args,
10    #[clap(flatten)]
11    pub op: Args,
12}
13
14#[derive(Debug, clap::Args, Clone)]
15pub struct Args {
16    /// Account to send to, e.g. `GBX...`
17    #[arg(long)]
18    pub destination: address::UnresolvedMuxedAccount,
19    /// Asset to send, default native, e.i. XLM
20    #[arg(long, default_value = "native")]
21    pub asset: builder::Asset,
22    /// Amount of the aforementioned asset to send, in stroops. 1 stroop = 0.0000001 of the asset (e.g. 1 XLM = `10_000_000` stroops).
23    #[arg(long)]
24    pub amount: builder::Amount,
25}
26
27impl TryFrom<&Cmd> for xdr::OperationBody {
28    type Error = tx::args::Error;
29    fn try_from(
30        Cmd {
31            tx,
32            op:
33                Args {
34                    destination,
35                    asset,
36                    amount,
37                },
38        }: &Cmd,
39    ) -> Result<Self, Self::Error> {
40        Ok(xdr::OperationBody::Payment(xdr::PaymentOp {
41            destination: tx.resolve_muxed_address(destination)?,
42            asset: tx.resolve_asset(asset)?,
43            amount: amount.into(),
44        }))
45    }
46}