esplora_btc_api/apis/
fee_estimates_api.rs

1/*
2 * Blockstream Esplora HTTP API
3 *
4 * JSON over RESTful HTTP. Amounts are always represented in satoshis.
5 *
6 * The version of the OpenAPI document: 1.0.1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `get_fee_estimates`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetFeeEstimatesError {
22    DefaultResponse(Vec<f32>),
23    UnknownValue(serde_json::Value),
24}
25
26
27pub async fn get_fee_estimates(configuration: &configuration::Configuration, ) -> Result<Vec<f32>, Error<GetFeeEstimatesError>> {
28
29    let local_var_client = &configuration.client;
30
31    let local_var_uri_str = format!("{}/fee-estimates", configuration.base_path);
32    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
33
34    if let Some(ref local_var_user_agent) = configuration.user_agent {
35        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
36    }
37
38    let local_var_req = local_var_req_builder.build()?;
39    let local_var_resp = local_var_client.execute(local_var_req).await?;
40
41    let local_var_status = local_var_resp.status();
42    let local_var_content = local_var_resp.text().await?;
43
44    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
45        serde_json::from_str(&local_var_content).map_err(Error::from)
46    } else {
47        let local_var_entity: Option<GetFeeEstimatesError> = serde_json::from_str(&local_var_content).ok();
48        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
49        Err(Error::ResponseError(local_var_error))
50    }
51}
52