arkecosystem_client/api/
delegates.rs1use http::client::Client;
2use std::borrow::Borrow;
3use std::collections::HashMap;
4
5use api::models::{Balances, Block, Delegate, Wallet};
6use api::Result;
7
8pub struct Delegates {
9 client: Client,
10}
11
12impl Delegates {
13 pub fn new(client: Client) -> Delegates {
14 Delegates { client }
15 }
16
17 pub fn all(&self) -> Result<Vec<Delegate>> {
18 self.all_params(Vec::<(String, String)>::new())
19 }
20
21 pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Delegate>>
22 where
23 I: IntoIterator,
24 I::Item: Borrow<(K, V)>,
25 K: AsRef<str>,
26 V: AsRef<str>,
27 {
28 self.client.get_with_params("delegates", parameters)
29 }
30
31 pub fn show(&self, id: &str) -> Result<Delegate> {
32 let endpoint = format!("delegates/{}", id);
33 self.client.get(&endpoint)
34 }
35
36 pub fn blocks(&self, id: &str) -> Result<Vec<Block>> {
37 self.blocks_params(id, Vec::<(String, String)>::new())
38 }
39
40 pub fn blocks_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Block>>
41 where
42 I: IntoIterator,
43 I::Item: Borrow<(K, V)>,
44 K: AsRef<str>,
45 V: AsRef<str>,
46 {
47 let endpoint = format!("delegates/{}/blocks", id);
48 self.client.get_with_params(&endpoint, parameters)
49 }
50
51 pub fn voters(&self, id: &str) -> Result<Vec<Wallet>> {
52 self.voters_params(id, Vec::<(String, String)>::new())
53 }
54
55 pub fn voters_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Wallet>>
56 where
57 I: IntoIterator,
58 I::Item: Borrow<(K, V)>,
59 K: AsRef<str>,
60 V: AsRef<str>,
61 {
62 let endpoint = format!("delegates/{}/voters", id);
63 self.client.get_with_params(&endpoint, parameters)
64 }
65
66 pub fn voters_balances(&self, id: &str) -> Result<Balances> {
84 let endpoint = format!("delegates/{}/voters/balances", id);
85 self.client.get(&endpoint)
86 }
87
88 pub fn search<I, K, V>(
107 &self,
108 payload: Option<HashMap<&str, &str>>,
109 parameters: I,
110 ) -> Result<Vec<Delegate>>
111 where
112 I: IntoIterator,
113 I::Item: Borrow<(K, V)>,
114 K: AsRef<str>,
115 V: AsRef<str>,
116 {
117 self.client
118 .post_with_params("delegates/search", payload, parameters)
119 }
120}