1use anyhow::Result;
2use colored_json::prelude::*;
3use penumbra_sdk_proto::{util::tendermint_proxy::v1::GetTxRequest, DomainType};
4use penumbra_sdk_transaction::Transaction;
5
6use crate::App;
7
8use super::OutputFormat;
9
10#[derive(Debug, clap::Args)]
12pub struct Tx {
13 #[clap(short, long, value_enum, default_value_t)]
15 output: OutputFormat,
16 hash: String,
18}
19
20impl Tx {
21 pub async fn exec(&self, app: &mut App) -> Result<()> {
22 let mut client = app.tendermint_proxy_client().await?;
23
24 let rsp = client
25 .get_tx(GetTxRequest {
26 hash: hex::decode(self.hash.clone())?,
27 prove: false,
28 })
29 .await?;
30
31 let rsp = rsp.into_inner();
32 let tx = Transaction::decode(rsp.tx.as_slice())?;
33
34 match self.output {
35 OutputFormat::Json => {
36 let tx_json = serde_json::to_string_pretty(&tx)?;
37 println!("{}", tx_json.to_colored_json_auto()?);
38 }
39 OutputFormat::Base64 => {
40 use base64::{display::Base64Display, engine::general_purpose::STANDARD};
41 println!("{}", Base64Display::new(&rsp.tx, &STANDARD));
42 }
43 }
44
45 Ok(())
46 }
47}