From bc4d88c0a6aa73f30cb1a3bf0eb0ecdf591e0d0a Mon Sep 17 00:00:00 2001 From: Theo Butler Date: Tue, 17 Oct 2023 12:14:18 -0400 Subject: [PATCH] fix(cli): add timeout to stdin read --- cli/Cargo.toml | 2 +- cli/src/main.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index fcc2a97..f23300e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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", ] } diff --git a/cli/src/main.rs b/cli/src/main.rs index eef4ddc..6032626 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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)] @@ -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());