Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cast): add --rpc-timeout option #9044

Merged
merged 14 commits into from
Oct 24, 2024
Merged
19 changes: 17 additions & 2 deletions crates/cast/bin/cmd/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Duration;

use cast::Cast;
use clap::Parser;
use eyre::Result;
Expand Down Expand Up @@ -29,16 +31,29 @@ pub struct RpcArgs {
#[arg(long, short = 'w')]
raw: bool,

/// Timeout for the rpc request
///
/// The timeout will be used to override the default timeout for RPC.
/// Default value is 45s
#[arg(long, env = "ETH_RPC_TIMEOUT")]
pub timeout: Option<u64>,
zerosnacks marked this conversation as resolved.
Show resolved Hide resolved

#[command(flatten)]
rpc: RpcOpts,
}

impl RpcArgs {
pub async fn run(self) -> Result<()> {
let Self { raw, method, params, rpc } = self;
let Self { raw, method, params, rpc, timeout } = self;

let config = Config::from(&rpc);
let provider = utils::get_provider(&config)?;
let mut builder = utils::get_provider_builder(&config)?;

if let Some(timeout) = timeout {
builder = builder.timeout(Duration::from_secs(timeout));
}

let provider = builder.build()?;

let params = if raw {
if params.is_empty() {
Expand Down
Loading