Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto
# Force LF endings for Rust code and common text files
*.rs text eol=lf
*.toml text eol=lf
*.md text eol=lf
24 changes: 12 additions & 12 deletions crates/core/src/network/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//! Manages RPC endpoints, archive URLs, network passphrases for
//! mainnet/testnet/futurenet/standalone networks.

use crate::network::jsonrpc::{GetHealthParams, JsonRpcRequest, JsonRpcTransport};
use crate::types::config::{Network, NetworkConfig};
use std::time::Duration;

/// Resolve a network name string to a `NetworkConfig`.
///
Expand All @@ -27,18 +29,16 @@ pub fn default_network() -> NetworkConfig {
}

/// Validate that a network configuration is reachable.
///
/// Uses the timeout from [`NetworkConfig::request_timeout_secs`] so a
/// misconfigured or unreachable endpoint does not block the caller
/// indefinitely.
pub async fn validate_network(config: &NetworkConfig) -> bool {
let client = reqwest::Client::new();
client
.post(&config.rpc_url)
.json(&serde_json::json!({
"jsonrpc": "2.0",
"id": 1,
"method": "getHealth",
"params": {}
}))
.send()
let timeout = Duration::from_secs(config.request_timeout_secs);
let transport = JsonRpcTransport::new(&config.rpc_url, 0, timeout);
let req = JsonRpcRequest::new(1, "getHealth", GetHealthParams {});
transport
.call::<_, serde_json::Value>(&req)
.await
.map(|r| r.status().is_success())
.unwrap_or(false)
.is_ok()
}
Loading