use crate::{
models::{transactions::Transaction, Account, Hotspot, Oui, QueryTimeRange, Validator},
*,
};
pub fn all(client: &Client) -> Stream<Account> {
client.fetch_stream("/accounts", NO_QUERY)
}
pub async fn get(client: &Client, address: &str) -> Result<Account> {
client
.fetch(&format!("/accounts/{}", address), NO_QUERY)
.await
}
pub fn hotspots(client: &Client, address: &str) -> Stream<Hotspot> {
client.fetch_stream(&format!("/accounts/{}/hotspots", address), NO_QUERY)
}
pub fn ouis(client: &Client, address: &str) -> Stream<Oui> {
client.fetch_stream(&format!("/accounts/{}/ouis", address), NO_QUERY)
}
pub fn validators(client: &Client, address: &str) -> Stream<Validator> {
client.fetch_stream(&format!("/accounts/{}/validators", address), NO_QUERY)
}
pub async fn richest(client: &Client, limit: Option<u32>) -> Result<Vec<Account>> {
client
.fetch("/accounts/rich", &[("limit", limit.unwrap_or(1000))])
.await
}
pub fn activity(client: &Client, address: &str, query: &QueryTimeRange) -> Stream<Transaction> {
client.fetch_stream(&format!("/accounts/{}/activity", address), query)
}
#[cfg(test)]
mod test {
use super::*;
use tokio::test;
#[test]
async fn all() {
let client = get_test_client();
let accounts = accounts::all(&client)
.take(10)
.into_vec()
.await
.expect("accounts");
assert_eq!(accounts.len(), 10);
}
#[test]
async fn get() {
let client = get_test_client();
let account = accounts::get(
&client,
"13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R",
)
.await
.expect("account");
assert_eq!(
account.address,
"13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R"
);
}
#[test]
async fn ouis() {
let client = get_test_client();
let ouis = accounts::ouis(
&client,
"13tyMLKRFYURNBQqLSqNJg9k41maP1A7Bh8QYxR13oWv7EnFooc",
)
.into_vec()
.await
.expect("oui list");
assert_eq!(ouis.len(), 1);
}
#[test]
async fn hotspots() {
let client = get_test_client();
let hotspots = accounts::hotspots(
&client,
"13WRNw4fmssJBvMqMnREwe1eCvUVXfnWXSXGcWXyVvAnQUF3D9R",
)
.into_vec()
.await
.expect("hotspot list");
assert!(hotspots.len() > 0);
}
#[test]
async fn richest() {
let client = get_test_client();
let richest = accounts::richest(&client, Some(10))
.await
.expect("richest list");
assert_eq!(richest.len(), 10);
}
}