Skip to main content

aptos_client_icp/apis/
view_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 [`view`]
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(untagged)]
18pub enum ViewError {
19    Status400(models::AptosError),
20    Status403(models::AptosError),
21    Status404(models::AptosError),
22    Status410(models::AptosError),
23    Status500(models::AptosError),
24    Status503(models::AptosError),
25    UnknownValue(serde_json::Value),
26}
27
28/// Execute the Move function with the given parameters and return its execution result.  The Aptos nodes prune account state history, via a configurable time window. If the requested ledger version has been pruned, the server responds with a 410.
29pub async fn view(
30    configuration: &configuration::Configuration,
31    view_request: models::ViewRequest,
32    ledger_version: Option<&str>,
33) -> Result<Vec<models::MoveValue>, Error<ViewError>> {
34    let local_var_configuration = configuration;
35
36    let local_var_client = &local_var_configuration.client;
37
38    let local_var_uri_str = format!("{}/view", local_var_configuration.base_path);
39    let mut local_var_req_builder =
40        local_var_client.request(crate::http::HttpMethod::POST, local_var_uri_str.as_str());
41
42    if let Some(ref local_var_str) = ledger_version {
43        local_var_req_builder =
44            local_var_req_builder.query(&[("ledger_version", &local_var_str.to_string())]);
45    }
46    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
47        local_var_req_builder =
48            local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
49    }
50    local_var_req_builder = local_var_req_builder.json(&view_request);
51
52    let local_var_req = local_var_req_builder.build()?;
53    let local_var_resp = local_var_client.execute(local_var_req).await?;
54
55    let local_var_status = local_var_resp.status();
56    let local_var_content = local_var_resp.text().await?;
57
58    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
59        serde_json::from_str(&local_var_content).map_err(Error::from)
60    } else {
61        let local_var_entity: Option<ViewError> = serde_json::from_str(&local_var_content).ok();
62        let local_var_error = ResponseContent {
63            status: local_var_status,
64            content: local_var_content,
65            entity: local_var_entity,
66        };
67        Err(Error::ResponseError(local_var_error))
68    }
69}