-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathutils.rs
More file actions
53 lines (47 loc) · 1.72 KB
/
Copy pathutils.rs
File metadata and controls
53 lines (47 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::time::Duration;
use alloy::primitives::U256;
use eyre::Context;
use serde_json::json;
use url::Url;
use crate::{
config::MUXER_HTTP_MAX_LENGTH,
interop::ssv::types::{SSVNodeResponse, SSVPublicResponse},
wire::safe_read_http_response,
};
pub async fn request_ssv_pubkeys_from_ssv_node(
url: Url,
node_operator_id: U256,
http_timeout: Duration,
) -> eyre::Result<SSVNodeResponse> {
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
let body = json!({
"operators": [node_operator_id]
});
let response = client.get(url).json(&body).send().await.map_err(|e| {
if e.is_timeout() {
eyre::eyre!("Request to SSV node timed out: {e}")
} else {
eyre::eyre!("Error sending request to SSV node: {e}")
}
})?;
// Parse the response as JSON
let body_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH).await?;
serde_json::from_slice::<SSVNodeResponse>(&body_bytes).wrap_err("failed to parse SSV response")
}
pub async fn request_ssv_pubkeys_from_public_api(
url: Url,
http_timeout: Duration,
) -> eyre::Result<SSVPublicResponse> {
let client = reqwest::ClientBuilder::new().timeout(http_timeout).build()?;
let response = client.get(url).send().await.map_err(|e| {
if e.is_timeout() {
eyre::eyre!("Request to SSV public API timed out: {e}")
} else {
eyre::eyre!("Error sending request to SSV public API: {e}")
}
})?;
// Parse the response as JSON
let body_bytes = safe_read_http_response(response, MUXER_HTTP_MAX_LENGTH).await?;
serde_json::from_slice::<SSVPublicResponse>(&body_bytes)
.wrap_err("failed to parse SSV response")
}