use reqwest;
use super::{Error, configuration};
use crate::apis::ResponseContent;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddParticipationKeyError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
Status503(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AppendKeysError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteParticipationKeyByIdError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GenerateParticipationKeysError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
Status503(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetParticipationKeyByIdError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetParticipationKeysError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPendingTransactionsError {
Status401(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
Status503(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPendingTransactionsByAddressError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
Status503(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PendingTransactionInformationError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status404(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RawTransactionError {
Status400(algonaut_model::algod::ErrorResponse),
Status401(algonaut_model::algod::ErrorResponse),
Status500(algonaut_model::algod::ErrorResponse),
Status503(algonaut_model::algod::ErrorResponse),
DefaultResponse(),
UnknownValue(serde_json::Value),
}
pub async fn add_participation_key(
configuration: &configuration::Configuration,
participationkey: &[u8],
) -> Result<algonaut_model::algod::ParticipationKeyId, Error<AddParticipationKeyError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v2/participation", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
local_var_req_builder = local_var_req_builder.body(participationkey.to_vec());
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<AddParticipationKeyError> =
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 append_keys(
configuration: &configuration::Configuration,
participation_id: &str,
keymap: &[u8],
) -> Result<algonaut_model::algod::ParticipationKey, Error<AppendKeysError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/participation/{participation_id}",
local_var_configuration.base_path,
participation_id = crate::apis::urlencode(participation_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
local_var_req_builder = local_var_req_builder.body(keymap.to_vec());
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<AppendKeysError> =
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 delete_participation_key_by_id(
configuration: &configuration::Configuration,
participation_id: &str,
) -> Result<(), Error<DeleteParticipationKeyByIdError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/participation/{participation_id}",
local_var_configuration.base_path,
participation_id = crate::apis::urlencode(participation_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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() {
Ok(())
} else {
let local_var_entity: Option<DeleteParticipationKeyByIdError> =
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 generate_participation_keys(
configuration: &configuration::Configuration,
address: &str,
first: u64,
last: u64,
dilution: Option<u64>,
) -> Result<String, Error<GenerateParticipationKeysError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/participation/generate/{address}",
local_var_configuration.base_path,
address = crate::apis::urlencode(address)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_str) = dilution {
local_var_req_builder =
local_var_req_builder.query(&[("dilution", &local_var_str.to_string())]);
}
local_var_req_builder = local_var_req_builder.query(&[("first", &first.to_string())]);
local_var_req_builder = local_var_req_builder.query(&[("last", &last.to_string())]);
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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<GenerateParticipationKeysError> =
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_participation_key_by_id(
configuration: &configuration::Configuration,
participation_id: &str,
) -> Result<algonaut_model::algod::ParticipationKey, Error<GetParticipationKeyByIdError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/participation/{participation_id}",
local_var_configuration.base_path,
participation_id = crate::apis::urlencode(participation_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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<GetParticipationKeyByIdError> =
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_participation_keys(
configuration: &configuration::Configuration,
) -> Result<Vec<algonaut_model::algod::ParticipationKey>, Error<GetParticipationKeysError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v2/participation", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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<GetParticipationKeysError> =
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_pending_transactions(
configuration: &configuration::Configuration,
max: Option<u64>,
format: Option<&str>,
) -> Result<algonaut_model::algod::PendingTransactions, Error<GetPendingTransactionsError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/transactions/pending",
local_var_configuration.base_path
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = max {
local_var_req_builder = local_var_req_builder.query(&[("max", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = format {
local_var_req_builder =
local_var_req_builder.query(&[("format", &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(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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_type = local_var_resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok())
.map(str::to_string);
let local_var_body = local_var_resp.bytes().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
crate::apis::decode_response_body(local_var_content_type.as_deref(), &local_var_body)
} else {
let local_var_content = String::from_utf8_lossy(&local_var_body).into_owned();
let local_var_entity: Option<GetPendingTransactionsError> =
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_pending_transactions_by_address(
configuration: &configuration::Configuration,
address: &str,
max: Option<u64>,
format: Option<&str>,
) -> Result<algonaut_model::algod::PendingTransactions, Error<GetPendingTransactionsByAddressError>>
{
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/accounts/{address}/transactions/pending",
local_var_configuration.base_path,
address = crate::apis::urlencode(address)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = max {
local_var_req_builder = local_var_req_builder.query(&[("max", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = format {
local_var_req_builder =
local_var_req_builder.query(&[("format", &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(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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_type = local_var_resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok())
.map(str::to_string);
let local_var_body = local_var_resp.bytes().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
crate::apis::decode_response_body(local_var_content_type.as_deref(), &local_var_body)
} else {
let local_var_content = String::from_utf8_lossy(&local_var_body).into_owned();
let local_var_entity: Option<GetPendingTransactionsByAddressError> =
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 pending_transaction_information(
configuration: &configuration::Configuration,
txid: &str,
format: Option<&str>,
) -> Result<
algonaut_model::algod::PendingTransactionResponse,
Error<PendingTransactionInformationError>,
> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/v2/transactions/pending/{txid}",
local_var_configuration.base_path,
txid = crate::apis::urlencode(txid)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = format {
local_var_req_builder =
local_var_req_builder.query(&[("format", &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(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
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_type = local_var_resp
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|v| v.to_str().ok())
.map(str::to_string);
let local_var_body = local_var_resp.bytes().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
crate::apis::decode_response_body(local_var_content_type.as_deref(), &local_var_body)
} else {
let local_var_content = String::from_utf8_lossy(&local_var_body).into_owned();
let local_var_entity: Option<PendingTransactionInformationError> =
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 raw_transaction(
configuration: &configuration::Configuration,
rawtxn: &[u8],
) -> Result<algonaut_model::algod::SubmitResponse, Error<RawTransactionError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v2/transactions", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("X-Algo-API-Token", local_var_value);
};
local_var_req_builder = local_var_req_builder.body(rawtxn.to_vec());
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<RawTransactionError> =
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))
}
}