soroban_cli/config/
sign_with.rsuse crate::{
print::Print,
signer::{self, Signer, SignerKind},
xdr::{self, TransactionEnvelope},
};
use clap::arg;
use super::{
locator,
network::{self, Network},
secret,
};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Signer(#[from] signer::Error),
#[error(transparent)]
Secret(#[from] secret::Error),
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
Rpc(#[from] soroban_rpc::Error),
#[error("No sign with key provided")]
NoSignWithKey,
#[error(transparent)]
StrKey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
Xdr(#[from] xdr::Error),
}
#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
pub struct Args {
#[arg(long, env = "STELLAR_SIGN_WITH_KEY")]
pub sign_with_key: Option<String>,
#[arg(long, requires = "sign_with_key")]
pub hd_path: Option<usize>,
#[allow(clippy::doc_markdown)]
#[arg(long, conflicts_with = "sign_with_key", env = "STELLAR_SIGN_WITH_LAB")]
pub sign_with_lab: bool,
}
impl Args {
pub fn sign_tx_env(
&self,
tx: &TransactionEnvelope,
locator: &locator::Args,
network: &Network,
quiet: bool,
) -> Result<TransactionEnvelope, Error> {
let print = Print::new(quiet);
let signer = if self.sign_with_lab {
Signer {
kind: SignerKind::Lab,
print,
}
} else {
let key_or_name = self.sign_with_key.as_deref().ok_or(Error::NoSignWithKey)?;
let secret = locator.key(key_or_name)?;
secret.signer(self.hd_path, print)?
};
Ok(signer.sign_tx_env(tx, network)?)
}
}