use crate::{
client::{node_api::query_tuples_to_query_string, ClientError, ClientInner},
types::{
api::plugins::participation::{
responses::{AddressOutputsResponse, EventsResponse, OutputStatusResponse},
types::{
AddressStakingStatus, ParticipationEventData, ParticipationEventId, ParticipationEventStatus,
ParticipationEventType,
},
},
block::{address::Bech32Address, output::OutputId},
},
utils::ConvertTo,
};
impl ClientInner {
pub async fn events(&self, event_type: Option<ParticipationEventType>) -> Result<EventsResponse, ClientError> {
let route = "api/participation/v1/events";
let query = query_tuples_to_query_string([event_type.map(|t| ("type", (t as u8).to_string()))]);
self.get_request(route, query.as_deref(), false).await
}
pub async fn event(&self, event_id: &ParticipationEventId) -> Result<ParticipationEventData, ClientError> {
let route = format!("api/participation/v1/events/{event_id}");
self.get_request(&route, None, false).await
}
pub async fn event_status(
&self,
event_id: &ParticipationEventId,
milestone_index: Option<u32>,
) -> Result<ParticipationEventStatus, ClientError> {
let route = format!("api/participation/v1/events/{event_id}/status");
let query = query_tuples_to_query_string([milestone_index.map(|i| ("milestoneIndex", i.to_string()))]);
self.get_request(&route, query.as_deref(), false).await
}
pub async fn output_status(&self, output_id: &OutputId) -> Result<OutputStatusResponse, ClientError> {
let route = format!("api/participation/v1/outputs/{output_id}");
self.get_request(&route, None, false).await
}
pub async fn address_staking_status(
&self,
bech32_address: impl ConvertTo<Bech32Address>,
) -> Result<AddressStakingStatus, ClientError> {
let route = format!("api/participation/v1/addresses/{}", bech32_address.convert()?);
self.get_request(&route, None, false).await
}
pub async fn address_participation_output_ids(
&self,
bech32_address: impl ConvertTo<Bech32Address>,
) -> Result<AddressOutputsResponse, ClientError> {
let route = format!("api/participation/v1/addresses/{}/outputs", bech32_address.convert()?);
self.get_request(&route, None, false).await
}
}