pcli/command/view/
transaction_hashes.rs

1use anyhow::Result;
2use comfy_table::{presets, Table};
3use penumbra_sdk_keys::FullViewingKey;
4use penumbra_sdk_transaction::MemoView;
5use penumbra_sdk_view::ViewClient;
6
7#[derive(Debug, clap::Args)]
8pub struct TransactionHashesCmd {
9    #[clap(short, long)]
10    pub start_height: Option<u64>,
11    #[clap(short, long)]
12    pub end_height: Option<u64>,
13}
14
15impl TransactionHashesCmd {
16    pub fn offline(&self) -> bool {
17        false
18    }
19
20    pub async fn exec<V: ViewClient>(&self, _fvk: &FullViewingKey, view: &mut V) -> Result<()> {
21        // Initialize the table
22
23        let mut table = Table::new();
24        table.load_preset(presets::NOTHING);
25
26        let txs = view
27            .transaction_info(self.start_height, self.end_height)
28            .await?;
29
30        table.set_header(vec!["Height", "Transaction Hash", "Return Address", "Memo"]);
31
32        for tx_info in txs {
33            let (return_address, memo) = match tx_info.view.body_view.memo_view {
34                Some(MemoView::Visible { plaintext, .. }) => (
35                    plaintext.return_address.address().display_short_form(),
36                    plaintext.text,
37                ),
38                _ => (String::new(), String::new()),
39            };
40            table.add_row(vec![
41                format!("{}", tx_info.height),
42                format!("{}", hex::encode(tx_info.id)),
43                format!("{}", return_address),
44                format!("{}", memo),
45            ]);
46        }
47
48        println!("{table}");
49
50        Ok(())
51    }
52}