introduce PayCache

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-09-01 14:11:34 -04:00
parent 09238baee0
commit 14c59a6c94

View File

@@ -1,12 +1,19 @@
use std::collections::HashMap;
use enostr::{NoteId, Pubkey};
use nostrdb::{Ndb, Transaction};
use nwc::nostr::nips::nip47::PayInvoiceResponse;
use poll_promise::Promise;
use tokio::task::JoinError;
use url::Url;
use crate::{
get_wallet_for,
zaps::{get_users_zap_address, ZapAddress},
zaps::{
get_users_zap_address,
networking::{LNUrlPayResponse, PayEntry},
ZapAddress,
},
Accounts, GlobalWallet, ZapError,
};
@@ -29,6 +36,23 @@ pub struct Zaps {
events: Vec<EventResponse>,
}
/// Cache to hold LNURL payRequest responses from the desired LNURL endpoint
#[derive(Default)]
pub struct PayCache {
// endpoint URL to response
pub pay_responses: HashMap<Url, LNUrlPayResponse>,
}
impl PayCache {
pub fn get_response(&self, url: &Url) -> Option<&LNUrlPayResponse> {
self.pay_responses.get(url)
}
pub fn insert(&mut self, entry: PayEntry) {
self.pay_responses.insert(entry.url, entry.response);
}
}
fn process_event(
id: ZapId,
event: ZapEvent,