diff --git a/controller/src/display.rs b/controller/src/display.rs index 44e598f..99af9ea 100644 --- a/controller/src/display.rs +++ b/controller/src/display.rs @@ -17,9 +17,10 @@ use crate::core::core::FeeFields; use crate::core::global; use crate::libwallet::{ address, AcctPathMapping, Error, OutputCommitMapping, OutputStatus, SlatepackAddress, - TxLogEntry, ViewWallet, WalletInfo, + TxLogEntry, TxLogEntryType, ViewWallet, WalletInfo, }; use crate::util::ToHex; + use prettytable; use prettytable::format::{FormatBuilder, LinePosition, LineSeparator}; use std::io::prelude::Write; @@ -150,47 +151,68 @@ pub fn txs( let mut table = table!(); - table.set_titles(row![ - bMG->"Id", - bMG->"Type", - bMG->"State", - bMG->"Shared Transaction Id", - bMG->"Creation Time", - bMG->"TTL Cutoff Height", - bMG->"Confirmed?", - bMG->"Confirmation Time", - bMG->"Num. \nInputs", - bMG->"Num. \nOutputs", - bMG->"Amount \nCredited", - bMG->"Amount \nDebited", - bMG->"Fee", - bMG->"Net \nDifference", - bMG->"Payment \nProof", - bMG->"Kernel", - bMG->"Tx \nData", - ]); + table.set_titles(if dark_background_color_scheme { + row![ + bMG->"Id", + bMG->"Type (State)", + bMG->"Shared Transaction Id \nKernel", + bMG->"Creation Time \nConfirmation Time", + bMG->"Payment Proof \nTTL Cutoff Height", + bMG->"Inputs \nOutputs", + bMG->"Credited \nDebited", + bMG->"Fee \nDifference", + ] + } else { + row![ + bFD ->"Id", + bFD->"Type (State)", + bFD->"Shared Transaction Id \nKernel", + bFD->"Creation Time \nConfirmation Time", + bFD->"Payment Proof \nTTL Cutoff Height", + bFD->"Inputs \nOutputs", + bFD->"Credited \nDebited", + bFD->"Fee \nDifference", + ] + }); - for t in txs { + for (i, t) in txs.iter().enumerate() { let id = format!("{}", t.id); let slate_id = match t.tx_slate_id { Some(m) => format!("{}", m), None => "None".to_owned(), }; - let slate_state = match t.tx_slate_state.as_ref() { - Some(m) => format!("{}", m), - None => "None".to_owned(), + + let entry_type = (match t.tx_type { + TxLogEntryType::ConfirmedCoinbase => "Coinbase", + TxLogEntryType::TxReceived => "Received Tx", + TxLogEntryType::TxSent => "Sent Tx", + TxLogEntryType::TxReceivedCancelled => "Received Tx", + TxLogEntryType::TxSentCancelled => "Sent Tx", + TxLogEntryType::TxReverted => "Received Tx", + }) + .to_string(); + let entry_type_state = match t.tx_slate_state.as_ref() { + None => entry_type.to_string(), + Some(s) => format!("{} ({})", entry_type, s), }; - let entry_type = format!("{}", t.tx_type); + let entry_type_desc = (match t.tx_type { + TxLogEntryType::ConfirmedCoinbase => "Confirmed", + TxLogEntryType::TxReceived => "", + TxLogEntryType::TxSent => "", + TxLogEntryType::TxReceivedCancelled => "Cancelled", + TxLogEntryType::TxSentCancelled => "Cancelled", + TxLogEntryType::TxReverted => "Reverted", + }) + .to_string(); let creation_ts = format!("{}", t.creation_ts.format("%Y-%m-%d %H:%M:%S")); let ttl_cutoff_height = match t.ttl_cutoff_height { - Some(b) => format!("{}", b), + Some(b) => b.to_string(), None => "None".to_owned(), }; let confirmation_ts = match t.confirmation_ts { Some(m) => format!("{}", m.format("%Y-%m-%d %H:%M:%S")), None => "None".to_owned(), }; - let confirmed = format!("{}", t.confirmed); let num_inputs = format!("{}", t.num_inputs); let num_outputs = format!("{}", t.num_outputs); let amount_debited_str = amount_to_hr_string(t.amount_debited, true); @@ -207,10 +229,6 @@ pub fn txs( amount_to_hr_string(t.amount_debited - t.amount_credited, true) ) }; - let tx_data = match t.stored_tx { - Some(_) => "Yes".to_owned(), - None => "None".to_owned(), - }; let kernel_excess = match t.kernel_excess { Some(e) => { let excess: &[u8] = e.0.as_ref(); @@ -225,65 +243,52 @@ pub fn txs( if dark_background_color_scheme { table.add_row(row![ bFC->id, - bFC->entry_type, - bFC->slate_state, + bFC->entry_type_state, bFC->slate_id, bFB->creation_ts, - bFB->ttl_cutoff_height, - bFC->confirmed, - bFB->confirmation_ts, + bFC->payment_proof, bFC->num_inputs, - bFC->num_outputs, bFG->amount_credited_str, - bFR->amount_debited_str, bFR->fee, - bFY->net_diff, - bfG->payment_proof, + ]); + table.add_row(row![ + bFD->"", + bFC->entry_type_desc, bFB->kernel_excess, - bFb->tx_data, + bFB->confirmation_ts, + bFB->ttl_cutoff_height, + bFC->num_outputs, + bFR->amount_debited_str, + bFY->net_diff, ]); } else { - if t.confirmed { - table.add_row(row![ - bFD->id, - bFb->entry_type, - bFD->slate_id, - bFB->creation_ts, - bFg->confirmed, - bFB->confirmation_ts, - bFD->num_inputs, - bFD->num_outputs, - bFG->amount_credited_str, - bFD->amount_debited_str, - bFD->fee, - bFG->net_diff, - bfG->payment_proof, - bFB->kernel_excess, - bFB->tx_data, - ]); - } else { - table.add_row(row![ - bFD->id, - bFb->entry_type, - bFD->slate_id, - bFB->creation_ts, - bFR->confirmed, - bFB->confirmation_ts, - bFD->num_inputs, - bFD->num_outputs, - bFG->amount_credited_str, - bFD->amount_debited_str, - bFD->fee, - bFG->net_diff, - bfG->payment_proof, - bFB->kernel_excess, - bFB->tx_data, - ]); - } + table.add_row(row![ + bFD->id, + bFb->entry_type_state, + bFD->slate_id, + bFB->creation_ts, + bFD->payment_proof, + bFD->num_inputs, + bFG->amount_credited_str, + bFR->fee, + ]); + table.add_row(row![ + bFD->"", + bFb->entry_type_desc, + bFB->kernel_excess, + bFB->confirmation_ts, + bFB->ttl_cutoff_height, + bFD->num_outputs, + bFR->amount_debited_str, + bFG->net_diff, + ]); + } + if i != txs.len() - 1 { + table.add_empty_row(); } } - table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP); + table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); table.printstd(); println!(); diff --git a/libwallet/src/types.rs b/libwallet/src/types.rs index e7e3f69..ae96d6b 100644 --- a/libwallet/src/types.rs +++ b/libwallet/src/types.rs @@ -608,12 +608,12 @@ pub enum TxLogEntryType { impl fmt::Display for TxLogEntryType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - TxLogEntryType::ConfirmedCoinbase => write!(f, "Confirmed \nCoinbase"), + TxLogEntryType::ConfirmedCoinbase => write!(f, "Confirmed Coinbase"), TxLogEntryType::TxReceived => write!(f, "Received Tx"), TxLogEntryType::TxSent => write!(f, "Sent Tx"), - TxLogEntryType::TxReceivedCancelled => write!(f, "Received Tx\n- Cancelled"), - TxLogEntryType::TxSentCancelled => write!(f, "Sent Tx\n- Cancelled"), - TxLogEntryType::TxReverted => write!(f, "Received Tx\n- Reverted"), + TxLogEntryType::TxReceivedCancelled => write!(f, "Received Tx - Cancelled"), + TxLogEntryType::TxSentCancelled => write!(f, "Sent Tx - Cancelled"), + TxLogEntryType::TxReverted => write!(f, "Received Tx - Reverted"), } } }