esplora_btc_api/apis/
mempool_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetMempoolError {
22 DefaultResponse(crate::models::Mempool),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetMempoolRecentError {
30 DefaultResponse(Vec<crate::models::InlineResponseDefault4>),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetMempoolTxidsError {
38 DefaultResponse(Vec<String>),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_mempool(configuration: &configuration::Configuration, ) -> Result<crate::models::Mempool, Error<GetMempoolError>> {
44
45 let local_var_client = &configuration.client;
46
47 let local_var_uri_str = format!("{}/mempool", configuration.base_path);
48 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
49
50 if let Some(ref local_var_user_agent) = configuration.user_agent {
51 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
52 }
53
54 let local_var_req = local_var_req_builder.build()?;
55 let local_var_resp = local_var_client.execute(local_var_req).await?;
56
57 let local_var_status = local_var_resp.status();
58 let local_var_content = local_var_resp.text().await?;
59
60 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
61 serde_json::from_str(&local_var_content).map_err(Error::from)
62 } else {
63 let local_var_entity: Option<GetMempoolError> = serde_json::from_str(&local_var_content).ok();
64 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
65 Err(Error::ResponseError(local_var_error))
66 }
67}
68
69pub async fn get_mempool_recent(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::InlineResponseDefault4>, Error<GetMempoolRecentError>> {
70
71 let local_var_client = &configuration.client;
72
73 let local_var_uri_str = format!("{}/mempool/recent", configuration.base_path);
74 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
75
76 if let Some(ref local_var_user_agent) = configuration.user_agent {
77 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78 }
79
80 let local_var_req = local_var_req_builder.build()?;
81 let local_var_resp = local_var_client.execute(local_var_req).await?;
82
83 let local_var_status = local_var_resp.status();
84 let local_var_content = local_var_resp.text().await?;
85
86 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
87 serde_json::from_str(&local_var_content).map_err(Error::from)
88 } else {
89 let local_var_entity: Option<GetMempoolRecentError> = serde_json::from_str(&local_var_content).ok();
90 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
91 Err(Error::ResponseError(local_var_error))
92 }
93}
94
95pub async fn get_mempool_txids(configuration: &configuration::Configuration, ) -> Result<Vec<String>, Error<GetMempoolTxidsError>> {
96
97 let local_var_client = &configuration.client;
98
99 let local_var_uri_str = format!("{}/mempool/txids", configuration.base_path);
100 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
101
102 if let Some(ref local_var_user_agent) = configuration.user_agent {
103 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104 }
105
106 let local_var_req = local_var_req_builder.build()?;
107 let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109 let local_var_status = local_var_resp.status();
110 let local_var_content = local_var_resp.text().await?;
111
112 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113 serde_json::from_str(&local_var_content).map_err(Error::from)
114 } else {
115 let local_var_entity: Option<GetMempoolTxidsError> = serde_json::from_str(&local_var_content).ok();
116 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117 Err(Error::ResponseError(local_var_error))
118 }
119}
120