From 748ac9309d21cb06e0c4c1a56fd8aabe61604bd3 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Mon, 17 Jul 2023 20:04:29 +0100 Subject: [PATCH] chore: use custom http client with timeout --- scripts/simple.sh | 2 +- src/client/near.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/simple.sh b/scripts/simple.sh index 6ec389e..f95137b 100755 --- a/scripts/simple.sh +++ b/scripts/simple.sh @@ -145,7 +145,7 @@ sleep 1 # Upgrading Aurora EVM to 2.9.0. curl -sL $ENGINE_LAST_WASM_URL -o $ENGINE_WASM_PATH || error_exit aurora-cli --engine $ENGINE_ACCOUNT stage-upgrade $ENGINE_WASM_PATH || error_exit -sleep 3 +sleep 2 aurora-cli --engine $ENGINE_ACCOUNT deploy-upgrade || error_exit sleep 1 version=$(aurora-cli --engine $ENGINE_ACCOUNT get-version || error_exit) diff --git a/src/client/near.rs b/src/client/near.rs index fc726df..1b943c0 100644 --- a/src/client/near.rs +++ b/src/client/near.rs @@ -27,6 +27,7 @@ use crate::utils; // The maximum amount of prepaid NEAR gas required for paying for a transaction. const NEAR_GAS: u64 = 300_000_000_000_000; +const TIMEOUT: u64 = 20; pub struct NearClient { client: JsonRpcClient, @@ -36,7 +37,19 @@ pub struct NearClient { impl NearClient { pub fn new(url: U, engine_account_id: &str, signer_key_path: Option) -> Self { - let client = JsonRpcClient::connect(url); + let mut headers = reqwest::header::HeaderMap::with_capacity(2); + headers.insert( + reqwest::header::CONTENT_TYPE, + reqwest::header::HeaderValue::from_static("application/json"), + ); + let client = reqwest::Client::builder() + .timeout(std::time::Duration::from_secs(TIMEOUT)) + .default_headers(headers) + .build() + .map(JsonRpcClient::with) + .expect("couldn't create json rpc client"); + let client = client.connect(url); + Self { client, engine_account_id: engine_account_id.parse().unwrap(),