forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.rs
42 lines (37 loc) Β· 985 Bytes
/
info.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::*;
#[derive(Debug, Parser)]
pub(crate) struct Info {
#[clap(long)]
transactions: bool,
}
#[derive(Serialize, Deserialize)]
pub struct TransactionsOutput {
pub start: u64,
pub end: u64,
pub count: u64,
pub elapsed: f64,
}
impl Info {
pub(crate) fn run(self, options: Options) -> Result {
let index = Index::open(&options)?;
index.update()?;
let info = index.info()?;
if self.transactions {
let mut output = Vec::new();
for window in info.transactions.windows(2) {
let start = &window[0];
let end = &window[1];
output.push(TransactionsOutput {
start: start.starting_block_count,
end: end.starting_block_count,
count: end.starting_block_count - start.starting_block_count,
elapsed: (end.starting_timestamp - start.starting_timestamp) as f64 / 1000.0 / 60.0,
});
}
print_json(output)?;
} else {
print_json(info)?;
}
Ok(())
}
}