-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Leigh McCulloch <[email protected]>
- Loading branch information
1 parent
d567965
commit b47be01
Showing
12 changed files
with
258 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{ | ||
commands::global, | ||
config::{locator, network, sign_with}, | ||
xdr::{self, Limits, WriteXdr}, | ||
}; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
XdrArgs(#[from] super::xdr::Error), | ||
#[error(transparent)] | ||
Network(#[from] network::Error), | ||
#[error(transparent)] | ||
Locator(#[from] locator::Error), | ||
#[error(transparent)] | ||
SignWith(#[from] sign_with::Error), | ||
#[error(transparent)] | ||
Xdr(#[from] xdr::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
#[command(flatten)] | ||
pub sign_with: sign_with::Args, | ||
#[command(flatten)] | ||
pub network: network::Args, | ||
#[command(flatten)] | ||
pub locator: locator::Args, | ||
} | ||
|
||
impl Cmd { | ||
#[allow(clippy::unused_async)] | ||
pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> { | ||
let tx_env = super::xdr::tx_envelope_from_stdin()?; | ||
let tx_env_signed = self.sign_with.sign_tx_env( | ||
tx_env, | ||
&self.locator, | ||
&self.network.get(&self.locator)?, | ||
global_args.quiet, | ||
)?; | ||
println!("{}", tx_env_signed.to_xdr_base64(Limits::none())?); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::{signer, xdr::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), | ||
} | ||
|
||
#[derive(Debug, clap::Args, Clone, Default)] | ||
#[group(skip)] | ||
pub struct Args { | ||
/// Sign with a local key. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path. | ||
#[arg(long, env = "STELLAR_SIGN_WITH_KEY")] | ||
pub sign_with_key: Option<String>, | ||
|
||
#[arg(long, requires = "sign_with_key")] | ||
/// If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0` | ||
pub hd_path: Option<usize>, | ||
} | ||
|
||
impl Args { | ||
pub fn sign_tx_env( | ||
&self, | ||
tx: TransactionEnvelope, | ||
locator: &locator::Args, | ||
network: &Network, | ||
quiet: bool, | ||
) -> Result<TransactionEnvelope, Error> { | ||
let key_or_name = self.sign_with_key.as_deref().ok_or(Error::NoSignWithKey)?; | ||
let secret = locator.key(key_or_name)?; | ||
let signer = secret.signer(self.hd_path, quiet)?; | ||
Ok(signer.sign_tx_env(tx, network)?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.