@@ -14,7 +14,11 @@ use crate::{data::get_db_paths, ui::format_zec};
14
14
15
15
// Options accepted for the `list-tx` command
16
16
#[ 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
+ }
18
22
19
23
impl Command {
20
24
pub ( crate ) fn run ( self , wallet_dir : Option < String > ) -> anyhow:: Result < ( ) > {
@@ -23,16 +27,6 @@ impl Command {
23
27
let conn = Connection :: open ( db_data) ?;
24
28
rusqlite:: vtab:: array:: load_module ( & conn) ?;
25
29
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
-
36
30
let mut stmt_txs = conn. prepare (
37
31
"SELECT mined_height,
38
32
txid,
@@ -55,12 +49,8 @@ impl Command {
55
49
-- in history). We represent this with NULL.
56
50
) AS sort_height
57
51
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" ,
64
54
) ?;
65
55
66
56
let mut stmt_outputs = conn. prepare (
@@ -79,7 +69,7 @@ impl Command {
79
69
80
70
println ! ( "Transactions:" ) ;
81
71
for row in stmt_txs. query_and_then (
82
- named_params ! { ":account_uuid" : account_uuid } ,
72
+ named_params ! { ":account_uuid" : self . account_id } ,
83
73
|row| -> anyhow:: Result < _ > {
84
74
let txid = row. get :: < _ , Vec < u8 > > ( 1 ) ?;
85
75
0 commit comments