pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct NetworksClient {
client: crate::client::Client,
}
impl NetworksClient {
pub fn new(client: crate::client::Client) -> Self {
NetworksClient { client }
}
pub async fn estimate_fees(
&self,
query: Option<EstimateFeesQuery>,
) -> Result<serde_json::Value, crate::error::Error> {
let mut path = String::from("/networks/fees");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
q.push(format!(
"network={}",
urlencoding::encode(&query.network.to_string())
));
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn call_function(
&self,
network: String,
body: CallFunctionRequest,
) -> Result<serde_json::Value, crate::error::Error> {
let path = format!("/networks/{}/call-function", urlencoding::encode(&network));
let body = serde_json::to_value(&body)?;
self.client
.request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
.await
}
pub async fn get_canton_validator(
&self,
network: String,
validator_id: String,
) -> Result<GetCantonValidatorResponse, crate::error::Error> {
let path = format!(
"/networks/{}/validators/{}",
urlencoding::encode(&network),
urlencoding::encode(&validator_id)
);
self.client
.request::<GetCantonValidatorResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn update_canton_validator(
&self,
network: String,
validator_id: String,
body: UpdateCantonValidatorRequest,
) -> Result<UpdateCantonValidatorResponse, crate::error::Error> {
let path = format!(
"/networks/{}/validators/{}",
urlencoding::encode(&network),
urlencoding::encode(&validator_id)
);
let body = serde_json::to_value(&body)?;
self.client
.request::<UpdateCantonValidatorResponse>(
reqwest::Method::PUT,
&path,
Some(&body),
true,
)
.await
}
pub async fn delete_canton_validator(
&self,
network: String,
validator_id: String,
) -> Result<DeleteCantonValidatorResponse, crate::error::Error> {
let path = format!(
"/networks/{}/validators/{}",
urlencoding::encode(&network),
urlencoding::encode(&validator_id)
);
self.client
.request::<DeleteCantonValidatorResponse>(reqwest::Method::DELETE, &path, None, true)
.await
}
pub async fn list_canton_validators(
&self,
network: String,
query: Option<ListCantonValidatorsQuery>,
) -> Result<ListCantonValidatorsResponse, crate::error::Error> {
let mut path = format!("/networks/{}/validators", urlencoding::encode(&network));
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListCantonValidatorsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_canton_validator(
&self,
network: String,
body: CreateCantonValidatorRequest,
) -> Result<CreateCantonValidatorResponse, crate::error::Error> {
let path = format!("/networks/{}/validators", urlencoding::encode(&network));
let body = serde_json::to_value(&body)?;
self.client
.request::<CreateCantonValidatorResponse>(
reqwest::Method::POST,
&path,
Some(&body),
true,
)
.await
}
}