]> Untitled Git - bdk-cli/commitdiff
refactor(payjoin): return session history as JSON
authorVadim Anufriev <m@vaan.io>
Fri, 13 Nov 2026 15:26:55 +0000 (19:26 +0400)
committerVadim Anufriev <m@vaan.io>
Fri, 13 Nov 2026 19:46:35 +0000 (23:46 +0400)
The last cli-table user, dead weight since --pretty was dropped in #278.

CHANGELOG.md
src/handlers/payjoin/db.rs
src/handlers/payjoin/mod.rs

index d477c1e9e2284ab3b1e9f890d2c3dc27b71156d4..cb4e2aaaa2b403c76a4c6d9fa4a52381b08ac9fb 100644 (file)
@@ -24,6 +24,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details.
 - Fixed `key restore` ignoring `--password`, which restored passphrase-protected mnemonics to the wrong key
 - Fixed `key generate` silently producing a 24-word mnemonic for any `--entropy` value other than 12; values other than 12 and 24 are now rejected
 - Gated `full_scan`'s `--scan-stop-gap` to the Electrum and Esplora backends that use it; RPC and CBF wallets now reject the flag instead of silently ignoring it, while a `STOP_GAP` environment variable keeps working for supported backends and no longer breaks unsupported ones
+- Changed `payjoin history` to return JSON instead of a rendered table
 
 ## [4.0.0]
 
index f28ffc48b3236388d1075f58915f9fe15a0b89e0..f0e57bb1a73142d0036d973a4d237336859053e5 100644 (file)
@@ -823,7 +823,7 @@ mod tests {
         assert!(table.contains(&active_recv_ids[0].to_string()));
         assert!(table.contains(&inactive_send_ids[0].0.to_string()));
         assert!(table.contains(&inactive_recv_ids[0].0.to_string()));
-        assert!(table.contains("Not Completed"));
+        assert!(table.contains("\"completed_at\": null"));
 
         drop(active_sender);
         drop(active_receiver);
index c78fa0af121637cc9483306ce078ef1a9b185e63..435162145798592b42d1dbd28236c7078c34c7c2 100644 (file)
@@ -4,7 +4,6 @@ use bdk_wallet::{
     SignOptions, Wallet,
     bitcoin::{FeeRate, Psbt, Txid, consensus::encode::serialize_hex},
 };
-use cli_table::{Cell, CellStruct, Style, Table};
 use payjoin::bitcoin::TxIn;
 use payjoin::persist::{OptionalTransitionOutcome, SessionPersister};
 use payjoin::receive::InputPair;
@@ -21,6 +20,7 @@ use payjoin::send::v2::{
     replay_event_log as replay_sender_event_log,
 };
 use payjoin::{HpkePublicKey, ImplementationError, UriExt};
+use serde::Serialize;
 use serde_json::{json, to_string_pretty};
 use std::{path::PathBuf, sync::Arc};
 
@@ -92,6 +92,12 @@ impl StatusText for ReceiveSession {
     }
 }
 
+#[derive(Serialize)]
+struct SessionHistory<'a> {
+    sessions: Vec<&'a SessionHistoryRow>,
+}
+
+#[derive(Serialize)]
 struct SessionHistoryRow {
     id: String,
     role: &'static str,
@@ -1050,33 +1056,8 @@ impl<'a> PayjoinManager<'a> {
             });
         }
 
-        let rows: Vec<Vec<CellStruct>> = send_rows
-            .iter()
-            .chain(recv_rows.iter())
-            .map(|row| {
-                vec![
-                    row.id.as_str().cell(),
-                    row.role.cell(),
-                    row.completed_at
-                        .clone()
-                        .unwrap_or_else(|| "Not Completed".to_string())
-                        .cell(),
-                    row.status.as_str().cell(),
-                ]
-            })
-            .collect();
+        let sessions: Vec<&SessionHistoryRow> = send_rows.iter().chain(recv_rows.iter()).collect();
 
-        let table = rows
-            .table()
-            .title(vec![
-                "Session ID".cell().bold(true),
-                "Sender/Receiver".cell().bold(true),
-                "Completed At".cell().bold(true),
-                "Status".cell().bold(true),
-            ])
-            .display()
-            .map_err(|e| Error::Generic(e.to_string()))?;
-
-        Ok(format!("{table}"))
+        Ok(to_string_pretty(&SessionHistory { sessions })?)
     }
 }