diff --git a/apps/faucet/src/main.rs b/apps/faucet/src/main.rs index 7e8a222..dd7b023 100644 --- a/apps/faucet/src/main.rs +++ b/apps/faucet/src/main.rs @@ -600,16 +600,45 @@ async fn faucet( } } -/// Check if the RPC node is reachable. +/// Check if the RPC node is reachable via JSON-RPC. async fn check_rpc_connection(state: &FaucetState) -> bool { - let url = format!("{}/health", state.config.rpc_url); - state + #[derive(Serialize)] + struct RpcRequest { + jsonrpc: &'static str, + method: &'static str, + params: Vec<()>, + id: u64, + } + + #[derive(Deserialize)] + struct RpcResponse { + result: Option, + #[allow(dead_code)] + error: Option, + } + + let request = RpcRequest { + jsonrpc: "2.0", + method: "synor_getInfo", + params: vec![], + id: 1, + }; + + let response = match state .http_client - .get(&url) + .post(&state.config.rpc_url) + .json(&request) .send() .await - .map(|r| r.status().is_success()) - .unwrap_or(false) + { + Ok(r) if r.status().is_success() => r, + _ => return false, + }; + + match response.json::().await { + Ok(resp) => resp.result.is_some(), + Err(_) => false, + } } /// Validate Synor address format.