Skip to content

Commit

Permalink
fix(cli): add timeout to stdin read
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Oct 17, 2023
1 parent 53d4b19 commit bc4d88c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ chrono = { version = "0.4.23", default-features = false, features = [
clap = { version = "4.1.0", features = ["derive"] }
ethers = { version = "2.0.0", default-features = false, features = ["rustls"] }
graph-subscriptions = { path = "../graph-subscriptions-rs" }
tokio = { version = "1.24", features = ["macros", "rt"] }
tokio = { version = "1.24", features = ["io-std", "macros", "rt"] }
toolshed = { git = "https://github.com/edgeandnode/toolshed", tag = "v0.1.3", default-features = false, features = [
"url",
] }
12 changes: 10 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use chrono::{DateTime, Utc};
use clap::{Parser, Subcommand};
use ethers::{abi::Address, prelude::*};
use graph_subscriptions::{Subscription, Subscriptions, TicketPayload, IERC20};
use std::{io::stdin, str::FromStr as _, sync::Arc};
use std::time::Duration;
use std::{str::FromStr as _, sync::Arc};
use tokio::io::AsyncReadExt;
use tokio::time::timeout;
use toolshed::url::Url;

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -69,7 +72,12 @@ async fn main() -> Result<()> {
let token = IERC20::new(opt.token, provider.clone());

let mut secret_key = String::new();
stdin().read_line(&mut secret_key)?;
timeout(
Duration::from_secs(2),
tokio::io::stdin().read_to_string(&mut secret_key),
)
.await??;

let wallet = Wallet::from_str(secret_key.trim())?.with_chain_id(opt.chain_id);
drop(secret_key);
let client = SignerMiddleware::new(provider, wallet.clone());
Expand Down

0 comments on commit bc4d88c

Please sign in to comment.