Skip to content

Commit 024ffcd

Browse files
author
kenbak wan
committed
fix: donation total_raised uses actual received amount
For donations there's no overpay concept — the received ZEC amount IS the donation. Use received_zatoshis * confirmed_rate instead of the invoice's requested fiat amount.
1 parent c66de05 commit 024ffcd

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/scanner/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,17 @@ async fn on_invoice_confirmed(
700700
config: &Config,
701701
invoice: &invoices::Invoice,
702702
) {
703-
// Donation campaign tracking: increment total_raised exactly once per invoice
703+
// Donation campaign tracking: increment total_raised exactly once per invoice.
704+
// For donations, use actual received ZEC converted at confirmation rate — there's
705+
// no overpay/underpay concept, the received amount IS the donation.
704706
if invoice.is_donation == 1 && invoice.campaign_counted == 0 {
705707
if let Some(ref link_id) = invoice.payment_link_id {
706-
let amount_cents = (invoice.amount.unwrap_or(invoice.price_eur) * 100.0) as i64;
708+
let amount_cents = if let Some(rate) = invoice.confirmed_rate {
709+
let received_zec = invoice.received_zatoshis as f64 / 100_000_000.0;
710+
(received_zec * rate * 100.0) as i64
711+
} else {
712+
(invoice.amount.unwrap_or(invoice.price_eur) * 100.0) as i64
713+
};
707714
// Atomic: set campaign_counted=1 only if still 0 (belt-and-suspenders idempotency)
708715
let marked = sqlx::query(
709716
"UPDATE invoices SET campaign_counted = 1 WHERE id = ? AND campaign_counted = 0",

0 commit comments

Comments
 (0)