Uploads pending tokens to the worldwide counter. Returns the new worldwide total on success, or None on any failure.
(amount: u64)
| 40 | /// Uploads pending tokens to the worldwide counter. |
| 41 | /// Returns the new worldwide total on success, or None on any failure. |
| 42 | pub fn flush_pending(amount: u64) -> Option<u64> { |
| 43 | if amount == 0 { |
| 44 | return None; |
| 45 | } |
| 46 | let body = serde_json::json!({ "amount": amount }); |
| 47 | let agent = agent_with_timeout(FLUSH_TIMEOUT); |
| 48 | let parsed: WorkerResponse = agent |
| 49 | .post(&format!("{WORKER_URL}/increment")) |
| 50 | .send_json(&body) |
| 51 | .ok()? |
| 52 | .body_mut() |
| 53 | .read_json() |
| 54 | .ok()?; |
| 55 | Some(parsed.total) |
| 56 | } |
| 57 | |
| 58 | /// Fetches the current worldwide total from the worker. |
| 59 | /// Returns None on timeout, network error, or parse failure. |
no test coverage detected