Skip to content

Commit

Permalink
WIP: check yes flag
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Sep 13, 2024
1 parent c66425d commit f294d25
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion cmd/soroban-cli/src/config/sign_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use crate::{
xdr::TransactionEnvelope,
};
use clap::arg;
use crossterm::event::{read, Event, KeyCode};
use soroban_env_host::xdr::WriteXdr;
use soroban_sdk::xdr::{self, Limits};
use soroban_sdk::xdr::Limits;
use std::path::PathBuf;
use stellar_strkey::ed25519::PublicKey;
use url::Url;

Expand Down Expand Up @@ -39,6 +41,9 @@ pub enum Error {
Url(#[from] url::ParseError),
#[error(transparent)]
Open(#[from] std::io::Error),
#[error("User cancelled signing, perhaps need to remove --check")]
//todo pull this error into a common module instead of duplicating it here
UserCancelledSigning,
}

#[derive(Debug, clap::Args, Clone, Default)]
Expand Down Expand Up @@ -119,6 +124,17 @@ impl Args {
network: &Network,
tx_env: &TransactionEnvelope,
) -> Result<(), Error> {
if !self.yes {
//todo: bring this into a common mod instead of duplicating it here
eprintln!("Press 'y' or 'Y' for yes, any other key for no:");
match read_key() {
'y' | 'Y' => {
eprintln!("Signing now...");
}
_ => return Err(Error::UserCancelledSigning),
};
}

let passphrase = network.network_passphrase.clone();
let xdr_buffer = tx_env.to_xdr_base64(Limits::none())?;

Expand All @@ -135,3 +151,15 @@ impl Args {
Ok(())
}
}

pub fn read_key() -> char {
loop {
if let Event::Key(key) = read().unwrap() {
match key.code {
KeyCode::Char(c) => return c,
KeyCode::Esc => return '\x1b', // escape key
_ => (),
}
}
}
}

0 comments on commit f294d25

Please sign in to comment.