Skip to content

Commit 9755c36

Browse files
authored
Merge pull request #111 from nuttycom/feature/list_tx_configure_acct
command (list_tx): Add CLI argument for account filtering.
2 parents f970907 + 692e619 commit 9755c36

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/commands/wallet/list_tx.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use crate::{data::get_db_paths, ui::format_zec};
1414

1515
// Options accepted for the `list-tx` command
1616
#[derive(Debug, Args)]
17-
pub(crate) struct Command {}
17+
pub(crate) struct Command {
18+
/// The UUID of the account for which to get the list of transactions. If omitted, transactions
19+
/// transactions from all accounts will be returned.
20+
account_id: Option<Uuid>,
21+
}
1822

1923
impl Command {
2024
pub(crate) fn run(self, wallet_dir: Option<String>) -> anyhow::Result<()> {
@@ -23,16 +27,6 @@ impl Command {
2327
let conn = Connection::open(db_data)?;
2428
rusqlite::vtab::array::load_module(&conn)?;
2529

26-
// Show the first account in the database.
27-
let account_uuid = conn.query_row(
28-
"SELECT uuid
29-
FROM accounts
30-
ORDER BY id
31-
LIMIT 1",
32-
named_params! {},
33-
|row| row.get::<_, Uuid>(0),
34-
)?;
35-
3630
let mut stmt_txs = conn.prepare(
3731
"SELECT mined_height,
3832
txid,
@@ -55,12 +49,8 @@ impl Command {
5549
-- in history). We represent this with NULL.
5650
) AS sort_height
5751
FROM v_transactions
58-
WHERE account_uuid = :account_uuid
59-
ORDER BY
60-
-- By default, integer ordering places NULL before all values. Flip this
61-
-- around so that transactions in the mempool are shown as most recent.
62-
CASE WHEN sort_height IS NULL THEN 1 ELSE 0 END,
63-
sort_height",
52+
WHERE (:account_uuid IS NULL OR account_uuid = :account_uuid)
53+
ORDER BY sort_height ASC NULLS LAST",
6454
)?;
6555

6656
let mut stmt_outputs = conn.prepare(
@@ -79,7 +69,7 @@ impl Command {
7969

8070
println!("Transactions:");
8171
for row in stmt_txs.query_and_then(
82-
named_params! {":account_uuid": account_uuid},
72+
named_params! {":account_uuid": self.account_id },
8373
|row| -> anyhow::Result<_> {
8474
let txid = row.get::<_, Vec<u8>>(1)?;
8575

0 commit comments

Comments
 (0)