use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccountTxsError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BlockTxsError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DepositHistoryError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NextNonceError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendTxError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SendTxBatchError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TransferHistoryError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TxError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TxFromL1TxHashError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TxsError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WithdrawHistoryError {
Status400(models::ResultCode),
UnknownValue(serde_json::Value),
}
pub async fn account_txs(
configuration: &configuration::Configuration,
limit: i64,
by: &str,
value: &str,
authorization: Option<&str>,
index: Option<i64>,
types: Option<Vec<i32>>,
auth: Option<&str>,
) -> Result<models::Txs, Error<AccountTxsError>> {
let p_query_limit = limit;
let p_query_by = by;
let p_query_value = value;
let p_header_authorization = authorization;
let p_query_index = index;
let p_query_types = types;
let p_query_auth = auth;
let uri_str = format!("{}/api/v1/accountTxs", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_index {
req_builder = req_builder.query(&[("index", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("limit", &p_query_limit.to_string())]);
req_builder = req_builder.query(&[("by", &p_query_by.to_string())]);
req_builder = req_builder.query(&[("value", &p_query_value.to_string())]);
if let Some(ref param_value) = p_query_types {
req_builder = match "csv" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("types".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"types",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = p_query_auth {
req_builder = req_builder.query(&[("auth", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_authorization {
req_builder = req_builder.header("authorization", param_value.to_string());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Txs`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Txs`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccountTxsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn block_txs(
configuration: &configuration::Configuration,
by: &str,
value: &str,
) -> Result<models::Txs, Error<BlockTxsError>> {
let p_query_by = by;
let p_query_value = value;
let uri_str = format!("{}/api/v1/blockTxs", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("by", &p_query_by.to_string())]);
req_builder = req_builder.query(&[("value", &p_query_value.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Txs`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Txs`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BlockTxsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn deposit_history(
configuration: &configuration::Configuration,
account_index: i64,
l1_address: &str,
authorization: Option<&str>,
auth: Option<&str>,
cursor: Option<&str>,
filter: Option<&str>,
) -> Result<models::DepositHistory, Error<DepositHistoryError>> {
let p_query_account_index = account_index;
let p_query_l1_address = l1_address;
let p_header_authorization = authorization;
let p_query_auth = auth;
let p_query_cursor = cursor;
let p_query_filter = filter;
let uri_str = format!("{}/api/v1/deposit/history", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("account_index", &p_query_account_index.to_string())]);
if let Some(ref param_value) = p_query_auth {
req_builder = req_builder.query(&[("auth", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("l1_address", &p_query_l1_address.to_string())]);
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_authorization {
req_builder = req_builder.header("authorization", param_value.to_string());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DepositHistory`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DepositHistory`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DepositHistoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn next_nonce(
configuration: &configuration::Configuration,
account_index: i64,
api_key_index: i32,
) -> Result<models::NextNonce, Error<NextNonceError>> {
let p_query_account_index = account_index;
let p_query_api_key_index = api_key_index;
let uri_str = format!("{}/api/v1/nextNonce", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("account_index", &p_query_account_index.to_string())]);
req_builder = req_builder.query(&[("api_key_index", &p_query_api_key_index.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NextNonce`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::NextNonce`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<NextNonceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn send_tx(
configuration: &configuration::Configuration,
tx_type: i32,
tx_info: &str,
price_protection: Option<bool>,
) -> Result<models::RespSendTx, Error<SendTxError>> {
let p_form_tx_type = tx_type;
let p_form_tx_info = tx_info;
let p_form_price_protection = price_protection;
let uri_str = format!("{}/api/v1/sendTx", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form = reqwest::multipart::Form::new();
multipart_form = multipart_form.text("tx_type", p_form_tx_type.to_string());
multipart_form = multipart_form.text("tx_info", p_form_tx_info.to_string());
if let Some(param_value) = p_form_price_protection {
multipart_form = multipart_form.text("price_protection", param_value.to_string());
}
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSendTx`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSendTx`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendTxError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn send_tx_batch(
configuration: &configuration::Configuration,
tx_types: &str,
tx_infos: &str,
) -> Result<models::RespSendTxBatch, Error<SendTxBatchError>> {
let p_form_tx_types = tx_types;
let p_form_tx_infos = tx_infos;
let uri_str = format!("{}/api/v1/sendTxBatch", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let mut multipart_form = reqwest::multipart::Form::new();
multipart_form = multipart_form.text("tx_types", p_form_tx_types.to_string());
multipart_form = multipart_form.text("tx_infos", p_form_tx_infos.to_string());
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespSendTxBatch`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespSendTxBatch`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SendTxBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn transfer_history(
configuration: &configuration::Configuration,
account_index: i64,
authorization: Option<&str>,
auth: Option<&str>,
cursor: Option<&str>,
) -> Result<models::TransferHistory, Error<TransferHistoryError>> {
let p_query_account_index = account_index;
let p_header_authorization = authorization;
let p_query_auth = auth;
let p_query_cursor = cursor;
let uri_str = format!("{}/api/v1/transfer/history", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("account_index", &p_query_account_index.to_string())]);
if let Some(ref param_value) = p_query_auth {
req_builder = req_builder.query(&[("auth", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_authorization {
req_builder = req_builder.header("authorization", param_value.to_string());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TransferHistory`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TransferHistory`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<TransferHistoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn tx(
configuration: &configuration::Configuration,
by: &str,
value: &str,
) -> Result<models::EnrichedTx, Error<TxError>> {
let p_query_by = by;
let p_query_value = value;
let uri_str = format!("{}/api/v1/tx", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("by", &p_query_by.to_string())]);
req_builder = req_builder.query(&[("value", &p_query_value.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EnrichedTx`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EnrichedTx`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<TxError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn tx_from_l1_tx_hash(
configuration: &configuration::Configuration,
hash: &str,
) -> Result<models::EnrichedTx, Error<TxFromL1TxHashError>> {
let p_query_hash = hash;
let uri_str = format!("{}/api/v1/txFromL1TxHash", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("hash", &p_query_hash.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EnrichedTx`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EnrichedTx`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<TxFromL1TxHashError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn txs(
configuration: &configuration::Configuration,
limit: i64,
index: Option<i64>,
) -> Result<models::Txs, Error<TxsError>> {
let p_query_limit = limit;
let p_query_index = index;
let uri_str = format!("{}/api/v1/txs", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_index {
req_builder = req_builder.query(&[("index", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("limit", &p_query_limit.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Txs`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Txs`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<TxsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn withdraw_history(
configuration: &configuration::Configuration,
account_index: i64,
authorization: Option<&str>,
auth: Option<&str>,
cursor: Option<&str>,
filter: Option<&str>,
) -> Result<models::WithdrawHistory, Error<WithdrawHistoryError>> {
let p_query_account_index = account_index;
let p_header_authorization = authorization;
let p_query_auth = auth;
let p_query_cursor = cursor;
let p_query_filter = filter;
let uri_str = format!("{}/api/v1/withdraw/history", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("account_index", &p_query_account_index.to_string())]);
if let Some(ref param_value) = p_query_auth {
req_builder = req_builder.query(&[("auth", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_authorization {
req_builder = req_builder.header("authorization", param_value.to_string());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WithdrawHistory`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WithdrawHistory`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<WithdrawHistoryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}