Skip to main content

soroban_cli/commands/tx/
sign.rs

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