arkecosystem_client/api/
blocks.rs

1use http::client::Client;
2use std::borrow::Borrow;
3
4use api::models::{Block, Transaction};
5use api::Result;
6
7pub struct Blocks {
8    client: Client,
9}
10
11impl Blocks {
12    pub fn new(client: Client) -> Blocks {
13        Blocks { client }
14    }
15
16    pub fn all(&self) -> Result<Vec<Block>> {
17        self.all_params(Vec::<(String, String)>::new())
18    }
19
20    pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Block>>
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("blocks", parameters)
28    }
29
30    pub fn show(&self, id: &str) -> Result<Block> {
31        let endpoint = format!("blocks/{}", id);
32
33        self.client.get(&endpoint)
34    }
35
36    pub fn transactions(&self, id: &str) -> Result<Vec<Transaction>> {
37        self.transactions_params(id, Vec::<(String, String)>::new())
38    }
39
40    pub fn transactions_params<I, K, V>(&self, id: &str, parameters: I) -> Result<Vec<Transaction>>
41    where
42        I: IntoIterator,
43        I::Item: Borrow<(K, V)>,
44        K: AsRef<str>,
45        V: AsRef<str>,
46    {
47        let endpoint = format!("blocks/{}/transactions", id);
48        self.client.get_with_params(&endpoint, parameters)
49    }
50
51    pub fn search<I, K, V>(&self, parameters: I) -> Result<Vec<Block>>
52    where
53        I: IntoIterator,
54        I::Item: Borrow<(K, V)>,
55        K: AsRef<str>,
56        V: AsRef<str>,
57    {
58        self.client.get_with_params("blocks/search", parameters)
59    }
60}