coinbase_mesh/apis/
call_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 [`call`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CallError {
22    Status500(models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26
27/// Call invokes an arbitrary, network-specific procedure call with network-specific parameters. The guidance for what this endpoint should or could do is purposely left vague. In Ethereum, this could be used to invoke `eth_call` to implement an entire Rosetta API interface for some smart contract that is not parsed by the implementation creator (like a DEX). This endpoint could also be used to provide access to data that does not map to any Rosetta models instead of requiring an integrator to use some network-specific SDK and call some network-specific endpoint (like surfacing staking parameters).  Call is NOT a replacement for implementing Rosetta API endpoints or mapping network-specific data to Rosetta models. Rather, it enables developers to build additional Rosetta API interfaces for things they care about without introducing complexity into a base-level Rosetta implementation. Simply put, imagine that the average integrator will use layered Rosetta API implementations that each surfaces unique data. 
28pub async fn call(configuration: &configuration::Configuration, call_request: models::CallRequest) -> Result<models::CallResponse, Error<CallError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!("{}/call", local_var_configuration.base_path);
34    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
37        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    local_var_req_builder = local_var_req_builder.json(&call_request);
40
41    let local_var_req = local_var_req_builder.build()?;
42    let local_var_resp = local_var_client.execute(local_var_req).await?;
43
44    let local_var_status = local_var_resp.status();
45    let local_var_content = local_var_resp.text().await?;
46
47    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
48        serde_json::from_str(&local_var_content).map_err(Error::from)
49    } else {
50        let local_var_entity: Option<CallError> = serde_json::from_str(&local_var_content).ok();
51        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
52        Err(Error::ResponseError(local_var_error))
53    }
54}
55