coinbase_mesh/apis/
mempool_api.rs

1/*
2 * Rosetta
3 *
4 * Build Once. Integrate Your Blockchain Everywhere. 
5 *
6 * The version of the OpenAPI document: 1.4.13
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`mempool`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum MempoolError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`mempool_transaction`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum MempoolTransactionError {
30    Status500(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Get all Transaction Identifiers in the mempool
36pub async fn mempool(configuration: &configuration::Configuration, network_request: models::NetworkRequest) -> Result<models::MempoolResponse, Error<MempoolError>> {
37    let local_var_configuration = configuration;
38
39    let local_var_client = &local_var_configuration.client;
40
41    let local_var_uri_str = format!("{}/mempool", local_var_configuration.base_path);
42    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
43
44    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
45        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
46    }
47    local_var_req_builder = local_var_req_builder.json(&network_request);
48
49    let local_var_req = local_var_req_builder.build()?;
50    let local_var_resp = local_var_client.execute(local_var_req).await?;
51
52    let local_var_status = local_var_resp.status();
53    let local_var_content = local_var_resp.text().await?;
54
55    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
56        serde_json::from_str(&local_var_content).map_err(Error::from)
57    } else {
58        let local_var_entity: Option<MempoolError> = serde_json::from_str(&local_var_content).ok();
59        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
60        Err(Error::ResponseError(local_var_error))
61    }
62}
63
64/// Get a transaction in the mempool by its Transaction Identifier. This is a separate request than fetching a block transaction (/block/transaction) because some blockchain nodes need to know that a transaction query is for something in the mempool instead of a transaction in a block.  Transactions may not be fully parsable until they are in a block (ex: may not be possible to determine the fee to pay before a transaction is executed). On this endpoint, it is ok that returned transactions are only estimates of what may actually be included in a block. 
65pub async fn mempool_transaction(configuration: &configuration::Configuration, mempool_transaction_request: models::MempoolTransactionRequest) -> Result<models::MempoolTransactionResponse, Error<MempoolTransactionError>> {
66    let local_var_configuration = configuration;
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!("{}/mempool/transaction", local_var_configuration.base_path);
71    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
72
73    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
74        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
75    }
76    local_var_req_builder = local_var_req_builder.json(&mempool_transaction_request);
77
78    let local_var_req = local_var_req_builder.build()?;
79    let local_var_resp = local_var_client.execute(local_var_req).await?;
80
81    let local_var_status = local_var_resp.status();
82    let local_var_content = local_var_resp.text().await?;
83
84    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
85        serde_json::from_str(&local_var_content).map_err(Error::from)
86    } else {
87        let local_var_entity: Option<MempoolTransactionError> = serde_json::from_str(&local_var_content).ok();
88        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
89        Err(Error::ResponseError(local_var_error))
90    }
91}
92