use anyhow::{Context, Result};
use penumbra_proto::{util::tendermint_proxy::v1::GetTxRequest, DomainType};
use penumbra_transaction::Transaction;
use penumbra_view::{TransactionInfo, ViewClient};
use crate::App;
#[derive(Debug, clap::Args)]
pub struct TxCmd {
hash: String,
#[clap(long)]
raw: bool,
}
impl TxCmd {
pub fn offline(&self) -> bool {
false
}
pub async fn exec(&self, app: &mut App) -> Result<()> {
let hash = self
.hash
.to_uppercase()
.parse()
.context("invalid transaction hash")?;
let tx_info = if let Ok(tx_info) = app.view().transaction_info_by_hash(hash).await {
tx_info
} else {
if !self.raw {
println!("Transaction not found in view service, fetching from fullnode...");
} else {
tracing::info!("Transaction not found in view service, fetching from fullnode...");
}
let mut client = app.tendermint_proxy_client().await?;
let rsp = client
.get_tx(GetTxRequest {
hash: hex::decode(self.hash.clone())?,
prove: false,
})
.await?;
let rsp = rsp.into_inner();
let tx = Transaction::decode(rsp.tx.as_slice())?;
let txp = Default::default();
let txv = tx.view_from_perspective(&txp);
TransactionInfo {
height: rsp.height,
id: hash,
transaction: tx,
perspective: txp,
view: txv,
}
};
if self.raw {
use colored_json::prelude::*;
println!(
"{}",
serde_json::to_string_pretty(&tx_info.view)?.to_colored_json_auto()?
);
} else {
use crate::transaction_view_ext::TransactionViewExt;
tx_info.view.render_terminal();
}
Ok(())
}
}