node: read-only Node::list_payments(friend_pk) for the TUI payment history #78

Merged
sirius merged 1 commit from wt/t_6fb6d365 into feat/wallet-create-import 2026-09-15 19:27:23 +00:00
Owner

Exposes the store's existing payment query to the TUI as one typed read method.

The tui-design payment-history card (t_935bf84e) depends on this method: it is the only way src/tui.rs gets payment rows, and that card is blocked on it landing.

What

pub fn list_payments(&self, friend_pk: &[u8]) -> Result<Vec<crate::store::Payment>, String>

on impl Node, delegating to Store::list_payments. Read-only: no schema change, no migration, no new column, no new frame, no docs/PROTOCOL.md change, and no store handle becomes reachable from the TUI.

  • Returns store::Payment as-is: id, dir, kind, amount_atomic, address, memo, txid (Option), verified, created_at.
  • Error mapping is the same Result<_, String> style as the neighbouring list_messages / wallet_recent_transfers. No new error type.
  • Empty history is Ok(vec![]). An unknown friend is Ok(vec![]) too, not an error.

Test placement (deliberate deviation from the card)

The card asked for the test in tests/pay.rs. That is not possible for a Node method: Node::start / Node::start_with_passphrase are the only public constructors and both bootstrap Tor, ingest_receipt is private, and tests/pay.rs is an integration test against the public API. So the test lives in src/node.rs's existing #[cfg(test)] mod tests, using an unbootstrapped Arti client and a null deliverer over a real encrypted store in a temp dir. It writes the outbound row directly (the shape pay_invoice writes) and drives the inbound row through the node's own ingest_receipt.

TDD evidence

RED first, with the method removed:

error[E0599]: no method named `list_payments` found for struct `node::Node` in the current scope
    --> src/node.rs:1794:25
     |  let rows = node.list_payments(&peer).expect("list_payments");
error[E0599]: no method named `list_payments` found for struct `node::Node` in the current scope
    --> src/node.rs:1814:25
     |  let none = node.list_payments(&[9u8; 32]).expect("unknown friend");

GREEN after adding it:

test node::tests::list_payments_returns_the_friends_rows_and_empty_for_an_unknown_friend ... ok
test result: ok. 36 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The test asserts both rows with dir in in/out, kind, amount_atomic, address, memo, txid and verified matching what was written, plus Ok(vec![]) for an unknown 32-byte pubkey.

Verification

cargo test --locked            -> TEST_EXIT=0, 0 failures (4 network Arti tests ignored)
cargo clippy --locked --all-targets -- -D warnings -> CLIPPY_EXIT=0, clean

Only src/node.rs is touched (124 insertions, 1 deletion). crates/onionwire-sdk is a separate workspace and was neither touched nor rebuilt. No repo-wide cargo fmt: rustfmt --edition 2024 --check src/node.rs reports the same 6 inherited hunks as the base branch, line-shifted only, so the added code is format-clean.

Exposes the store's existing payment query to the TUI as one typed read method. The tui-design payment-history card (t_935bf84e) depends on this method: it is the only way src/tui.rs gets payment rows, and that card is blocked on it landing. ## What pub fn list_payments(&self, friend_pk: &[u8]) -> Result<Vec<crate::store::Payment>, String> on `impl Node`, delegating to `Store::list_payments`. Read-only: no schema change, no migration, no new column, no new frame, no `docs/PROTOCOL.md` change, and no store handle becomes reachable from the TUI. - Returns `store::Payment` as-is: id, dir, kind, amount_atomic, address, memo, txid (Option), verified, created_at. - Error mapping is the same `Result<_, String>` style as the neighbouring `list_messages` / `wallet_recent_transfers`. No new error type. - Empty history is `Ok(vec![])`. An unknown friend is `Ok(vec![])` too, not an error. ## Test placement (deliberate deviation from the card) The card asked for the test in `tests/pay.rs`. That is not possible for a `Node` method: `Node::start` / `Node::start_with_passphrase` are the only public constructors and both bootstrap Tor, `ingest_receipt` is private, and `tests/pay.rs` is an integration test against the public API. So the test lives in `src/node.rs`'s existing `#[cfg(test)] mod tests`, using an unbootstrapped Arti client and a null deliverer over a real encrypted store in a temp dir. It writes the outbound row directly (the shape `pay_invoice` writes) and drives the inbound row through the node's own `ingest_receipt`. ## TDD evidence RED first, with the method removed: error[E0599]: no method named `list_payments` found for struct `node::Node` in the current scope --> src/node.rs:1794:25 | let rows = node.list_payments(&peer).expect("list_payments"); error[E0599]: no method named `list_payments` found for struct `node::Node` in the current scope --> src/node.rs:1814:25 | let none = node.list_payments(&[9u8; 32]).expect("unknown friend"); GREEN after adding it: test node::tests::list_payments_returns_the_friends_rows_and_empty_for_an_unknown_friend ... ok test result: ok. 36 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out The test asserts both rows with dir in in/out, kind, amount_atomic, address, memo, txid and verified matching what was written, plus `Ok(vec![])` for an unknown 32-byte pubkey. ## Verification cargo test --locked -> TEST_EXIT=0, 0 failures (4 network Arti tests ignored) cargo clippy --locked --all-targets -- -D warnings -> CLIPPY_EXIT=0, clean Only `src/node.rs` is touched (124 insertions, 1 deletion). `crates/onionwire-sdk` is a separate workspace and was neither touched nor rebuilt. No repo-wide `cargo fmt`: `rustfmt --edition 2024 --check src/node.rs` reports the same 6 inherited hunks as the base branch, line-shifted only, so the added code is format-clean.
node: read-only Node::list_payments(friend_pk) for the TUI payment history
All checks were successful
ci / test (pull_request) Successful in 4m29s
ci / sdk (pull_request) Successful in 1m19s
fe6465aa6b
Re-exposes the existing Store::list_payments as one typed read method so
src/tui.rs can render a friend's payment history without ever touching the
store. Maps the store error to Result<_, String> exactly like the
neighbouring list_messages / wallet_recent_transfers, and returns
store::Payment as-is (id, dir, kind, amount_atomic, address, memo, txid,
verified, created_at).

Read-only: no schema change, no migration, no new frame, no new column, no
docs/PROTOCOL.md change, and no store handle becomes reachable from the TUI.
An unknown friend is empty history (Ok(vec![])), not an error.

Test placement deviates from the card, deliberately: it lives in
src/node.rs's #[cfg(test)] mod tests instead of tests/pay.rs, because Node
has no constructor that avoids Tor (Node::start* is the only public one) and
ingest_receipt is private, so tests/pay.rs cannot build a Node at all. The
test uses an unbootstrapped Arti client plus a null deliverer over a real
encrypted store in a temp dir, writes the outbound row directly and drives
the inbound row through the node's own ingest_receipt.
sirius merged commit b20313e65d into feat/wallet-create-import 2026-09-15 19:27:23 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!78
No description provided.