lisk_api_rust_client/api/
delegates.rs

1use http::client::Client;
2use std::borrow::Borrow;
3
4use api::models::{DelegateWithAccount, Forger, ForgingStats};
5use api::Result;
6
7pub struct Delegates {
8    client: Client,
9}
10
11impl Delegates {
12    pub fn new(client: Client) -> Delegates {
13        Delegates { client }
14    }
15
16    pub fn all(&self) -> Result<Vec<DelegateWithAccount>> {
17        self.all_params(Vec::<(String, String)>::new())
18    }
19
20    pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<DelegateWithAccount>>
21    where
22        I: IntoIterator,
23        I::Item: Borrow<(K, V)>,
24        K: AsRef<str>,
25        V: AsRef<str>,
26    {
27        self.client.get_with_params("delegates", parameters)
28    }
29
30    pub fn forgers(&self) -> Result<Vec<Forger>> {
31        self.forgers_params(Vec::<(String, String)>::new())
32    }
33
34    pub fn forgers_params<I, K, V>(&self, parameters: I) -> Result<Vec<Forger>>
35    where
36        I: IntoIterator,
37        I::Item: Borrow<(K, V)>,
38        K: AsRef<str>,
39        V: AsRef<str>,
40    {
41        self.client.get_with_params("delegates/forgers", parameters)
42    }
43
44    pub fn forging_statistics(&self, address: &str) -> Result<Vec<ForgingStats>> {
45        self.forging_statistics_params(address, Vec::<(String, String)>::new())
46    }
47
48    pub fn forging_statistics_params<I, K, V>(
49        &self,
50        address: &str,
51        parameters: I,
52    ) -> Result<Vec<ForgingStats>>
53    where
54        I: IntoIterator,
55        I::Item: Borrow<(K, V)>,
56        K: AsRef<str>,
57        V: AsRef<str>,
58    {
59        let endpoint = format!("/delegates/{}/forging_statistics", address);
60        self.client.get_with_params(&endpoint, parameters)
61    }
62}