satstream_rust_sdk/apis/
mempool_api.rs1use std::rc::Rc;
12use std::borrow::Borrow;
13use std::borrow::Cow;
14use std::collections::HashMap;
15
16use hyper;
17use serde_json;
18use futures;
19use futures::{Future, Stream};
20
21use hyper::header::UserAgent;
22
23use super::{Error, configuration};
24
25pub struct MempoolApiClient<C: hyper::client::Connect> {
26 configuration: Rc<configuration::Configuration<C>>,
27}
28
29impl<C: hyper::client::Connect> MempoolApiClient<C> {
30 pub fn new(configuration: Rc<configuration::Configuration<C>>) -> MempoolApiClient<C> {
31 MempoolApiClient {
32 configuration: configuration,
33 }
34 }
35}
36
37pub trait MempoolApi {
38 fn get_address_mempool_transactions(&self, address: &str) -> Box<Future<Item = ::models::ResponsesGetAddressMempoolTxs, Error = Error<serde_json::Value>>>;
39 fn get_mempool_transaction_info(&self, txid: &str) -> Box<Future<Item = ::models::ResponsesGetMempoolTxInfo, Error = Error<serde_json::Value>>>;
40 fn get_mempool_transactions(&self, ) -> Box<Future<Item = ::models::ResponsesGetMempoolTransactions, Error = Error<serde_json::Value>>>;
41}
42
43
44impl<C: hyper::client::Connect>MempoolApi for MempoolApiClient<C> {
45 fn get_address_mempool_transactions(&self, address: &str) -> Box<Future<Item = ::models::ResponsesGetAddressMempoolTxs, Error = Error<serde_json::Value>>> {
46 let configuration: &configuration::Configuration<C> = self.configuration.borrow();
47
48 let mut auth_headers = HashMap::<String, String>::new();
49 let mut auth_query = HashMap::<String, String>::new();
50 if let Some(ref apikey) = configuration.api_key {
51 let key = apikey.key.clone();
52 let val = match apikey.prefix {
53 Some(ref prefix) => format!("{} {}", prefix, key),
54 None => key,
55 };
56 auth_headers.insert("X-API-KEY".to_owned(), val);
57 };
58 let method = hyper::Method::Get;
59
60 let query_string = {
61 let mut query = ::url::form_urlencoded::Serializer::new(String::new());
62 for (key, val) in &auth_query {
63 query.append_pair(key, val);
64 }
65 query.finish()
66 };
67 let uri_str = format!("{}/mempool/addresses/{address}/transactions?{}", configuration.base_path, query_string, address=address);
68
69 let mut uri: hyper::Uri = uri_str.parse().unwrap();
74
75 let mut req = hyper::Request::new(method, uri);
76
77 if let Some(ref user_agent) = configuration.user_agent {
78 req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
79 }
80
81
82 for (key, val) in auth_headers {
83 req.headers_mut().set_raw(key, val);
84 }
85
86
87 Box::new(
89 configuration.client.request(req)
90 .map_err(|e| Error::from(e))
91 .and_then(|resp| {
92 let status = resp.status();
93 resp.body().concat2()
94 .and_then(move |body| Ok((status, body)))
95 .map_err(|e| Error::from(e))
96 })
97 .and_then(|(status, body)| {
98 if status.is_success() {
99 Ok(body)
100 } else {
101 Err(Error::from((status, &*body)))
102 }
103 })
104 .and_then(|body| {
105 let parsed: Result<::models::ResponsesGetAddressMempoolTxs, _> = serde_json::from_slice(&body);
106 parsed.map_err(|e| Error::from(e))
107 })
108 )
109 }
110
111 fn get_mempool_transaction_info(&self, txid: &str) -> Box<Future<Item = ::models::ResponsesGetMempoolTxInfo, Error = Error<serde_json::Value>>> {
112 let configuration: &configuration::Configuration<C> = self.configuration.borrow();
113
114 let mut auth_headers = HashMap::<String, String>::new();
115 let mut auth_query = HashMap::<String, String>::new();
116 if let Some(ref apikey) = configuration.api_key {
117 let key = apikey.key.clone();
118 let val = match apikey.prefix {
119 Some(ref prefix) => format!("{} {}", prefix, key),
120 None => key,
121 };
122 auth_headers.insert("X-API-KEY".to_owned(), val);
123 };
124 let method = hyper::Method::Get;
125
126 let query_string = {
127 let mut query = ::url::form_urlencoded::Serializer::new(String::new());
128 for (key, val) in &auth_query {
129 query.append_pair(key, val);
130 }
131 query.finish()
132 };
133 let uri_str = format!("{}/mempool/transactions/{txid}?{}", configuration.base_path, query_string, txid=txid);
134
135 let mut uri: hyper::Uri = uri_str.parse().unwrap();
140
141 let mut req = hyper::Request::new(method, uri);
142
143 if let Some(ref user_agent) = configuration.user_agent {
144 req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
145 }
146
147
148 for (key, val) in auth_headers {
149 req.headers_mut().set_raw(key, val);
150 }
151
152
153 Box::new(
155 configuration.client.request(req)
156 .map_err(|e| Error::from(e))
157 .and_then(|resp| {
158 let status = resp.status();
159 resp.body().concat2()
160 .and_then(move |body| Ok((status, body)))
161 .map_err(|e| Error::from(e))
162 })
163 .and_then(|(status, body)| {
164 if status.is_success() {
165 Ok(body)
166 } else {
167 Err(Error::from((status, &*body)))
168 }
169 })
170 .and_then(|body| {
171 let parsed: Result<::models::ResponsesGetMempoolTxInfo, _> = serde_json::from_slice(&body);
172 parsed.map_err(|e| Error::from(e))
173 })
174 )
175 }
176
177 fn get_mempool_transactions(&self, ) -> Box<Future<Item = ::models::ResponsesGetMempoolTransactions, Error = Error<serde_json::Value>>> {
178 let configuration: &configuration::Configuration<C> = self.configuration.borrow();
179
180 let method = hyper::Method::Get;
181
182 let query_string = {
183 let mut query = ::url::form_urlencoded::Serializer::new(String::new());
184 query.finish()
185 };
186 let uri_str = format!("{}/mempool/transactions?{}", configuration.base_path, query_string);
187
188 let mut uri: hyper::Uri = uri_str.parse().unwrap();
193
194 let mut req = hyper::Request::new(method, uri);
195
196 if let Some(ref user_agent) = configuration.user_agent {
197 req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
198 }
199
200
201
202
203 Box::new(
205 configuration.client.request(req)
206 .map_err(|e| Error::from(e))
207 .and_then(|resp| {
208 let status = resp.status();
209 resp.body().concat2()
210 .and_then(move |body| Ok((status, body)))
211 .map_err(|e| Error::from(e))
212 })
213 .and_then(|(status, body)| {
214 if status.is_success() {
215 Ok(body)
216 } else {
217 Err(Error::from((status, &*body)))
218 }
219 })
220 .and_then(|body| {
221 let parsed: Result<::models::ResponsesGetMempoolTransactions, _> = serde_json::from_slice(&body);
222 parsed.map_err(|e| Error::from(e))
223 })
224 )
225 }
226
227}