Skip to content

Commit 52a0f55

Browse files
committed
test_blocks:src/lib.rs:intermediate
1 parent 21ec8c6 commit 52a0f55

File tree

3 files changed

+136
-8
lines changed

3 files changed

+136
-8
lines changed

src/args.rs

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,49 @@ pub struct Args {
9898
/// `https://mempool.space/api/validate-address/<ADDRESS>`
9999
pub validate_address: Option<String>,
100100

101-
/// block.
101+
/// - BLOCK
102+
/// `https://mempool.space/api/block/<BLOCK_HASH>`
102103
pub block: Option<String>,
104+
/// `https://mempool.space/api/block/<BLOCK_HASH>/header`
105+
pub block_header: Option<String>,
106+
107+
/// - BLOCK_HEIGHT
108+
/// `https://mempool.space/api/block-height/<BLOCK_HEIGHT>`
109+
pub block_height: Option<String>,
110+
111+
/// - V1 MINING BLOCKS TIMESTAMP <UTC_SECS>
112+
/// `https://mempool.space/api/v1/mining/blocks/timestamp/<UTC_SECS>`
113+
pub block_timestamp: Option<String>,
114+
115+
/// - BLOCK
116+
/// `https://mempool.space/api/block/<BLOCK_HASH>/raw`
117+
pub block_raw: Option<String>,
118+
/// `https://mempool.space/api/block/<BLOCK_HASH>/status`
119+
pub block_status: Option<String>,
120+
121+
/// - BLOCKS TIP HEIGHT
122+
/// `https://mempool.space/api/blocks/tip/height`
123+
pub blocks_tip_height: Option<String>,
124+
/// - BLOCKS TIP HASH
125+
/// `https://mempool.space/api/blocks/tip/hash`
126+
pub blocks_tip_hash: Option<String>,
127+
128+
/// - BLOCK <BLOCK_HASH> <TXID> <INDEX>
129+
/// `https://mempool.space/api/block/<TXID>/<INDEX>`
130+
pub block_txid: Option<String>,
131+
/// - BLOCK <BLOCK_HASH> <TXIDS>
132+
/// `https://mempool.space/api/block/<TXID>`
133+
pub block_txids: Option<String>,
134+
135+
/// - BLOCK <BLOCK_HASH> <TXS>
136+
/// `https://mempool.space/api/block/<BLOCK_HASH>/txs`
137+
pub block_txs: Option<String>,
138+
/// - V1 BLOCKS <BLOCK_HEIGHT>
139+
/// `https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT>`
140+
pub blocks: Option<String>,
141+
/// - V1 BLOCKS_BULK <BLOCK_HEIGHT_START> <BLOCK_HEIGHT_STOP>
142+
/// `https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>`
143+
pub blocks_bulk: Option<String>,
103144

104145
/// Configuration file.
105146
pub config: Option<PathBuf>,
@@ -157,8 +198,18 @@ impl Args {
157198
// ADDRESSES
158199
opts.optopt("", "address", "address api call", "ADDRESS");
159200
opts.optopt("", "address_txs", "address_txs api call", "ADDRESS_TXS");
160-
opts.optopt("", "address_txs_chain", "address_txs_chain api call", "ADDRESS_TXS_CHAIN");
161-
opts.optopt("", "address_txs_mempool", "address_txs_mempool api call", "ADDRESS_TXS_MEMPOOL");
201+
opts.optopt(
202+
"",
203+
"address_txs_chain",
204+
"address_txs_chain api call",
205+
"ADDRESS_TXS_CHAIN",
206+
);
207+
opts.optopt(
208+
"",
209+
"address_txs_mempool",
210+
"address_txs_mempool api call",
211+
"ADDRESS_TXS_MEMPOOL",
212+
);
162213
opts.optopt("", "address_utxos", "address_utxos api call", "ADDRESS_UTXOS");
163214
opts.optopt("", "validate_address", "validate an address", "VALIDATE_ADDRESS");
164215

@@ -302,7 +353,52 @@ impl Args {
302353
address_utxos: matches.opt_str("address_utxos"),
303354
validate_address: matches.opt_str("validate_address"),
304355

356+
// BLOCK/S
357+
// https://mempool.space/api/block/<endpoint>
358+
// https://mempool.space/api/block/<block_hash>
359+
// BLOCK
305360
block: matches.opt_str("block"),
361+
// https://mempool.space/api/block/<block_hash>/header
362+
block_header: matches.opt_str("block_header"),
363+
// BLOCK_HEIGHT
364+
// https://mempool.space/api/block-height/615615
365+
block_height: matches.opt_str("block_height"),
366+
367+
// V1 MINING BLOCKS
368+
// https://mempool.space/api/v1/mining/blocks/timestamp/<UTC_SECS>"
369+
block_timestamp: matches.opt_str("block_timestamp"),
370+
371+
// BLOCK
372+
// https://mempool.space/api/block/<block_hash>/raw
373+
block_raw: matches.opt_str("block_raw"),
374+
// https://mempool.space/api/block/<block_hash>/status
375+
block_status: matches.opt_str("block_status"),
376+
377+
// BLOCKS
378+
// BLOCKS TIP HEIGHT
379+
// https://mempool.space/api/blocks/tip/height
380+
blocks_tip_height: matches.opt_str("blocks_tip_height"),
381+
// BLOCKS TIP HASH
382+
// https://mempool.space/api/blocks/tip/hash
383+
blocks_tip_hash: matches.opt_str("blocks_tip_hash"),
384+
385+
// BLOCK
386+
// BLOCK BLOCK_HASH TXID INDEX
387+
// https://mempool.space/api/block/<block_hash>/<txid>/<index>
388+
block_txid: matches.opt_str("block_txid"),
389+
// BLOCK BLOCK_HASH TXIDS
390+
// https://mempool.space/api/block/<block_hash>/<txids>
391+
block_txids: matches.opt_str("block_txids"),
392+
// BLOCK BLOCK_HASH TXS
393+
// https://mempool.space/api/block/<block_hash>/<txs>
394+
block_txs: matches.opt_str("block_txs"),
395+
396+
// V1 BLOCKS
397+
// https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT>"
398+
blocks: matches.opt_str("blocks"),
399+
// V1 BLOCKS_BULK
400+
// https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>"
401+
blocks_bulk: matches.opt_str("blocks_bulk"),
306402

307403
server: matches.opt_str("s"),
308404
auth: matches.opt_str("a"),

src/bin/mempool-space_block_height.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::env;
44
fn main() {
55
{
66
let args: Vec<String> = env::args().collect();
7-
let mut block = &String::from("");
7+
let mut height = &String::from("");
88
if args.len() > 1 {
9-
block = &args[1];
9+
height = &args[1];
1010
} else {
1111
// silence is golden
1212
std::process::exit(0);
1313
}
14-
let _res = blocking(&format!("/block-height/{}", &block));
14+
let _res = blocking(&format!("/block-height/{}", &height));
1515
}
1616
}

src/lib.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,50 @@ mod tests {
265265
fn test_address_txs_utxo() {
266266
// GET /api/address/:address/utxo
267267
let binding = format!("address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY/utxo").clone();
268-
let prices: &str = blocking(&binding).expect("REASON");
268+
let address_utxo: &str = blocking(&binding).expect("existing valid address needed");
269269
wait("1");
270270
}
271271
#[test]
272272
fn test_validate_address() {
273273
// GET /api/v1/validate-address/:address
274274
let binding = format!("v1/validate-address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY").clone();
275-
let prices: &str = blocking(&binding).expect("REASON");
275+
let prices: &str = blocking(&binding).expect("valid address needed");
276276
wait("1");
277277
}
278278

279279
/// Blocks
280+
#[test]
281+
fn test_block() {
282+
// GET /api/block/:hash
283+
let binding = format!("block/000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce").clone();
284+
let block: &str = blocking(&binding).expect("an existing block hash is needed");
285+
let block = generic_sys_call(
286+
"block",
287+
"000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce",
288+
);
289+
wait("1");
290+
}
291+
fn test_block_header() {
292+
// GET /api/block/:hash/header
293+
let binding = format!("block/000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce").clone();
294+
let block_header: &str = blocking(&binding).expect("an existing block hash is needed");
295+
let block = generic_sys_call(
296+
"block_header",
297+
"000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce",
298+
);
299+
wait("1");
300+
}
301+
fn test_block_height() {
302+
// GET /api/block/:block-height/height
303+
let binding = format!("block-height/615615").clone();
304+
let block_height: &str = blocking(&binding).expect("an existing block hash is needed");
305+
let block_height= generic_sys_call(
306+
"block_height",
307+
"615615",
308+
);
309+
wait("1");
310+
}
311+
280312
#[test]
281313
fn test_blockheight() {
282314
let blockheight = blockheight::blockheight();

0 commit comments

Comments
 (0)