Merge branch 'master' into master
This commit is contained in:
@@ -433,6 +433,20 @@ pub fn outputs(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn payments(
|
||||
wallet: Arc<Mutex<WalletInst<impl NodeClient + 'static, keychain::ExtKeychain>>>,
|
||||
g_args: &GlobalArgs,
|
||||
dark_scheme: bool,
|
||||
) -> Result<(), Error> {
|
||||
controller::owner_single_use(wallet.clone(), |api| {
|
||||
let res = api.node_height()?;
|
||||
let (validated, outputs) = api.retrieve_payments(true, None)?;
|
||||
display::payments(&g_args.account, res.height, validated, outputs, dark_scheme)?;
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Txs command args
|
||||
pub struct TxsArgs {
|
||||
pub id: Option<u32>,
|
||||
@@ -462,8 +476,22 @@ pub fn txs(
|
||||
let (_, outputs) = api.retrieve_outputs(true, false, args.id)?;
|
||||
display::outputs(&g_args.account, res.height, validated, outputs, dark_scheme)?;
|
||||
// should only be one here, but just in case
|
||||
for tx in txs {
|
||||
display::tx_messages(&tx, dark_scheme)?;
|
||||
for tx in &txs {
|
||||
let (_, outputs) = api.retrieve_payments(true, tx.tx_slate_id)?;
|
||||
if outputs.len() > 0 {
|
||||
display::payments(
|
||||
&g_args.account,
|
||||
res.height,
|
||||
validated,
|
||||
outputs,
|
||||
dark_scheme,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// should only be one here, but just in case
|
||||
for tx in &txs {
|
||||
display::tx_messages(tx, dark_scheme)?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
|
||||
use crate::core::core::{self, amount_to_hr_string};
|
||||
use crate::core::global;
|
||||
use crate::libwallet::{
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, TxLogEntry, WalletInfo,
|
||||
|
||||
use crate::libwallet::types::{
|
||||
AcctPathMapping, Error, OutputCommitMapping, OutputStatus, PaymentCommitMapping, TxLogEntry,
|
||||
WalletInfo,
|
||||
};
|
||||
use crate::util;
|
||||
use prettytable;
|
||||
@@ -118,6 +120,89 @@ pub fn outputs(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Display payments in a pretty way
|
||||
pub fn payments(
|
||||
account: &str,
|
||||
cur_height: u64,
|
||||
validated: bool,
|
||||
outputs: Vec<PaymentCommitMapping>,
|
||||
dark_background_color_scheme: bool,
|
||||
) -> Result<(), Error> {
|
||||
let title = format!(
|
||||
"Wallet Payments - Account '{}' - Block Height: {}",
|
||||
account, cur_height
|
||||
);
|
||||
println!();
|
||||
let mut t = term::stdout().unwrap();
|
||||
t.fg(term::color::MAGENTA).unwrap();
|
||||
writeln!(t, "{}", title).unwrap();
|
||||
t.reset().unwrap();
|
||||
|
||||
let mut table = table!();
|
||||
|
||||
table.set_titles(row![
|
||||
bMG->"Output Commitment",
|
||||
bMG->"Block Height",
|
||||
bMG->"Locked Until",
|
||||
bMG->"Status",
|
||||
bMG->"# Confirms",
|
||||
bMG->"Value",
|
||||
bMG->"Shared Transaction Id"
|
||||
]);
|
||||
|
||||
for payment in outputs {
|
||||
let commit = format!("{}", util::to_hex(payment.commit.as_ref().to_vec()));
|
||||
let out = payment.output;
|
||||
|
||||
let height = format!("{}", out.height);
|
||||
let lock_height = format!("{}", out.lock_height);
|
||||
let status = format!("{}", out.status);
|
||||
|
||||
let num_confirmations = format!("{}", out.num_confirmations(cur_height));
|
||||
let value = if out.value == 0 {
|
||||
"unknown".to_owned()
|
||||
} else {
|
||||
format!("{}", core::amount_to_hr_string(out.value, false))
|
||||
};
|
||||
let slate_id = format!("{}", out.slate_id);
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFC->commit,
|
||||
bFB->height,
|
||||
bFB->lock_height,
|
||||
bFR->status,
|
||||
bFB->num_confirmations,
|
||||
bFG->value,
|
||||
bFC->slate_id,
|
||||
]);
|
||||
} else {
|
||||
table.add_row(row![
|
||||
bFD->commit,
|
||||
bFB->height,
|
||||
bFB->lock_height,
|
||||
bFR->status,
|
||||
bFB->num_confirmations,
|
||||
bFG->value,
|
||||
bFD->slate_id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_COLSEP);
|
||||
table.printstd();
|
||||
println!();
|
||||
|
||||
if !validated {
|
||||
println!(
|
||||
"\nWARNING: Wallet failed to verify data. \
|
||||
The above is from local cache and possibly invalid! \
|
||||
(is your `grin server` offline or broken?)"
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Display transaction log in a pretty way
|
||||
pub fn txs(
|
||||
account: &str,
|
||||
|
||||
Reference in New Issue
Block a user