use super::{configuration, Error};
use crate::{apis::ResponseContent, models};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBlockByHeightError {
Status400(models::AptosError),
Status403(models::AptosError),
Status404(models::AptosError),
Status410(models::AptosError),
Status500(models::AptosError),
Status503(models::AptosError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBlockByVersionError {
Status400(models::AptosError),
Status403(models::AptosError),
Status404(models::AptosError),
Status410(models::AptosError),
Status500(models::AptosError),
Status503(models::AptosError),
UnknownValue(serde_json::Value),
}
pub async fn get_block_by_height(
configuration: &configuration::Configuration,
block_height: i32,
with_transactions: Option<bool>,
) -> Result<models::Block, Error<GetBlockByHeightError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/blocks/by_height/{block_height}",
local_var_configuration.base_path,
block_height = block_height
);
let mut local_var_req_builder =
local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = with_transactions {
local_var_req_builder =
local_var_req_builder.query(&[("with_transactions", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetBlockByHeightError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_block_by_version(
configuration: &configuration::Configuration,
version: i32,
with_transactions: Option<bool>,
) -> Result<models::Block, Error<GetBlockByVersionError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/blocks/by_version/{version}",
local_var_configuration.base_path,
version = version
);
let mut local_var_req_builder =
local_var_client.request(crate::http::HttpMethod::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = with_transactions {
local_var_req_builder =
local_var_req_builder.query(&[("with_transactions", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header("User-Agent".to_string(), local_var_user_agent.clone());
}
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetBlockByVersionError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}