esplora_btc_api/apis/
address_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_address`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAddressError {
22    DefaultResponse(crate::models::InlineResponseDefault1),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `get_address_tx_history`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetAddressTxHistoryError {
30    DefaultResponse(Vec<crate::models::Transaction>),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `get_address_tx_mempool`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAddressTxMempoolError {
38    DefaultResponse(Vec<crate::models::Transaction>),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `get_address_utxo`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetAddressUtxoError {
46    DefaultResponse(Vec<crate::models::Utxo>),
47    UnknownValue(serde_json::Value),
48}
49
50
51pub async fn get_address(configuration: &configuration::Configuration, address: &str) -> Result<crate::models::InlineResponseDefault1, Error<GetAddressError>> {
52
53    let local_var_client = &configuration.client;
54
55    let local_var_uri_str = format!("{}/address/{address}", configuration.base_path, address=crate::apis::urlencode(address));
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58    if let Some(ref local_var_user_agent) = configuration.user_agent {
59        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60    }
61
62    let local_var_req = local_var_req_builder.build()?;
63    let local_var_resp = local_var_client.execute(local_var_req).await?;
64
65    let local_var_status = local_var_resp.status();
66    let local_var_content = local_var_resp.text().await?;
67
68    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
69        serde_json::from_str(&local_var_content).map_err(Error::from)
70    } else {
71        let local_var_entity: Option<GetAddressError> = serde_json::from_str(&local_var_content).ok();
72        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
73        Err(Error::ResponseError(local_var_error))
74    }
75}
76
77pub async fn get_address_tx_history(configuration: &configuration::Configuration, address: &str) -> Result<Vec<crate::models::Transaction>, Error<GetAddressTxHistoryError>> {
78
79    let local_var_client = &configuration.client;
80
81    let local_var_uri_str = format!("{}/address/{address}/txs", configuration.base_path, address=crate::apis::urlencode(address));
82    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
83
84    if let Some(ref local_var_user_agent) = configuration.user_agent {
85        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    let local_var_status = local_var_resp.status();
92    let local_var_content = local_var_resp.text().await?;
93
94    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95        serde_json::from_str(&local_var_content).map_err(Error::from)
96    } else {
97        let local_var_entity: Option<GetAddressTxHistoryError> = serde_json::from_str(&local_var_content).ok();
98        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102
103pub async fn get_address_tx_mempool(configuration: &configuration::Configuration, address: &str) -> Result<Vec<crate::models::Transaction>, Error<GetAddressTxMempoolError>> {
104
105    let local_var_client = &configuration.client;
106
107    let local_var_uri_str = format!("{}/address/{address}/txs/mempool", configuration.base_path, address=crate::apis::urlencode(address));
108    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
109
110    if let Some(ref local_var_user_agent) = configuration.user_agent {
111        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112    }
113
114    let local_var_req = local_var_req_builder.build()?;
115    let local_var_resp = local_var_client.execute(local_var_req).await?;
116
117    let local_var_status = local_var_resp.status();
118    let local_var_content = local_var_resp.text().await?;
119
120    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121        serde_json::from_str(&local_var_content).map_err(Error::from)
122    } else {
123        let local_var_entity: Option<GetAddressTxMempoolError> = serde_json::from_str(&local_var_content).ok();
124        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
125        Err(Error::ResponseError(local_var_error))
126    }
127}
128
129pub async fn get_address_utxo(configuration: &configuration::Configuration, address: &str) -> Result<Vec<crate::models::Utxo>, Error<GetAddressUtxoError>> {
130
131    let local_var_client = &configuration.client;
132
133    let local_var_uri_str = format!("{}/address/{address}/utxo", configuration.base_path, address=crate::apis::urlencode(address));
134    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
135
136    if let Some(ref local_var_user_agent) = configuration.user_agent {
137        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138    }
139
140    let local_var_req = local_var_req_builder.build()?;
141    let local_var_resp = local_var_client.execute(local_var_req).await?;
142
143    let local_var_status = local_var_resp.status();
144    let local_var_content = local_var_resp.text().await?;
145
146    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
147        serde_json::from_str(&local_var_content).map_err(Error::from)
148    } else {
149        let local_var_entity: Option<GetAddressUtxoError> = serde_json::from_str(&local_var_content).ok();
150        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
151        Err(Error::ResponseError(local_var_error))
152    }
153}
154