7
7
// Author: Simon Brummer ([email protected] )
8
8
9
9
#![ warn( missing_docs, clippy:: unwrap_used) ]
10
+
11
+ ///
12
+ /// A CLI tool for [`mempool_space`].
13
+ ///
14
+ /// [`mempool_space`]: https://github.com/randymcmillan/mempool_space
15
+
16
+ /// TESTING
17
+ ///
18
+ /// TESTING 2
19
+ ///
20
+ /// TESTING 2
21
+ ///
22
+ /// TESTING 2
23
+ ///
24
+ /// TESTING 2
25
+
26
+ // #[warn(missing_docs, clippy::unwrap_used)]
27
+ pub mod api;
28
+ pub mod blockheight;
29
+ pub mod blocking;
30
+ pub mod error;
31
+ pub mod resolve_policy;
32
+ pub mod target;
33
+
34
+ pub use error:: { CheckTargetError , ParseTargetError , ResolveTargetError } ;
35
+ pub use resolve_policy:: ResolvePolicy ;
36
+ pub use target:: { Fqhn , IcmpTarget , Port , Status , Target , TcpTarget } ;
37
+
38
+ #[ cfg( feature = "async" ) ]
39
+ pub use async_target:: { AsyncTarget , AsyncTargetExecutor , BoxedHandler , BoxedTarget , OldStatus } ;
40
+
41
+ /// Command-line argument parser.
42
+ pub mod args;
43
+ #[ cfg( feature = "async" ) ]
44
+ pub mod async_target;
45
+
46
+ /// Configuration file parser.
47
+ pub mod config;
48
+ /// Custom error implementation.
49
+ pub mod this_error;
50
+ /// Upload handler.
51
+ pub mod upload;
52
+
53
+ use crate :: args:: Args ;
54
+ use crate :: config:: Config ;
55
+ use crate :: this_error:: { Error , Result } ;
56
+ use crate :: upload:: Uploader ;
57
+ // use colored::Colorize;
58
+ use crossterm:: style:: Stylize ;
59
+ use std:: fs;
60
+ use std:: io:: IsTerminal ;
10
61
use std:: io:: Read ;
11
- const API_VERSION : & str = "v1" ;
62
+ use std:: io:: { self } ; //, Read};
63
+
64
+ use crate :: blocking:: blocking;
65
+
12
66
const URL : & str = "https://mempool.space/api" ;
13
67
68
+ // BOOM
69
+ //
14
70
/// mempool_space - a mempool.space API lib
15
71
///
16
72
/// Author: @RandyMcMillan ([email protected] )
@@ -24,38 +80,8 @@ const URL: &str = "https://mempool.space/api";
24
80
/// 1. Flags follow the mempool.space api/rest (replace dashes with underscores)
25
81
/// 2. Flags invoke the executable
26
82
27
- ///
28
-
29
- /// `pub fn api(option: &str, sub_string: &str) -> String`
30
83
///
31
- pub fn api ( option : & str , sub_string : & str ) -> String {
32
- use std:: process:: Command ;
33
84
34
- //if sub_string == "v1" {
35
- // print!("TODO: support --version v1 api versioning.");
36
- //} else if sub_string == "v2" {
37
- // print!("TODO: support --version v2 api versioning.");
38
- //} else {
39
- let output = if cfg ! ( target_os = "windows" ) {
40
- Command :: new ( format ! ( "mempool-space_{}" , option) )
41
- . args ( [ "/C" , sub_string] )
42
- . output ( )
43
- . expect ( "failed to execute process" )
44
- } else {
45
- Command :: new ( format ! ( "mempool-space_{}" , option) )
46
- . arg ( sub_string)
47
- //.arg("echo hello")
48
- . output ( )
49
- . expect ( "failed to execute process" )
50
- } ;
51
-
52
- let result = String :: from_utf8 ( output. stdout )
53
- . map_err ( |non_utf8| String :: from_utf8_lossy ( non_utf8. as_bytes ( ) ) . into_owned ( ) )
54
- . unwrap ( ) ;
55
- print ! ( "{}" , result) ;
56
- result
57
- //}
58
- }
59
85
/// mempool_space - a mempool.space API lib
60
86
///
61
87
/// Author: @RandyMcMillan ([email protected] )
@@ -84,84 +110,6 @@ pub fn api(option: &str, sub_string: &str) -> String {
84
110
/// mempool-space_block $(mempool-space_blocks_tip_hash)
85
111
///
86
112
87
- /// `pub fn blocking(api: &String) -> Result<&str>`
88
- pub fn blocking ( api : & String ) -> Result < & str > {
89
- //print!("api={}", api);
90
- let call = format ! ( "{}/{}" , URL , api) ;
91
- let mut body = ureq:: get ( & call)
92
- . call ( )
93
- . expect ( "calls to blocking(api: &String) needs to include /v1/<api_endpoint> in some cases." )
94
- . into_reader ( ) ;
95
- let mut buf = Vec :: new ( ) ;
96
- body. read_to_end ( & mut buf) . unwrap ( ) ;
97
- if !api. ends_with ( "raw" ) {
98
- //print!("!api.ends_with raw");
99
- let text = match std:: str:: from_utf8 ( & buf) {
100
- Ok ( s) => s,
101
- Err ( _) => panic ! ( "Invalid ASCII data" ) ,
102
- } ;
103
- print ! ( "{}" , text) ;
104
- } else {
105
- if api. ends_with ( "raw" ) {
106
- //print!("api.ends_with raw");
107
- print ! ( "{:?}" , & buf) ;
108
- }
109
- if api. ends_with ( "something_else" ) {
110
- //print!("api.ends_with something_else");
111
- print ! ( "{:?}" , & buf) ;
112
- }
113
- }
114
- Ok ( api)
115
- }
116
-
117
- /// `pub mod blockheight`
118
- pub mod blockheight;
119
- /// `pub mod error`
120
- pub mod error;
121
- /// `pub mod resolve_policy`
122
- pub mod resolve_policy;
123
- /// `pub mod target`
124
- pub mod target;
125
-
126
- #[ cfg( feature = "async" ) ]
127
- /// `pub mod async_target`
128
- pub mod async_target;
129
-
130
- // Re-exports
131
- /// `pub use error`
132
- pub use error:: { CheckTargetError , ParseTargetError , ResolveTargetError } ;
133
- /// `pub use resolve_policy`
134
- pub use resolve_policy:: ResolvePolicy ;
135
- /// `pub use target`
136
- pub use target:: { Fqhn , IcmpTarget , Port , Status , Target , TcpTarget } ;
137
-
138
- #[ cfg( feature = "async" ) ]
139
- pub use async_target:: { AsyncTarget , AsyncTargetExecutor , BoxedHandler , BoxedTarget , OldStatus } ;
140
-
141
- /// A CLI tool for [`mempool_space`].
142
- ///
143
- /// [`mempool_space`]: https://github.com/randymcmillan/mempool_space
144
-
145
- /// Command-line argument parser.
146
- pub mod args;
147
- /// Configuration file parser.
148
- pub mod config;
149
- /// Custom error implementation.
150
- pub mod this_error;
151
- /// Upload handler.
152
- pub mod upload;
153
-
154
- use crate :: args:: Args ;
155
- use crate :: config:: Config ;
156
- use crate :: this_error:: { Error , Result } ;
157
- use crate :: upload:: Uploader ;
158
- // use colored::Colorize;
159
- use std:: fs;
160
- use std:: io:: IsTerminal ;
161
- use std:: io:: { self } ; //, Read};
162
-
163
- use crossterm:: style:: Stylize ;
164
-
165
113
/// Default name of the configuration file.
166
114
const CONFIG_FILE : & str = "config.toml" ;
167
115
@@ -275,11 +223,12 @@ pub fn wait(sleep: &str) {
275
223
// }
276
224
}
277
225
226
+ /// TESTS
278
227
#[ cfg( test) ]
279
228
mod tests {
280
229
// Note this useful idiom: importing names from outer (for mod tests) scope.
281
230
use super :: * ;
282
- use crate :: args :: api;
231
+ use crate :: api :: api;
283
232
284
233
/// General
285
234
/// https://mempool.space/docs/api/rest
0 commit comments