esplora_btc_api/apis/
tx_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_all_tx_outspends`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAllTxOutspendsError {
22    DefaultResponse(Vec<crate::models::Spend>),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `get_tx`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetTxError {
30    DefaultResponse(crate::models::Transaction),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `get_tx_hex`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetTxHexError {
38    DefaultResponse(String),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `get_tx_merkle_block_proof`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetTxMerkleBlockProofError {
46    DefaultResponse(String),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `get_tx_merkle_proof`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetTxMerkleProofError {
54    DefaultResponse(crate::models::InlineResponseDefault),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method `get_tx_outspend`
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetTxOutspendError {
62    DefaultResponse(crate::models::Spend),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method `get_tx_raw`
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetTxRawError {
70    DefaultResponse(std::path::PathBuf),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method `get_tx_status`
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetTxStatusError {
78    DefaultResponse(crate::models::Status),
79    UnknownValue(serde_json::Value),
80}
81
82/// struct for typed errors of method `post_tx`
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum PostTxError {
86    DefaultResponse(String),
87    UnknownValue(serde_json::Value),
88}
89
90
91pub async fn get_all_tx_outspends(configuration: &configuration::Configuration, tx_id: &str) -> Result<Vec<crate::models::Spend>, Error<GetAllTxOutspendsError>> {
92
93    let local_var_client = &configuration.client;
94
95    let local_var_uri_str = format!("{}/tx/{txId}/outspends", configuration.base_path, txId=crate::apis::urlencode(tx_id));
96    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
97
98    if let Some(ref local_var_user_agent) = configuration.user_agent {
99        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101
102    let local_var_req = local_var_req_builder.build()?;
103    let local_var_resp = local_var_client.execute(local_var_req).await?;
104
105    let local_var_status = local_var_resp.status();
106    let local_var_content = local_var_resp.text().await?;
107
108    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
109        serde_json::from_str(&local_var_content).map_err(Error::from)
110    } else {
111        let local_var_entity: Option<GetAllTxOutspendsError> = serde_json::from_str(&local_var_content).ok();
112        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
113        Err(Error::ResponseError(local_var_error))
114    }
115}
116
117pub async fn get_tx(configuration: &configuration::Configuration, tx_id: &str) -> Result<crate::models::Transaction, Error<GetTxError>> {
118
119    let local_var_client = &configuration.client;
120
121    let local_var_uri_str = format!("{}/tx/{txId}", configuration.base_path, txId=crate::apis::urlencode(tx_id));
122    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
123
124    if let Some(ref local_var_user_agent) = configuration.user_agent {
125        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
126    }
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        serde_json::from_str(&local_var_content).map_err(Error::from)
136    } else {
137        let local_var_entity: Option<GetTxError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143pub async fn get_tx_hex(configuration: &configuration::Configuration, tx_id: &str) -> Result<String, Error<GetTxHexError>> {
144
145    let local_var_client = &configuration.client;
146
147    let local_var_uri_str = format!("{}/tx/{txId}/hex", configuration.base_path, txId=crate::apis::urlencode(tx_id));
148    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
149
150    if let Some(ref local_var_user_agent) = configuration.user_agent {
151        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
152    }
153
154    let local_var_req = local_var_req_builder.build()?;
155    let local_var_resp = local_var_client.execute(local_var_req).await?;
156
157    let local_var_status = local_var_resp.status();
158    let local_var_content = local_var_resp.text().await?;
159
160    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
161        serde_json::from_str(&local_var_content).map_err(Error::from)
162    } else {
163        let local_var_entity: Option<GetTxHexError> = serde_json::from_str(&local_var_content).ok();
164        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
165        Err(Error::ResponseError(local_var_error))
166    }
167}
168
169pub async fn get_tx_merkle_block_proof(configuration: &configuration::Configuration, tx_id: &str) -> Result<String, Error<GetTxMerkleBlockProofError>> {
170
171    let local_var_client = &configuration.client;
172
173    let local_var_uri_str = format!("{}/tx/{txId}/merkleblock-proof", configuration.base_path, txId=crate::apis::urlencode(tx_id));
174    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
175
176    if let Some(ref local_var_user_agent) = configuration.user_agent {
177        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
178    }
179
180    let local_var_req = local_var_req_builder.build()?;
181    let local_var_resp = local_var_client.execute(local_var_req).await?;
182
183    let local_var_status = local_var_resp.status();
184    let local_var_content = local_var_resp.text().await?;
185
186    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
187        serde_json::from_str(&local_var_content).map_err(Error::from)
188    } else {
189        let local_var_entity: Option<GetTxMerkleBlockProofError> = serde_json::from_str(&local_var_content).ok();
190        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
191        Err(Error::ResponseError(local_var_error))
192    }
193}
194
195pub async fn get_tx_merkle_proof(configuration: &configuration::Configuration, tx_id: &str) -> Result<crate::models::InlineResponseDefault, Error<GetTxMerkleProofError>> {
196
197    let local_var_client = &configuration.client;
198
199    let local_var_uri_str = format!("{}/tx/{txId}/merkle-proof", configuration.base_path, txId=crate::apis::urlencode(tx_id));
200    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
201
202    if let Some(ref local_var_user_agent) = configuration.user_agent {
203        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
204    }
205
206    let local_var_req = local_var_req_builder.build()?;
207    let local_var_resp = local_var_client.execute(local_var_req).await?;
208
209    let local_var_status = local_var_resp.status();
210    let local_var_content = local_var_resp.text().await?;
211
212    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
213        serde_json::from_str(&local_var_content).map_err(Error::from)
214    } else {
215        let local_var_entity: Option<GetTxMerkleProofError> = serde_json::from_str(&local_var_content).ok();
216        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
217        Err(Error::ResponseError(local_var_error))
218    }
219}
220
221pub async fn get_tx_outspend(configuration: &configuration::Configuration, tx_id: &str, vout: f32) -> Result<crate::models::Spend, Error<GetTxOutspendError>> {
222
223    let local_var_client = &configuration.client;
224
225    let local_var_uri_str = format!("{}/tx/{txId}/outspend/{vout}", configuration.base_path, txId=crate::apis::urlencode(tx_id), vout=vout);
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    let local_var_status = local_var_resp.status();
236    let local_var_content = local_var_resp.text().await?;
237
238    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239        serde_json::from_str(&local_var_content).map_err(Error::from)
240    } else {
241        let local_var_entity: Option<GetTxOutspendError> = serde_json::from_str(&local_var_content).ok();
242        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
243        Err(Error::ResponseError(local_var_error))
244    }
245}
246
247pub async fn get_tx_raw(configuration: &configuration::Configuration, tx_id: &str) -> Result<std::path::PathBuf, Error<GetTxRawError>> {
248
249    let local_var_client = &configuration.client;
250
251    let local_var_uri_str = format!("{}/tx/{txId}/raw", configuration.base_path, txId=crate::apis::urlencode(tx_id));
252    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
253
254    if let Some(ref local_var_user_agent) = configuration.user_agent {
255        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
256    }
257
258    let local_var_req = local_var_req_builder.build()?;
259    let local_var_resp = local_var_client.execute(local_var_req).await?;
260
261    let local_var_status = local_var_resp.status();
262    let local_var_content = local_var_resp.text().await?;
263
264    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
265        serde_json::from_str(&local_var_content).map_err(Error::from)
266    } else {
267        let local_var_entity: Option<GetTxRawError> = serde_json::from_str(&local_var_content).ok();
268        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
269        Err(Error::ResponseError(local_var_error))
270    }
271}
272
273pub async fn get_tx_status(configuration: &configuration::Configuration, tx_id: &str) -> Result<crate::models::Status, Error<GetTxStatusError>> {
274
275    let local_var_client = &configuration.client;
276
277    let local_var_uri_str = format!("{}/tx/{txId}/status", configuration.base_path, txId=crate::apis::urlencode(tx_id));
278    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
279
280    if let Some(ref local_var_user_agent) = configuration.user_agent {
281        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
282    }
283
284    let local_var_req = local_var_req_builder.build()?;
285    let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287    let local_var_status = local_var_resp.status();
288    let local_var_content = local_var_resp.text().await?;
289
290    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291        serde_json::from_str(&local_var_content).map_err(Error::from)
292    } else {
293        let local_var_entity: Option<GetTxStatusError> = serde_json::from_str(&local_var_content).ok();
294        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
295        Err(Error::ResponseError(local_var_error))
296    }
297}
298
299pub async fn post_tx(configuration: &configuration::Configuration, body: &str) -> Result<String, Error<PostTxError>> {
300
301    let local_var_client = &configuration.client;
302
303    let local_var_uri_str = format!("{}/tx", configuration.base_path);
304    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
305
306    if let Some(ref local_var_user_agent) = configuration.user_agent {
307        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
308    }
309    local_var_req_builder = local_var_req_builder.json(&body);
310
311    let local_var_req = local_var_req_builder.build()?;
312    let local_var_resp = local_var_client.execute(local_var_req).await?;
313
314    let local_var_status = local_var_resp.status();
315    let local_var_content = local_var_resp.text().await?;
316
317    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
318        serde_json::from_str(&local_var_content).map_err(Error::from)
319    } else {
320        let local_var_entity: Option<PostTxError> = serde_json::from_str(&local_var_content).ok();
321        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
322        Err(Error::ResponseError(local_var_error))
323    }
324}
325