Skip to content

Commit

Permalink
chore: use custom http client with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss committed Jul 17, 2023
1 parent 3858860 commit 258ebbf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/client/near.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,7 +37,19 @@ pub struct NearClient {

impl NearClient {
pub fn new<U: AsUrl>(url: U, engine_account_id: &str, signer_key_path: Option<String>) -> 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(),
Expand Down

0 comments on commit 258ebbf

Please sign in to comment.