1use crate::{
2 models::{transactions::Transaction, Account, Hotspot, Oui, QueryTimeRange, Validator},
3 *,
4};
5
6pub fn all(client: &Client) -> Stream<Account> {
8 client.fetch_stream("/accounts", NO_QUERY)
9}
10
11pub async fn get(client: &Client, address: &str) -> Result<Account> {
13 client
14 .fetch(&format!("/accounts/{}", address), NO_QUERY)
15 .await
16}
17
18pub fn hotspots(client: &Client, address: &str) -> Stream<Hotspot> {
20 client.fetch_stream(&format!("/accounts/{}/hotspots", address), NO_QUERY)
21}
22
23pub fn ouis(client: &Client, address: &str) -> Stream<Oui> {
25 client.fetch_stream(&format!("/accounts/{}/ouis", address), NO_QUERY)
26}
27
28pub fn validators(client: &Client, address: &str) -> Stream<Validator> {
30 client.fetch_stream(&format!("/accounts/{}/validators", address), NO_QUERY)
31}
32
33pub async fn richest(client: &Client, limit: Option<u32>) -> Result<Vec<Account>> {
36 client
37 .fetch("/accounts/rich", &[("limit", limit.unwrap_or(1000))])
38 .await
39}
40
41pub fn activity(client: &Client, address: &str, query: &QueryTimeRange) -> Stream<Transaction> {
44 client.fetch_stream(&format!("/accounts/{}/activity", address), query)
45}
46
47#[cfg(test)]
48mod test {
49 use super::*;
50 use tokio::test;
51
52 #[test]
53 async fn all() {
54 let client = get_test_client();
55 let accounts = accounts::all(&client)
56 .take(10)
57 .into_vec()
58 .await
59 .expect("accounts");
60 assert_eq!(accounts.len(), 10);
61 }
62
63 #[test]
64 async fn get() {
65 let client = get_test_client();
66 let account = accounts::get(
67 &client,
68 "13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R",
69 )
70 .await
71 .expect("account");
72 assert_eq!(
73 account.address,
74 "13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R"
75 );
76 }
77
78 #[test]
79 async fn ouis() {
80 let client = get_test_client();
81 let ouis = accounts::ouis(
82 &client,
83 "13tyMLKRFYURNBQqLSqNJg9k41maP1A7Bh8QYxR13oWv7EnFooc",
84 )
85 .into_vec()
86 .await
87 .expect("oui list");
88 assert_eq!(ouis.len(), 1);
89 }
90
91 #[test]
92 async fn hotspots() {
93 let client = get_test_client();
94 let hotspots = accounts::hotspots(
95 &client,
96 "13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R",
97 )
98 .into_vec()
99 .await
100 .expect("hotspot list");
101 assert!(hotspots.len() > 0);
102 }
103
104 #[test]
105 async fn richest() {
106 let client = get_test_client();
107 let richest = accounts::richest(&client, Some(10))
108 .await
109 .expect("richest list");
110 assert_eq!(richest.len(), 10);
111 }
112}