use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProofEvent {
pub nonce: String,
pub client_id: String,
pub proof_hex: String,
pub merkle_root: String,
pub npub: String,
pub user_invoice: String,
pub operator_invoice: String,
pub timestamp: u64,
}
impl ProofEvent {
pub fn new(
nonce: String,
client_id: String,
proof_hex: String,
merkle_root: String,
npub: String,
user_invoice: String,
operator_invoice: String,
) -> Self {
Self {
nonce,
client_id,
proof_hex,
merkle_root,
npub,
user_invoice,
operator_invoice,
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentReceiptEvent {
pub nonce: String,
pub payment_hash: String,
pub preimage_hex: String,
pub amount_sats: u64,
pub timestamp: u64,
}
impl PaymentReceiptEvent {
pub fn new(
nonce: String,
payment_hash: String,
preimage_hex: String,
amount_sats: u64,
) -> Self {
Self {
nonce,
payment_hash,
preimage_hex,
amount_sats,
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoginCompleteEvent {
pub nonce: String,
pub client_id: String,
pub npub: String,
pub timestamp: u64,
}
impl LoginCompleteEvent {
pub fn new(nonce: String, client_id: String, npub: String) -> Self {
Self {
nonce,
client_id,
npub,
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_proof_event_creation() {
let event = ProofEvent::new(
"abc123".to_string(),
"acme".to_string(),
"deadbeef".to_string(),
"0x1234".to_string(),
"npub1xyz".to_string(),
"lnbc100n1...".to_string(),
"lnbc10n1...".to_string(),
);
assert_eq!(event.nonce, "abc123");
assert!(event.timestamp > 0);
}
#[test]
fn test_payment_receipt_creation() {
let event = PaymentReceiptEvent::new(
"abc123".to_string(),
"payment_hash_hex".to_string(),
"preimage_hex".to_string(),
1000,
);
assert_eq!(event.amount_sats, 1000);
}
}