helium_api/
validators.rs

1use crate::{
2    models::{QueryTimeRange, Reward, Validator, ValidatorStats},
3    *,
4};
5
6/// Get all known validators
7pub fn all(client: &Client) -> Stream<Validator> {
8    client.fetch_stream("/validators", NO_QUERY)
9}
10
11/// Get a specific validator
12pub async fn get(client: &Client, address: &str) -> Result<Validator> {
13    client
14        .fetch(&format!("/validators/{}", address), NO_QUERY)
15        .await
16}
17
18/// Get stats for validators
19pub async fn stats(client: &Client) -> Result<ValidatorStats> {
20    client.fetch("/validators/stats", NO_QUERY).await
21}
22
23/// Get rewards for a validator
24///
25/// Returns rewards for a given validator per reward block the validator is in,
26/// for a given timeframe. `QueryTimeRange` contains the timestamps given in
27/// 4ISO 8601 format, or in relative time. The block that contains the max_time
28/// timestamp is excluded from the result.
29pub fn rewards(client: &Client, address: &str, query: &QueryTimeRange) -> Stream<Reward> {
30    client.fetch_stream(&format!("/validators/{}/rewards", address), query)
31}