//! Durable seller-side entitlements for peer-file invoices and on-chain sales.
//! Payment records must outlive browser polling, process restarts and invoice
//! expiry: an invoice can settle while the buyer is disconnected.
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::path::{Path, PathBuf};
use tokio::{fs, io::AsyncWriteExt, sync::Mutex};
static WRITES: Mutex<()> = Mutex::const_new(());
#[derive(Clone, Serialize, Deserialize)]
struct Entitlement {
content_id: String,
price_sats: u64,
paid: bool,
}
fn path(data_dir: &Path, token: &str) -> PathBuf {
data_dir.join("content-entitlements").join(format!(
"{}.json",
hex::encode(Sha256::digest(token.as_bytes()))
))
}
async fn read(data_dir: &Path, token: &str) -> Result