Skip to main content

soroban_cli/commands/tx/new/
set_trustline_flags.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)]
15#[allow(clippy::struct_excessive_bools, clippy::doc_markdown)]
16pub struct Args {
17    /// Account to set trustline flags for, e.g. `GBX...`, or alias, or muxed account, `M123...``
18    #[arg(long)]
19    pub trustor: address::UnresolvedMuxedAccount,
20    /// Asset to set trustline flags for
21    #[arg(long)]
22    pub asset: builder::Asset,
23    #[arg(long, conflicts_with = "clear_authorize")]
24    /// Signifies complete authorization allowing an account to transact freely with the asset to make and receive payments and place orders.
25    pub set_authorize: bool,
26    #[arg(long, conflicts_with = "clear_authorize_to_maintain_liabilities")]
27    /// Denotes limited authorization that allows an account to maintain current orders but not to otherwise transact with the asset.
28    pub set_authorize_to_maintain_liabilities: bool,
29    #[arg(long, conflicts_with = "clear_trustline_clawback_enabled")]
30    /// Enables the issuing account to take back (burning) all of the asset. See our section on Clawbacks:
31    /// https://developers.stellar.org/docs/learn/encyclopedia/transactions-specialized/clawbacks
32    pub set_trustline_clawback_enabled: bool,
33    #[arg(long)]
34    pub clear_authorize: bool,
35    #[arg(long)]
36    pub clear_authorize_to_maintain_liabilities: bool,
37    #[arg(long)]
38    pub clear_trustline_clawback_enabled: bool,
39}
40
41impl TryFrom<&Cmd> for xdr::OperationBody {
42    type Error = tx::args::Error;
43    fn try_from(cmd: &Cmd) -> Result<Self, Self::Error> {
44        let mut set_flags = 0;
45        let mut set_flag = |flag: xdr::TrustLineFlags| set_flags |= flag as u32;
46
47        if cmd.op.set_authorize {
48            set_flag(xdr::TrustLineFlags::AuthorizedFlag);
49        }
50        if cmd.op.set_authorize_to_maintain_liabilities {
51            set_flag(xdr::TrustLineFlags::AuthorizedToMaintainLiabilitiesFlag);
52        }
53        if cmd.op.set_trustline_clawback_enabled {
54            set_flag(xdr::TrustLineFlags::TrustlineClawbackEnabledFlag);
55        }
56
57        let mut clear_flags = 0;
58        let mut clear_flag = |flag: xdr::TrustLineFlags| clear_flags |= flag as u32;
59        if cmd.op.clear_authorize {
60            clear_flag(xdr::TrustLineFlags::AuthorizedFlag);
61        }
62        if cmd.op.clear_authorize_to_maintain_liabilities {
63            clear_flag(xdr::TrustLineFlags::AuthorizedToMaintainLiabilitiesFlag);
64        }
65        if cmd.op.clear_trustline_clawback_enabled {
66            clear_flag(xdr::TrustLineFlags::TrustlineClawbackEnabledFlag);
67        }
68
69        Ok(xdr::OperationBody::SetTrustLineFlags(
70            xdr::SetTrustLineFlagsOp {
71                trustor: cmd.tx.resolve_account_id(&cmd.op.trustor)?,
72                asset: cmd.tx.resolve_asset(&cmd.op.asset)?,
73                clear_flags,
74                set_flags,
75            },
76        ))
77    }
78}