coinbase_mesh/apis/
block_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 [`block`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum BlockError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`block_transaction`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum BlockTransactionError {
30    Status500(models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Get a block by its Block Identifier. If transactions are returned in the same call to the node as fetching the block, the response should include these transactions in the Block object. If not, an array of Transaction Identifiers should be returned so /block/transaction fetches can be done to get all transaction information.  When requesting a block by the hash component of the BlockIdentifier, this request MUST be idempotent: repeated invocations for the same hash-identified block must return the exact same block contents.  No such restriction is imposed when requesting a block by height, given that a chain reorg event might cause the specific block at height `n` to be set to a different one. 
36pub async fn block(configuration: &configuration::Configuration, block_request: models::BlockRequest) -> Result<models::BlockResponse, Error<BlockError>> {
37    let local_var_configuration = configuration;
38
39    let local_var_client = &local_var_configuration.client;
40
41    let local_var_uri_str = format!("{}/block", 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(&block_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<BlockError> = 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 a block by its Transaction Identifier. This endpoint should only be used when querying a node for a block does not return all transactions contained within it.  All transactions returned by this endpoint must be appended to any transactions returned by the /block method by consumers of this data. Fetching a transaction by hash is considered an Explorer Method (which is classified under the Future Work section).  This method can be used to let consumers to paginate results when the  block trasactions count is too big to be returned in a single BlockResponse.  Calling this endpoint requires reference to a BlockIdentifier because transaction parsing can change depending on which block contains the transaction. For example, in Bitcoin it is necessary to know which block contains a transaction to determine the destination of fee payments. Without specifying a block identifier, the node would have to infer which block to use (which could change during a re-org).  Implementations that require fetching previous transactions to populate the response (ex: Previous UTXOs in Bitcoin) may find it useful to run a cache within the Rosetta server in the /data directory (on a path that does not conflict with the node). 
65pub async fn block_transaction(configuration: &configuration::Configuration, block_transaction_request: models::BlockTransactionRequest) -> Result<models::BlockTransactionResponse, Error<BlockTransactionError>> {
66    let local_var_configuration = configuration;
67
68    let local_var_client = &local_var_configuration.client;
69
70    let local_var_uri_str = format!("{}/block/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(&block_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<BlockTransactionError> = 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