pcli/command/view/
transaction_hashes.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
43
44
45
46
47
48
49
50
51
52
use anyhow::Result;
use comfy_table::{presets, Table};
use penumbra_keys::FullViewingKey;
use penumbra_transaction::MemoView;
use penumbra_view::ViewClient;

#[derive(Debug, clap::Args)]
pub struct TransactionHashesCmd {
    #[clap(short, long)]
    pub start_height: Option<u64>,
    #[clap(short, long)]
    pub end_height: Option<u64>,
}

impl TransactionHashesCmd {
    pub fn offline(&self) -> bool {
        false
    }

    pub async fn exec<V: ViewClient>(&self, _fvk: &FullViewingKey, view: &mut V) -> Result<()> {
        // Initialize the table

        let mut table = Table::new();
        table.load_preset(presets::NOTHING);

        let txs = view
            .transaction_info(self.start_height, self.end_height)
            .await?;

        table.set_header(vec!["Height", "Transaction Hash", "Return Address", "Memo"]);

        for tx_info in txs {
            let (return_address, memo) = match tx_info.view.body_view.memo_view {
                Some(MemoView::Visible { plaintext, .. }) => (
                    plaintext.return_address.address().display_short_form(),
                    plaintext.text,
                ),
                _ => (String::new(), String::new()),
            };
            table.add_row(vec![
                format!("{}", tx_info.height),
                format!("{}", hex::encode(tx_info.id)),
                format!("{}", return_address),
                format!("{}", memo),
            ]);
        }

        println!("{table}");

        Ok(())
    }
}