use crate::{
client::{ClientInner, Result},
types::{
api::plugins::participation::{
responses::{AddressOutputsResponse, EventsResponse, OutputStatusResponse},
types::{
AddressStakingStatus, ParticipationEventData, ParticipationEventId, ParticipationEventStatus,
ParticipationEventType,
},
},
block::{address::Bech32Address, output::OutputId, ConvertTo},
},
};
impl ClientInner {
pub async fn events(&self, event_type: Option<ParticipationEventType>) -> Result<EventsResponse> {
let route = "api/participation/v1/events";
let query = event_type.map(|event_type| match event_type {
ParticipationEventType::Voting => "type=0",
ParticipationEventType::Staking => "type=1",
});
self.node_manager
.read()
.await
.get_request(route, query, self.get_timeout().await, false, false)
.await
}
pub async fn event(&self, event_id: &ParticipationEventId) -> Result<ParticipationEventData> {
let route = format!("api/participation/v1/events/{event_id}");
self.node_manager
.read()
.await
.get_request(&route, None, self.get_timeout().await, false, false)
.await
}
pub async fn event_status(
&self,
event_id: &ParticipationEventId,
milestone_index: Option<u32>,
) -> Result<ParticipationEventStatus> {
let route = format!("api/participation/v1/events/{event_id}/status");
self.node_manager
.read()
.await
.get_request(
&route,
milestone_index.map(|index| index.to_string()).as_deref(),
self.get_timeout().await,
false,
false,
)
.await
}
pub async fn output_status(&self, output_id: &OutputId) -> Result<OutputStatusResponse> {
let route = format!("api/participation/v1/outputs/{output_id}");
self.node_manager
.read()
.await
.get_request(&route, None, self.get_timeout().await, false, false)
.await
}
pub async fn address_staking_status(
&self,
bech32_address: impl ConvertTo<Bech32Address>,
) -> Result<AddressStakingStatus> {
let route = format!("api/participation/v1/addresses/{}", bech32_address.convert()?);
self.node_manager
.read()
.await
.get_request(&route, None, self.get_timeout().await, false, false)
.await
}
pub async fn address_participation_output_ids(
&self,
bech32_address: impl ConvertTo<Bech32Address>,
) -> Result<AddressOutputsResponse> {
let route = format!("api/participation/v1/addresses/{}/outputs", bech32_address.convert()?);
self.node_manager
.read()
.await
.get_request(&route, None, self.get_timeout().await, false, false)
.await
}
}