fix: faucet health check uses JSON-RPC instead of REST
The synord RPC server is JSON-RPC only, not REST. Changed health check from GET /health to POST with synor_getInfo method.
This commit is contained in:
parent
cca23a4019
commit
33fd1a015f
1 changed files with 35 additions and 6 deletions
|
|
@ -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<serde_json::Value>,
|
||||
#[allow(dead_code)]
|
||||
error: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
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::<RpcResponse>().await {
|
||||
Ok(resp) => resp.result.is_some(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate Synor address format.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue