use crate::{
client::{Client, Result},
types::{
api::plugins::participation::{
responses::{AddressOutputsResponse, EventsResponse, OutputStatusResponse},
types::{
AddressStakingStatus, ParticipationEventData, ParticipationEventId, ParticipationEventStatus,
ParticipationEventType,
},
},
block::output::OutputId,
},
};
impl Client {
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
.get_request(route, query, self.get_timeout(), 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
.get_request(&route, None, self.get_timeout(), 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
.get_request(
&route,
milestone_index.map(|index| index.to_string()).as_deref(),
self.get_timeout(),
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
.get_request(&route, None, self.get_timeout(), false, false)
.await
}
pub async fn address_staking_status(&self, bech32_address: &str) -> Result<AddressStakingStatus> {
let route = format!("api/participation/v1/addresses/{bech32_address}");
self.node_manager
.get_request(&route, None, self.get_timeout(), false, false)
.await
}
pub async fn address_participation_output_ids(&self, bech32_address: &str) -> Result<AddressOutputsResponse> {
let route = format!("api/participation/v1/addresses/{bech32_address}/outputs");
self.node_manager
.get_request(&route, None, self.get_timeout(), false, false)
.await
}
}