ord/subcommand/index/
info.rs1use super::*;
2
3#[derive(Debug, Parser)]
4pub(crate) struct Info {
5 #[arg(long)]
6 transactions: bool,
7}
8
9#[derive(Serialize, Deserialize)]
10pub struct TransactionsOutput {
11 pub start: u32,
12 pub end: u32,
13 pub count: u32,
14 pub elapsed: f64,
15}
16
17impl Info {
18 pub(crate) fn run(self, settings: Settings) -> SubcommandResult {
19 let index = Index::open(&settings)?;
20
21 index.update()?;
22
23 let info = index.info()?;
24
25 if self.transactions {
26 let mut output = Vec::new();
27 for window in info.transactions.windows(2) {
28 let start = &window[0];
29 let end = &window[1];
30 output.push(TransactionsOutput {
31 start: start.starting_block_count,
32 end: end.starting_block_count,
33 count: end.starting_block_count - start.starting_block_count,
34 elapsed: (end.starting_timestamp - start.starting_timestamp) as f64 / 1000.0 / 60.0,
35 });
36 }
37 Ok(Some(Box::new(output)))
38 } else {
39 Ok(Some(Box::new(info)))
40 }
41 }
42}