arkecosystem_client/api/
transactions.rs1use api::models::{Transaction, TransactionFees, TransactionTypes};
2use api::Result;
3use http::client::Client;
4use std::borrow::Borrow;
5use std::collections::HashMap;
6
7pub struct Transactions {
8 client: Client,
9}
10
11impl Transactions {
12 pub fn new(client: Client) -> Transactions {
13 Transactions { client }
14 }
15
16 pub fn all(&self) -> Result<Vec<Transaction>> {
17 self.all_params(Vec::<(String, String)>::new())
18 }
19
20 pub fn all_params<I, K, V>(&self, parameters: I) -> Result<Vec<Transaction>>
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("transactions", parameters)
28 }
29
30 pub fn create(&self, transactions: Vec<&str>) -> Result<Transaction> {
31 let mut payload = HashMap::<&str, Vec<&str>>::new();
32 payload.insert("transactions", transactions);
33
34 self.client.post("transactions", Some(payload))
35 }
36
37 pub fn show(&self, id: &str) -> Result<Transaction> {
38 let endpoint = format!("transactions/{}", id);
39 self.client.get(&endpoint)
40 }
41
42 pub fn all_unconfirmed(&self) -> Result<Vec<Transaction>> {
43 self.all_unconfirmed_params(Vec::<(String, String)>::new())
44 }
45
46 pub fn all_unconfirmed_params<I, K, V>(&self, parameters: I) -> Result<Vec<Transaction>>
47 where
48 I: IntoIterator,
49 I::Item: Borrow<(K, V)>,
50 K: AsRef<str>,
51 V: AsRef<str>,
52 {
53 self.client
54 .get_with_params("transactions/unconfirmed", parameters)
55 }
56
57 pub fn show_unconfirmed(&self, id: &str) -> Result<Vec<Transaction>> {
58 let endpoint = format!("transactions/unconfirmed/{}", id);
59 self.client.get(&endpoint)
60 }
61
62 pub fn search<I, K, V>(
63 &self,
64 payload: Option<HashMap<&str, &str>>,
65 parameters: I,
66 ) -> Result<Vec<Transaction>>
67 where
68 I: IntoIterator,
69 I::Item: Borrow<(K, V)>,
70 K: AsRef<str>,
71 V: AsRef<str>,
72 {
73 self.client
74 .post_with_params("transactions/search", payload, parameters)
75 }
76
77 pub fn types(&self) -> Result<TransactionTypes> {
94 self.client.get("transactions/types")
95 }
96
97 pub fn fees(&self) -> Result<TransactionFees> {
114 self.client.get("transactions/fees")
115 }
116}