arkecosystem_client/api/
wallets.rs

1use http::client::Client;
2use std::borrow::Borrow;
3
4use api::models::{Transaction, Wallet};
5use api::Result;
6
7pub struct Wallets {
8    client: Client,
9}
10
11impl Wallets {
12    pub fn new(client: Client) -> Wallets {
13        Wallets { client }
14    }
15
16    pub fn all(&self) -> Result<Vec<Wallet>> {
17        self.all_params(Vec::<(String, String)>::new())
18    }
19
20    pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Wallet>>
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("wallets", parameters)
28    }
29
30    pub fn top(&self) -> Result<Vec<Wallet>> {
31        self.top_params(Vec::<(String, String)>::new())
32    }
33
34    pub fn top_params<I, K, V>(&self, parameters: I) -> Result<Vec<Wallet>>
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("wallets/top", parameters)
42    }
43
44    pub fn show(&self, id: &str) -> Result<Wallet> {
45        let endpoint = format!("wallets/{}", id);
46        self.client.get(&endpoint)
47    }
48
49    pub fn transactions(&self, id: &str) -> Result<Vec<Transaction>> {
50        self.transactions_params(id, Vec::<(String, String)>::new())
51    }
52
53    pub fn transactions_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Transaction>>
54    where
55        I: IntoIterator,
56        I::Item: Borrow<(K, V)>,
57        K: AsRef<str>,
58        V: AsRef<str>,
59    {
60        let endpoint = format!("wallets/{}/transactions", id);
61        self.client.get_with_params(&endpoint, parameters)
62    }
63
64    pub fn sent_transactions(&self, id: &str) -> Result<Vec<Transaction>> {
65        self.sent_transactions_params(id, Vec::<(String, String)>::new())
66    }
67
68    pub fn sent_transactions_params<I, K, V>(
69        &self,
70        id: &str,
71        parameters: I,
72    ) -> Result<Vec<Transaction>>
73    where
74        I: IntoIterator,
75        I::Item: Borrow<(K, V)>,
76        K: AsRef<str>,
77        V: AsRef<str>,
78    {
79        let endpoint = format!("wallets/{}/transactions/sent", id);
80        self.client.get_with_params(&endpoint, parameters)
81    }
82
83    pub fn received_transactions(&self, id: &str) -> Result<Vec<Transaction>> {
84        self.received_transactions_params(id, Vec::<(String, String)>::new())
85    }
86
87    pub fn received_transactions_params<I, K, V>(
88        &self,
89        id: &str,
90        parameters: I,
91    ) -> Result<Vec<Transaction>>
92    where
93        I: IntoIterator,
94        I::Item: Borrow<(K, V)>,
95        K: AsRef<str>,
96        V: AsRef<str>,
97    {
98        let endpoint = format!("wallets/{}/transactions/received", id);
99        self.client.get_with_params(&endpoint, parameters)
100    }
101
102    pub fn votes(&self, id: &str) -> Result<Vec<Transaction>> {
103        let endpoint = format!("wallets/{}/votes", id);
104        self.client.get(&endpoint)
105    }
106
107    pub fn search<I, K, V>(&self, parameters: I) -> Result<Vec<Wallet>>
108    where
109        I: IntoIterator,
110        I::Item: Borrow<(K, V)>,
111        K: AsRef<str>,
112        V: AsRef<str>,
113    {
114        self.client.get_with_params("wallets/search", parameters)
115    }
116}