use crate::client::{seg, FyuzClient, QueryPairs};
use crate::error::Result;
use crate::models::{
AddressPayouts, Claimable, PayoutStats, Pot, RoundDetail, RoundReceipt, Shares,
};
use crate::params::{RoundsParams, SharesParams, ToQuery};
#[derive(Debug, Clone, Copy)]
pub struct Distributor<'a> {
client: &'a FyuzClient,
}
impl<'a> Distributor<'a> {
pub(crate) fn new(client: &'a FyuzClient) -> Self {
Self { client }
}
pub async fn get_stats(&self) -> Result<PayoutStats> {
self.client
.get_json("/distributor/stats", QueryPairs::new())
.await
}
pub async fn get_pot(&self) -> Result<Pot> {
self.client
.get_json("/distributor/pot", QueryPairs::new())
.await
}
pub async fn get_shares(&self, params: &SharesParams) -> Result<Shares> {
self.client
.get_json("/distributor/shares", params.to_query())
.await
}
pub async fn list_rounds(&self, params: &RoundsParams) -> Result<Vec<RoundReceipt>> {
self.client
.get_json("/distributor/rounds", params.to_query())
.await
}
pub async fn get_round(&self, id: i64) -> Result<RoundDetail> {
self.client
.get_json(&format!("/distributor/rounds/{id}"), QueryPairs::new())
.await
}
pub async fn get_payouts(&self, address: &str) -> Result<AddressPayouts> {
self.client
.get_json(
&format!("/distributor/payouts/{}", seg(address)),
QueryPairs::new(),
)
.await
}
pub async fn get_claimable(&self, address: &str) -> Result<Claimable> {
self.client
.get_json(
&format!("/distributor/claimable/{}", seg(address)),
QueryPairs::new(),
)
.await
}
}