From 2a86bec93273e2f4ceeab60683058c65dbb1da3d Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 May 2026 14:50:41 +0530 Subject: feat: multi-mint health tracker, discovery, portal, multi-wallet (Phase 3-8) - mint_health.h/c: FreeRTOS probing task, GET /v1/info every 5min, recovery threshold 3, immediate failure, mutex-protected state - cashu.c: health-gated acceptance (config match AND reachable) - tollgate_api.c: one price_per_step tag per reachable mint in discovery - captive_portal.c: mint list with green/grey indicators, /mints API, auto-refresh every 30s via JS - nucula_wallet.h/cpp: multi-wallet (up to 4), route receive to correct wallet by mint URL, balance sums across all wallets - tollgate_main.c: init health tracker + multi-wallet on service start - CMakeLists.txt: add mint_health.c --- main/tollgate_api.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'main/tollgate_api.c') diff --git a/main/tollgate_api.c b/main/tollgate_api.c index 650b0f3..b694729 100644 --- a/main/tollgate_api.c +++ b/main/tollgate_api.c @@ -4,6 +4,7 @@ #include "session.h" #include "firewall.h" #include "nucula_wallet.h" +#include "mint_health.h" #include "esp_log.h" #include "cJSON.h" #include "lwip/sockets.h" @@ -110,16 +111,36 @@ static esp_err_t api_get_discovery(httpd_req_t *req) cJSON_AddItemToArray(step_tag, cJSON_CreateString(step_str)); cJSON_AddItemToArray(tags, step_tag); - cJSON *price_tag = cJSON_CreateArray(); - cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); - cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); char price_str[32]; snprintf(price_str, sizeof(price_str), "%d", cfg->price_per_step); - cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); - cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); - cJSON_AddItemToArray(price_tag, cJSON_CreateString(cfg->mint_url)); - cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); - cJSON_AddItemToArray(tags, price_tag); + + int mint_count = 0; + const mint_status_t *mints = mint_health_get_all(&mint_count); + bool any_reachable = false; + + for (int i = 0; i < mint_count; i++) { + if (!mints[i].reachable) continue; + any_reachable = true; + cJSON *price_tag = cJSON_CreateArray(); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString(mints[i].url)); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); + cJSON_AddItemToArray(tags, price_tag); + } + + if (!any_reachable) { + cJSON *price_tag = cJSON_CreateArray(); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); + cJSON_AddItemToArray(price_tag, cJSON_CreateString(cfg->mint_url)); + cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); + cJSON_AddItemToArray(tags, price_tag); + } cJSON *tips_tag = cJSON_CreateArray(); cJSON_AddItemToArray(tips_tag, cJSON_CreateString("tips")); -- cgit v1.2.3