Add option to limit number of TXs shown (#660)

Co-authored-by: cliik <cliik@example.com>
This commit is contained in:
cliik 2022-07-26 09:16:47 +00:00 committed by GitHub
parent ef3fadbd24
commit a3687c69a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -1106,6 +1106,7 @@ where
pub struct TxsArgs { pub struct TxsArgs {
pub id: Option<u32>, pub id: Option<u32>,
pub tx_slate_id: Option<Uuid>, pub tx_slate_id: Option<Uuid>,
pub count: Option<u32>,
} }
pub fn txs<L, C, K>( pub fn txs<L, C, K>(
@ -1125,11 +1126,15 @@ where
let res = api.node_height(m)?; let res = api.node_height(m)?;
let (validated, txs) = api.retrieve_txs(m, true, args.id, args.tx_slate_id)?; let (validated, txs) = api.retrieve_txs(m, true, args.id, args.tx_slate_id)?;
let include_status = !args.id.is_some() && !args.tx_slate_id.is_some(); let include_status = !args.id.is_some() && !args.tx_slate_id.is_some();
// If view count is specified, restrict the TX list to `txs.len() - count`
let first_tx = args
.count
.map_or(0, |c| txs.len().saturating_sub(c as usize));
display::txs( display::txs(
&g_args.account, &g_args.account,
res.height, res.height,
validated || updater_running, validated || updater_running,
&txs, &txs[first_tx..],
include_status, include_status,
dark_scheme, dark_scheme,
)?; )?;

View file

@ -333,6 +333,11 @@ subcommands:
short: t short: t
long: txid long: txid
takes_value: true takes_value: true
- count:
help: Maximum number of transactions to show
short: c
long: count
takes_value: true
- post: - post:
about: Posts a finalized transaction to the chain about: Posts a finalized transaction to the chain
args: args:

View file

@ -840,9 +840,14 @@ pub fn parse_txs_args(args: &ArgMatches) -> Result<command::TxsArgs, ParseError>
let msg = format!("At most one of 'id' (-i) or 'txid' (-t) may be provided."); let msg = format!("At most one of 'id' (-i) or 'txid' (-t) may be provided.");
return Err(ParseError::ArgumentError(msg)); return Err(ParseError::ArgumentError(msg));
} }
let count = match args.value_of("count") {
None => None,
Some(c) => Some(parse_u64(c, "count")? as u32),
};
Ok(command::TxsArgs { Ok(command::TxsArgs {
id: tx_id, id: tx_id,
tx_slate_id: tx_slate_id, tx_slate_id: tx_slate_id,
count: count,
}) })
} }