Skip to main content

aptos_client_icp/apis/
transactions_api.rs

1/*
2 * Aptos Node API
3 *
4 * The Aptos Node API is a RESTful API for client applications to interact with the Aptos blockchain.
5 *
6 * The version of the OpenAPI document: 1.2.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use serde::{Deserialize, Serialize};
14
15/// struct for typed errors of method [`encode_submission`]
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum EncodeSubmissionError {
19    Status400(models::AptosError),
20    Status403(models::AptosError),
21    Status500(models::AptosError),
22    Status503(models::AptosError),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`estimate_gas_price`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum EstimateGasPriceError {
30    Status400(models::AptosError),
31    Status403(models::AptosError),
32    Status500(models::AptosError),
33    Status503(models::AptosError),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`get_account_transactions`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum GetAccountTransactionsError {
41    Status400(models::AptosError),
42    Status403(models::AptosError),
43    Status404(models::AptosError),
44    Status410(models::AptosError),
45    Status500(models::AptosError),
46    Status503(models::AptosError),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`get_transaction_by_hash`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetTransactionByHashError {
54    Status400(models::AptosError),
55    Status403(models::AptosError),
56    Status404(models::AptosError),
57    Status410(models::AptosError),
58    Status500(models::AptosError),
59    Status503(models::AptosError),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_transaction_by_version`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetTransactionByVersionError {
67    Status400(models::AptosError),
68    Status403(models::AptosError),
69    Status404(models::AptosError),
70    Status410(models::AptosError),
71    Status500(models::AptosError),
72    Status503(models::AptosError),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`get_transactions`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetTransactionsError {
80    Status400(models::AptosError),
81    Status403(models::AptosError),
82    Status404(models::AptosError),
83    Status410(models::AptosError),
84    Status500(models::AptosError),
85    Status503(models::AptosError),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`simulate_transaction`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum SimulateTransactionError {
93    Status400(models::AptosError),
94    Status403(models::AptosError),
95    Status404(models::AptosError),
96    Status413(models::AptosError),
97    Status500(models::AptosError),
98    Status503(models::AptosError),
99    Status507(models::AptosError),
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`submit_batch_transactions`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum SubmitBatchTransactionsError {
107    Status400(models::AptosError),
108    Status403(models::AptosError),
109    Status404(models::AptosError),
110    Status413(models::AptosError),
111    Status500(models::AptosError),
112    Status503(models::AptosError),
113    Status507(models::AptosError),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`submit_transaction`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum SubmitTransactionError {
121    Status400(models::AptosError),
122    Status403(models::AptosError),
123    Status404(models::AptosError),
124    Status413(models::AptosError),
125    Status500(models::AptosError),
126    Status503(models::AptosError),
127    Status507(models::AptosError),
128    UnknownValue(serde_json::Value),
129}
130
131/// struct for typed errors of method [`wait_transaction_by_hash`]
132#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum WaitTransactionByHashError {
135    Status400(models::AptosError),
136    Status403(models::AptosError),
137    Status404(models::AptosError),
138    Status410(models::AptosError),
139    Status500(models::AptosError),
140    Status503(models::AptosError),
141    UnknownValue(serde_json::Value),
142}
143
144/// This endpoint accepts an EncodeSubmissionRequest, which internally is a UserTransactionRequestInner (and optionally secondary signers) encoded as JSON, validates the request format, and then returns that request encoded in BCS. The client can then use this to create a transaction signature to be used in a SubmitTransactionRequest, which it then passes to the /transactions POST endpoint.  To be clear, this endpoint makes it possible to submit transaction requests to the API from languages that do not have library support for BCS. If you are using an SDK that has BCS support, such as the official Rust, TypeScript, or Python SDKs, you do not need to use this endpoint.  To sign a message using the response from this endpoint: - Decode the hex encoded string in the response to bytes. - Sign the bytes to create the signature. - Use that as the signature field in something like Ed25519Signature, which you then use to build a TransactionSignature.
145pub async fn encode_submission(
146    configuration: &configuration::Configuration,
147    encode_submission_request: models::EncodeSubmissionRequest,
148) -> Result<String, Error<EncodeSubmissionError>> {
149    let local_var_configuration = configuration;
150
151    let local_var_client = &local_var_configuration.client;
152
153    let local_var_uri_str = format!(
154        "{}/transactions/encode_submission",
155        local_var_configuration.base_path
156    );
157    let mut local_var_req_builder =
158        local_var_client.request(crate::http::HttpMethod::POST, local_var_uri_str.as_str());
159
160    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
161        local_var_req_builder =
162            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
163    }
164    local_var_req_builder = local_var_req_builder.json(&encode_submission_request);
165
166    let local_var_req = local_var_req_builder.build()?;
167    let local_var_resp: crate::http::Response = local_var_client.execute(local_var_req).await?;
168
169    let local_var_status = local_var_resp.status();
170    let local_var_content = local_var_resp.text().await?;
171
172    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
173        serde_json::from_str(&local_var_content).map_err(Error::from)
174    } else {
175        let local_var_entity: Option<EncodeSubmissionError> =
176            serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent {
178            status: local_var_status,
179            content: local_var_content,
180            entity: local_var_entity,
181        };
182        Err(Error::ResponseError(local_var_error))
183    }
184}
185
186/// Gives an estimate of the gas unit price required to get a transaction on chain in a reasonable amount of time. The gas unit price is the amount that each transaction commits to pay for each unit of gas consumed in executing the transaction. The estimate is based on recent history: it gives the minimum gas that would have been required to get into recent blocks, for blocks that were full. (When blocks are not full, the estimate will match the minimum gas unit price.)  The estimation is given in three values: de-prioritized (low), regular, and prioritized (aggressive). Using a more aggressive value increases the likelihood that the transaction will make it into the next block; more aggressive values are computed with a larger history and higher percentile statistics. More details are in AIP-34.
187pub async fn estimate_gas_price(
188    configuration: &configuration::Configuration,
189) -> Result<models::GasEstimation, Error<EstimateGasPriceError>> {
190    let local_var_configuration = configuration;
191
192    let local_var_client = &local_var_configuration.client;
193
194    let local_var_uri_str = format!("{}/estimate_gas_price", local_var_configuration.base_path);
195    let mut local_var_req_builder =
196        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
197
198    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
199        local_var_req_builder =
200            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
201    }
202
203    let local_var_req = local_var_req_builder.build()?;
204    let local_var_resp = local_var_client.execute(local_var_req).await?;
205
206    let local_var_status = local_var_resp.status();
207    let local_var_content = local_var_resp.text().await?;
208
209    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
210        serde_json::from_str(&local_var_content).map_err(Error::from)
211    } else {
212        let local_var_entity: Option<EstimateGasPriceError> =
213            serde_json::from_str(&local_var_content).ok();
214        let local_var_error = ResponseContent {
215            status: local_var_status,
216            content: local_var_content,
217            entity: local_var_entity,
218        };
219        Err(Error::ResponseError(local_var_error))
220    }
221}
222
223/// Retrieves on-chain committed transactions from an account. If the start version is too far in the past, a 410 will be returned.  If no start version is given, it will start at version 0.  To retrieve a pending transaction, use /transactions/by_hash.
224pub async fn get_account_transactions(
225    configuration: &configuration::Configuration,
226    address: &str,
227    start: Option<&str>,
228    limit: Option<i32>,
229) -> Result<Vec<models::Transaction>, Error<GetAccountTransactionsError>> {
230    let local_var_configuration = configuration;
231
232    let local_var_client = &local_var_configuration.client;
233
234    let local_var_uri_str = format!(
235        "{}/accounts/{address}/transactions",
236        local_var_configuration.base_path,
237        address = crate::apis::urlencode(address)
238    );
239    let mut local_var_req_builder =
240        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
241
242    if let Some(ref local_var_str) = start {
243        local_var_req_builder =
244            local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
245    }
246    if let Some(ref local_var_str) = limit {
247        local_var_req_builder =
248            local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
249    }
250    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
251        local_var_req_builder =
252            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
253    }
254
255    let local_var_req = local_var_req_builder.build()?;
256    let local_var_resp = local_var_client.execute(local_var_req).await?;
257
258    let local_var_status = local_var_resp.status();
259    let local_var_content = local_var_resp.text().await?;
260
261    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
262        serde_json::from_str(&local_var_content).map_err(Error::from)
263    } else {
264        let local_var_entity: Option<GetAccountTransactionsError> =
265            serde_json::from_str(&local_var_content).ok();
266        let local_var_error = ResponseContent {
267            status: local_var_status,
268            content: local_var_content,
269            entity: local_var_entity,
270        };
271        Err(Error::ResponseError(local_var_error))
272    }
273}
274
275/// Look up a transaction by its hash. This is the same hash that is returned by the API when submitting a transaction (see PendingTransaction).  When given a transaction hash, the server first looks for the transaction in storage (on-chain, committed). If no on-chain transaction is found, it looks the transaction up by hash in the mempool (pending, not yet committed).  To create a transaction hash by yourself, do the following: 1. Hash message bytes: \"RawTransaction\" bytes + BCS bytes of [Transaction](https://aptos-labs.github.io/aptos-core/aptos_types/transaction/enum.Transaction.html). 2. Apply hash algorithm `SHA3-256` to the hash message bytes. 3. Hex-encode the hash bytes with `0x` prefix.
276pub async fn get_transaction_by_hash(
277    configuration: &configuration::Configuration,
278    txn_hash: &str,
279) -> Result<models::Transaction, Error<GetTransactionByHashError>> {
280    let local_var_configuration = configuration;
281
282    let local_var_client = &local_var_configuration.client;
283
284    let local_var_uri_str = format!(
285        "{}/transactions/by_hash/{txn_hash}",
286        local_var_configuration.base_path,
287        txn_hash = crate::apis::urlencode(txn_hash)
288    );
289    let mut local_var_req_builder =
290        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
291
292    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
293        local_var_req_builder =
294            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
295    }
296
297    let local_var_req = local_var_req_builder.build()?;
298    let local_var_resp = local_var_client.execute(local_var_req).await?;
299
300    let local_var_status = local_var_resp.status();
301    let local_var_content = local_var_resp.text().await?;
302
303    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
304        serde_json::from_str(&local_var_content).map_err(Error::from)
305    } else {
306        let local_var_entity: Option<GetTransactionByHashError> =
307            serde_json::from_str(&local_var_content).ok();
308        let local_var_error = ResponseContent {
309            status: local_var_status,
310            content: local_var_content,
311            entity: local_var_entity,
312        };
313        Err(Error::ResponseError(local_var_error))
314    }
315}
316
317/// Retrieves a transaction by a given version. If the version has been pruned, a 410 will be returned.
318pub async fn get_transaction_by_version(
319    configuration: &configuration::Configuration,
320    txn_version: &str,
321) -> Result<models::Transaction, Error<GetTransactionByVersionError>> {
322    let local_var_configuration = configuration;
323
324    let local_var_client = &local_var_configuration.client;
325
326    let local_var_uri_str = format!(
327        "{}/transactions/by_version/{txn_version}",
328        local_var_configuration.base_path,
329        txn_version = crate::apis::urlencode(txn_version)
330    );
331    let mut local_var_req_builder =
332        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
333
334    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
335        local_var_req_builder =
336            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
337    }
338
339    let local_var_req = local_var_req_builder.build()?;
340    let local_var_resp = local_var_client.execute(local_var_req).await?;
341
342    let local_var_status = local_var_resp.status();
343    let local_var_content = local_var_resp.text().await?;
344
345    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346        serde_json::from_str(&local_var_content).map_err(Error::from)
347    } else {
348        let local_var_entity: Option<GetTransactionByVersionError> =
349            serde_json::from_str(&local_var_content).ok();
350        let local_var_error = ResponseContent {
351            status: local_var_status,
352            content: local_var_content,
353            entity: local_var_entity,
354        };
355        Err(Error::ResponseError(local_var_error))
356    }
357}
358
359/// Retrieve on-chain committed transactions. The page size and start ledger version can be provided to get a specific sequence of transactions.  If the version has been pruned, then a 410 will be returned.  To retrieve a pending transaction, use /transactions/by_hash.
360pub async fn get_transactions(
361    configuration: &configuration::Configuration,
362    start: Option<&str>,
363    limit: Option<i32>,
364) -> Result<Vec<models::Transaction>, Error<GetTransactionsError>> {
365    let local_var_configuration = configuration;
366
367    let local_var_client = &local_var_configuration.client;
368
369    let local_var_uri_str = format!("{}/transactions", local_var_configuration.base_path);
370    let mut local_var_req_builder =
371        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
372
373    if let Some(ref local_var_str) = start {
374        local_var_req_builder =
375            local_var_req_builder.query(&[("start", &local_var_str.to_string())]);
376    }
377    if let Some(ref local_var_str) = limit {
378        local_var_req_builder =
379            local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
380    }
381    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
382        local_var_req_builder =
383            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
384    }
385
386    let local_var_req = local_var_req_builder.build()?;
387    let local_var_resp = local_var_client.execute(local_var_req).await?;
388
389    let local_var_status = local_var_resp.status();
390    let local_var_content = local_var_resp.text().await?;
391
392    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
393        serde_json::from_str(&local_var_content).map_err(Error::from)
394    } else {
395        let local_var_entity: Option<GetTransactionsError> =
396            serde_json::from_str(&local_var_content).ok();
397        let local_var_error = ResponseContent {
398            status: local_var_status,
399            content: local_var_content,
400            entity: local_var_entity,
401        };
402        Err(Error::ResponseError(local_var_error))
403    }
404}
405
406/// The output of the transaction will have the exact transaction outputs and events that running an actual signed transaction would have.  However, it will not have the associated state hashes, as they are not updated in storage.  This can be used to estimate the maximum gas units for a submitted transaction.  To use this, you must: - Create a SignedTransaction with a zero-padded signature. - Submit a SubmitTransactionRequest containing a UserTransactionRequest containing that signature.  To use this endpoint with BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs.
407pub async fn simulate_transaction(
408    configuration: &configuration::Configuration,
409    submit_transaction_request: models::SubmitTransactionRequest,
410    estimate_max_gas_amount: Option<bool>,
411    estimate_gas_unit_price: Option<bool>,
412    estimate_prioritized_gas_unit_price: Option<bool>,
413) -> Result<Vec<models::UserTransaction>, Error<SimulateTransactionError>> {
414    let local_var_configuration = configuration;
415
416    let local_var_client = &local_var_configuration.client;
417
418    let local_var_uri_str = format!(
419        "{}/transactions/simulate",
420        local_var_configuration.base_path
421    );
422    let mut local_var_req_builder =
423        local_var_client.request(crate::http::HttpMethod::POST, local_var_uri_str.as_str());
424
425    if let Some(ref local_var_str) = estimate_max_gas_amount {
426        local_var_req_builder =
427            local_var_req_builder.query(&[("estimate_max_gas_amount", &local_var_str.to_string())]);
428    }
429    if let Some(ref local_var_str) = estimate_gas_unit_price {
430        local_var_req_builder =
431            local_var_req_builder.query(&[("estimate_gas_unit_price", &local_var_str.to_string())]);
432    }
433    if let Some(ref local_var_str) = estimate_prioritized_gas_unit_price {
434        local_var_req_builder = local_var_req_builder.query(&[(
435            "estimate_prioritized_gas_unit_price",
436            &local_var_str.to_string(),
437        )]);
438    }
439    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
440        local_var_req_builder =
441            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
442    }
443    local_var_req_builder = local_var_req_builder.json(&submit_transaction_request);
444
445    let local_var_req = local_var_req_builder.build()?;
446    let local_var_resp = local_var_client.execute(local_var_req).await?;
447
448    let local_var_status = local_var_resp.status();
449    let local_var_content = local_var_resp.text().await?;
450
451    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
452        serde_json::from_str(&local_var_content).map_err(Error::from)
453    } else {
454        let local_var_entity: Option<SimulateTransactionError> =
455            serde_json::from_str(&local_var_content).ok();
456        let local_var_error = ResponseContent {
457            status: local_var_status,
458            content: local_var_content,
459            entity: local_var_entity,
460        };
461        Err(Error::ResponseError(local_var_error))
462    }
463}
464
465/// This allows you to submit multiple transactions.  The response has three outcomes:  1. All transactions succeed, and it will return a 202 2. Some transactions succeed, and it will return the failed transactions and a 206 3. No transactions succeed, and it will also return the failed transactions and a 206  To submit a transaction as JSON, you must submit a SubmitTransactionRequest. To build this request, do the following:  1. Encode the transaction as BCS. If you are using a language that has native BCS support, make sure to use that library. If not, you may take advantage of /transactions/encode_submission. When using this endpoint, make sure you trust the node you're talking to, as it is possible they could manipulate your request. 2. Sign the encoded transaction and use it to create a TransactionSignature. 3. Submit the request. Make sure to use the \"application/json\" Content-Type.  To submit a transaction as BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs. Make sure to use the `application/x.aptos.signed_transaction+bcs` Content-Type.
466pub async fn submit_batch_transactions(
467    configuration: &configuration::Configuration,
468    submit_transaction_request: Vec<models::SubmitTransactionRequest>,
469) -> Result<models::TransactionsBatchSubmissionResult, Error<SubmitBatchTransactionsError>> {
470    let local_var_configuration = configuration;
471
472    let local_var_client = &local_var_configuration.client;
473
474    let local_var_uri_str = format!("{}/transactions/batch", local_var_configuration.base_path);
475    let mut local_var_req_builder =
476        local_var_client.request(crate::http::HttpMethod::POST, local_var_uri_str.as_str());
477
478    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
479        local_var_req_builder =
480            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
481    }
482    local_var_req_builder = local_var_req_builder.json(&submit_transaction_request);
483
484    let local_var_req = local_var_req_builder.build()?;
485    let local_var_resp = local_var_client.execute(local_var_req).await?;
486
487    let local_var_status = local_var_resp.status();
488    let local_var_content = local_var_resp.text().await?;
489
490    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
491        serde_json::from_str(&local_var_content).map_err(Error::from)
492    } else {
493        let local_var_entity: Option<SubmitBatchTransactionsError> =
494            serde_json::from_str(&local_var_content).ok();
495        let local_var_error = ResponseContent {
496            status: local_var_status,
497            content: local_var_content,
498            entity: local_var_entity,
499        };
500        Err(Error::ResponseError(local_var_error))
501    }
502}
503
504/// This endpoint accepts transaction submissions in two formats.  To submit a transaction as JSON, you must submit a SubmitTransactionRequest. To build this request, do the following:  1. Encode the transaction as BCS. If you are using a language that has native BCS support, make sure of that library. If not, you may take advantage of /transactions/encode_submission. When using this endpoint, make sure you trust the node you're talking to, as it is possible they could manipulate your request. 2. Sign the encoded transaction and use it to create a TransactionSignature. 3. Submit the request. Make sure to use the \"application/json\" Content-Type.  To submit a transaction as BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs. Make sure to use the `application/x.aptos.signed_transaction+bcs` Content-Type.
505pub async fn submit_transaction(
506    configuration: &configuration::Configuration,
507    submit_transaction_request: models::SubmitTransactionRequest,
508) -> Result<models::PendingTransaction, Error<SubmitTransactionError>> {
509    let local_var_configuration = configuration;
510
511    let local_var_client = &local_var_configuration.client;
512
513    let local_var_uri_str = format!("{}/transactions", local_var_configuration.base_path);
514    let mut local_var_req_builder =
515        local_var_client.request(crate::http::HttpMethod::POST, local_var_uri_str.as_str());
516
517    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
518        local_var_req_builder =
519            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
520    }
521    local_var_req_builder = local_var_req_builder.json(&submit_transaction_request);
522
523    let local_var_req = local_var_req_builder.build()?;
524    let local_var_resp = local_var_client.execute(local_var_req).await?;
525
526    let local_var_status = local_var_resp.status();
527    let local_var_content = local_var_resp.text().await?;
528
529    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
530        serde_json::from_str(&local_var_content).map_err(Error::from)
531    } else {
532        let local_var_entity: Option<SubmitTransactionError> =
533            serde_json::from_str(&local_var_content).ok();
534        let local_var_error = ResponseContent {
535            status: local_var_status,
536            content: local_var_content,
537            entity: local_var_entity,
538        };
539        Err(Error::ResponseError(local_var_error))
540    }
541}
542
543/// Same as /transactions/by_hash, but will wait for a pending transaction to be committed. To be used as a long poll optimization by clients, to reduce latency caused by polling. The \"long\" poll is generally a second or less but dictated by the server; the client must deal with the result as if the request was a normal /transactions/by_hash request, e.g., by retrying if the transaction is pending.
544pub async fn wait_transaction_by_hash(
545    configuration: &configuration::Configuration,
546    txn_hash: &str,
547) -> Result<models::Transaction, Error<WaitTransactionByHashError>> {
548    let local_var_configuration = configuration;
549
550    let local_var_client = &local_var_configuration.client;
551
552    let local_var_uri_str = format!(
553        "{}/transactions/wait_by_hash/{txn_hash}",
554        local_var_configuration.base_path,
555        txn_hash = crate::apis::urlencode(txn_hash)
556    );
557    let mut local_var_req_builder =
558        local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
559
560    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
561        local_var_req_builder =
562            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
563    }
564
565    let local_var_req = local_var_req_builder.build()?;
566    let local_var_resp = local_var_client.execute(local_var_req).await?;
567
568    let local_var_status = local_var_resp.status();
569    let local_var_content = local_var_resp.text().await?;
570
571    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
572        serde_json::from_str(&local_var_content).map_err(Error::from)
573    } else {
574        let local_var_entity: Option<WaitTransactionByHashError> =
575            serde_json::from_str(&local_var_content).ok();
576        let local_var_error = ResponseContent {
577            status: local_var_status,
578            content: local_var_content,
579            entity: local_var_entity,
580        };
581        Err(Error::ResponseError(local_var_error))
582    }
583}