Merge remote-tracking branch 'origin/onionwire/t_21787cec-node-expose-peer-payment-history-node-li' into onionwire/t_ef1d35d2-tui-payments-row-on-f9-render-peer-payme
This commit is contained in:
commit
b1a6796742
1 changed files with 82 additions and 1 deletions
83
src/node.rs
83
src/node.rs
|
|
@ -28,7 +28,7 @@ use crate::ratchet::{RatchetKeyPair, RatchetState};
|
||||||
use crate::ratelimit::TokenBucket;
|
use crate::ratelimit::TokenBucket;
|
||||||
use crate::sanitize;
|
use crate::sanitize;
|
||||||
use crate::session::{self, Keys};
|
use crate::session::{self, Keys};
|
||||||
use crate::store::{Friend, FriendProfile, Message, PaymentWrite, Store};
|
use crate::store::{Friend, FriendProfile, Message, Payment, PaymentWrite, Store};
|
||||||
use crate::wallet::{self, Readiness, Wallet, WalletConfig, WalletStatus};
|
use crate::wallet::{self, Readiness, Wallet, WalletConfig, WalletStatus};
|
||||||
use crate::wallet_child::{ChildConfig, WalletChild, WalletChildState, WalletChildStatus};
|
use crate::wallet_child::{ChildConfig, WalletChild, WalletChildState, WalletChildStatus};
|
||||||
|
|
||||||
|
|
@ -500,6 +500,23 @@ impl Node {
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The signed `/pay` invoices and `/tip` receipts that came from one peer,
|
||||||
|
/// oldest row first. A friend with no payment rows is an empty vector, not
|
||||||
|
/// an error.
|
||||||
|
///
|
||||||
|
/// Read-only and fail-closed: it locks the store and nothing else — no Tor
|
||||||
|
/// dial, no wallet RPC. `memo` is the text the peer signed, stored and
|
||||||
|
/// returned as it arrived; a renderer sanitizes it with
|
||||||
|
/// [`crate::sanitize::display_text`] at draw time, exactly as the chat
|
||||||
|
/// bodies from [`Self::list_messages`] are.
|
||||||
|
pub fn list_payments(&self, friend_pk: &[u8]) -> Result<Vec<Payment>, String> {
|
||||||
|
self.store
|
||||||
|
.lock()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.list_payments(friend_pk)
|
||||||
|
.map_err(|e| e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
/// The live wallet, cloned out of its lock. Every wallet call goes through
|
/// The live wallet, cloned out of its lock. Every wallet call goes through
|
||||||
/// this so a `std::sync::Mutex` guard never lives across an `.await`, and so
|
/// this so a `std::sync::Mutex` guard never lives across an `.await`, and so
|
||||||
/// the F7 screen can re-point the wallet mid-session.
|
/// the F7 screen can re-point the wallet mid-session.
|
||||||
|
|
@ -2314,6 +2331,70 @@ mod tests {
|
||||||
assert_eq!(rows[0].kind, "tip");
|
assert_eq!(rows[0].kind, "tip");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The peer payment history the TUI needs: `Store::list_payments` existed but
|
||||||
|
/// nothing on `Node` reached it, so the signed invoice/receipt frames a peer
|
||||||
|
/// sent were invisible to the app. One row per stored frame, oldest first,
|
||||||
|
/// and a friend with no rows is an empty vector, not an error.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn list_payments_round_trips_a_peers_invoice_and_receipt() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let node = offline_node(&dir.path().join("bob"), Arc::new(NoDial));
|
||||||
|
let peer = Keys::generate();
|
||||||
|
let stranger = Keys::generate();
|
||||||
|
let addr = xmr_addr();
|
||||||
|
befriend(
|
||||||
|
&node.store.lock().unwrap(),
|
||||||
|
&peer.identity_pk,
|
||||||
|
&peer.prekey_pk,
|
||||||
|
"peer.onion",
|
||||||
|
);
|
||||||
|
{
|
||||||
|
let store = node.store.lock().unwrap();
|
||||||
|
store
|
||||||
|
.insert_payment(
|
||||||
|
&peer.identity_pk,
|
||||||
|
PaymentWrite {
|
||||||
|
dir: "in",
|
||||||
|
kind: "invoice",
|
||||||
|
amount_atomic: "500000000000",
|
||||||
|
address: &addr,
|
||||||
|
memo: "rent",
|
||||||
|
txid: None,
|
||||||
|
verified: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("store inbound invoice");
|
||||||
|
store
|
||||||
|
.insert_payment(
|
||||||
|
&peer.identity_pk,
|
||||||
|
PaymentWrite {
|
||||||
|
dir: "in",
|
||||||
|
kind: "receipt",
|
||||||
|
amount_atomic: "250000000000",
|
||||||
|
address: &addr,
|
||||||
|
memo: "",
|
||||||
|
txid: Some("deadbeef"),
|
||||||
|
verified: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("store inbound receipt");
|
||||||
|
}
|
||||||
|
|
||||||
|
let rows = node.list_payments(&peer.identity_pk).expect("payments");
|
||||||
|
assert_eq!(rows.len(), 2, "one row per stored frame");
|
||||||
|
assert_eq!(rows[0].kind, "invoice", "oldest row first");
|
||||||
|
assert_eq!(rows[0].dir, "in");
|
||||||
|
assert_eq!(rows[0].amount_atomic, "500000000000");
|
||||||
|
assert_eq!(rows[0].memo, "rent");
|
||||||
|
assert_eq!(rows[1].kind, "receipt");
|
||||||
|
assert_eq!(rows[1].txid.as_deref(), Some("deadbeef"));
|
||||||
|
|
||||||
|
let none = node
|
||||||
|
.list_payments(&stranger.identity_pk)
|
||||||
|
.expect("a friend with no rows is an empty vector, not an error");
|
||||||
|
assert!(none.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
/// A stand-in for `monero-wallet-rpc`: it records its argv, then does what
|
/// A stand-in for `monero-wallet-rpc`: it records its argv, then does what
|
||||||
/// the test needs. The wallet child spawns a real process, so this is the
|
/// the test needs. The wallet child spawns a real process, so this is the
|
||||||
/// only honest way to drive the start path offline.
|
/// only honest way to drive the start path offline.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue