bug fixing and deploy and build diagnostics
This commit is contained in:
@@ -6,8 +6,6 @@ use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::Path;
|
||||
use tokio::fs;
|
||||
use tracing::debug;
|
||||
|
||||
use super::ecash;
|
||||
|
||||
const PROFITS_FILE: &str = "wallet/profits.json";
|
||||
@@ -55,42 +53,6 @@ pub async fn load_profits(data_dir: &Path) -> Result<ProfitsSummary> {
|
||||
Ok(summary)
|
||||
}
|
||||
|
||||
/// Save profits summary to disk.
|
||||
pub async fn save_profits(data_dir: &Path, summary: &ProfitsSummary) -> Result<()> {
|
||||
let dir = data_dir.join("wallet");
|
||||
fs::create_dir_all(&dir)
|
||||
.await
|
||||
.context("Failed to create wallet dir")?;
|
||||
let path = data_dir.join(PROFITS_FILE);
|
||||
let content =
|
||||
serde_json::to_string_pretty(summary).context("Failed to serialize profits")?;
|
||||
fs::write(&path, content)
|
||||
.await
|
||||
.context("Failed to write profits file")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Record a content sale profit.
|
||||
pub async fn record_content_sale(data_dir: &Path, amount_sats: u64, description: &str) -> Result<()> {
|
||||
let mut summary = load_profits(data_dir).await?;
|
||||
summary.total_sats += amount_sats;
|
||||
summary.content_sales_sats += amount_sats;
|
||||
summary.recent.insert(
|
||||
0,
|
||||
ProfitEntry {
|
||||
source: ProfitSource::ContentSale,
|
||||
amount_sats,
|
||||
timestamp: chrono::Utc::now().to_rfc3339(),
|
||||
description: description.to_string(),
|
||||
},
|
||||
);
|
||||
// Keep only the last 100 entries
|
||||
summary.recent.truncate(100);
|
||||
save_profits(data_dir, &summary).await?;
|
||||
debug!("Recorded content sale: {} sats", amount_sats);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute a full profits summary including ecash receive transactions.
|
||||
pub async fn get_networking_profits(data_dir: &Path) -> Result<ProfitsSummary> {
|
||||
let mut summary = load_profits(data_dir).await?;
|
||||
|
||||
Reference in New Issue
Block a user