soroban_cli/commands/tx/
sign.rs

1use crate::{
2    commands::global,
3    config::{locator, network, sign_with},
4    xdr::{self, Limits, WriteXdr},
5};
6use std::ffi::OsString;
7
8#[derive(thiserror::Error, Debug)]
9pub enum Error {
10    #[error(transparent)]
11    XdrArgs(#[from] super::xdr::Error),
12    #[error(transparent)]
13    Network(#[from] network::Error),
14    #[error(transparent)]
15    Locator(#[from] locator::Error),
16    #[error(transparent)]
17    SignWith(#[from] sign_with::Error),
18    #[error(transparent)]
19    Xdr(#[from] xdr::Error),
20}
21
22#[derive(Debug, clap::Parser, Clone)]
23#[group(skip)]
24pub struct Cmd {
25    /// Base-64 transaction envelope XDR, or file containing XDR to decode, or stdin if empty
26    #[arg()]
27    pub tx_xdr: Option<OsString>,
28    #[command(flatten)]
29    pub sign_with: sign_with::Args,
30    #[command(flatten)]
31    pub network: network::Args,
32    #[command(flatten)]
33    pub locator: locator::Args,
34}
35
36impl Cmd {
37    #[allow(clippy::unused_async)]
38    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
39        let tx_env = super::xdr::tx_envelope_from_input(&self.tx_xdr)?;
40        let tx_env_signed = self
41            .sign_with
42            .sign_tx_env(
43                &tx_env,
44                &self.locator,
45                &self.network.get(&self.locator)?,
46                global_args.quiet,
47                None,
48            )
49            .await?;
50        println!("{}", tx_env_signed.to_xdr_base64(Limits::none())?);
51        Ok(())
52    }
53}