diff --git a/CHANGELOG.md b/CHANGELOG.md index d477c1e9..cb4e2aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/Cargo.lock b/Cargo.lock index 29bd4886..1bc7186a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,7 +335,6 @@ dependencies = [ "bitcoin-payment-instructions", "clap", "clap_complete", - "cli-table", "dirs", "env_logger", "log", @@ -1088,29 +1087,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" -[[package]] -name = "cli-table" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14da8d951cef7cc4f13ccc9b744d736963d57863c7e6fc33c070ea274546082c" -dependencies = [ - "cli-table-derive", - "csv", - "termcolor", - "unicode-width", -] - -[[package]] -name = "cli-table-derive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7c1b60bae2c3d45228dfb096046aa51ef6c300de70b658d7a13fcb0c4f832e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.118", -] - [[package]] name = "cmake" version = "0.1.58" @@ -1310,27 +1286,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "csv" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52cd9d68cf7efc6ddfaaee42e7288d3a99d613d4b50f76ce9827ae0c6e14f938" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde_core", -] - -[[package]] -name = "csv-core" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782" -dependencies = [ - "memchr", -] - [[package]] name = "ctr" version = "0.7.0" @@ -4213,15 +4168,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "termtree" version = "0.5.1" @@ -4570,12 +4516,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" - [[package]] name = "universal-hash" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 9319864d..827d0f1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,9 +21,6 @@ log = "0.4" serde_json = "1.0" thiserror = "2.0.18" tokio = { version = "1", features = ["full"] } -cli-table = "0.5.0" -tracing = "0.1.44" -tracing-subscriber = "0.3.20" toml = "1.1.0" serde= {version = "1.0", features = ["derive"]} @@ -34,6 +31,8 @@ bdk_esplora = { version = "0.22.2", default-features = false, features = ["async bdk_kyoto = { version = "0.17.0", optional = true } bdk_redb = { version = "0.2.0", optional = true } bdk_sp = { version = "0.2.0", optional = true } +tracing = { version = "0.1.44", optional = true } +tracing-subscriber = { version = "0.3.20", optional = true } shlex = { version = "1.3.0", optional = true } payjoin = { version = "0.25.0", features = ["v1", "v2", "io", "_test-utils"], optional = true} reqwest = { version = "0.13.2", default-features = false, features = ["rustls"], optional = true } @@ -53,14 +52,14 @@ sqlite = ["bdk_wallet/rusqlite"] redb = ["bdk_redb"] # Available blockchain client options -cbf = ["bdk_kyoto", "_payjoin-dependencies"] +cbf = ["bdk_kyoto", "tracing", "tracing-subscriber", "_payjoin-dependencies"] electrum = ["bdk_electrum", "_payjoin-dependencies"] esplora = ["bdk_esplora", "_payjoin-dependencies"] rpc = ["bdk_bitcoind_rpc", "_payjoin-dependencies"] dns_payment = ["bitcoin-payment-instructions"] # Internal features -_payjoin-dependencies = ["payjoin", "reqwest", "url", "sqlite"] +_payjoin-dependencies = ["payjoin", "reqwest", "url", "sqlite", "tracing"] message_signer = ["bdk_message_signer"] # Use this to consensus verify transactions at sync time diff --git a/src/handlers/payjoin/db.rs b/src/handlers/payjoin/db.rs index f28ffc48..f0e57bb1 100644 --- a/src/handlers/payjoin/db.rs +++ b/src/handlers/payjoin/db.rs @@ -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); diff --git a/src/handlers/payjoin/mod.rs b/src/handlers/payjoin/mod.rs index c78fa0af..43516214 100644 --- a/src/handlers/payjoin/mod.rs +++ b/src/handlers/payjoin/mod.rs @@ -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> = 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 })?) } }