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 11, 2024
1 parent b6a1878 commit 0e71259
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions cmd/soroban-cli/src/config/sign_with.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::path::PathBuf;

use crate::{
signer::{self, sign_txn_env, Stellar},
xdr::TransactionEnvelope,
};
use clap::arg;
use crossterm::event::{read, Event, KeyCode};
use soroban_env_host::xdr::WriteXdr;
use soroban_sdk::xdr::Limits;
use std::path::PathBuf;
use url::Url;

use super::{
Expand Down Expand Up @@ -35,6 +35,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 @@ -101,6 +104,17 @@ impl Args {
}

pub fn sign_tx_env_with_lab(&self, 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 = self.get_network()?.network_passphrase;
let xdr_buffer = tx_env.to_xdr_base64(Limits::none())?;

Expand All @@ -125,3 +139,15 @@ impl Args {
Ok(self.locator.config_dir()?)
}
}

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 0e71259

Please sign in to comment.