diff options
| author | Your Name <you@example.com> | 2026-05-18 14:50:41 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-18 14:50:41 +0530 |
| commit | 2a86bec93273e2f4ceeab60683058c65dbb1da3d (patch) | |
| tree | 56e66acc4eaa0b5a947bb78d28e494a0adc857e2 /main/tollgate_api.c | |
| parent | 0c3f08ac7cf8e970369ec137153107ca8edc3326 (diff) | |
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
Diffstat (limited to 'main/tollgate_api.c')
| -rw-r--r-- | main/tollgate_api.c | 37 |
1 files changed, 29 insertions, 8 deletions
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 @@ | |||
| 4 | #include "session.h" | 4 | #include "session.h" |
| 5 | #include "firewall.h" | 5 | #include "firewall.h" |
| 6 | #include "nucula_wallet.h" | 6 | #include "nucula_wallet.h" |
| 7 | #include "mint_health.h" | ||
| 7 | #include "esp_log.h" | 8 | #include "esp_log.h" |
| 8 | #include "cJSON.h" | 9 | #include "cJSON.h" |
| 9 | #include "lwip/sockets.h" | 10 | #include "lwip/sockets.h" |
| @@ -110,16 +111,36 @@ static esp_err_t api_get_discovery(httpd_req_t *req) | |||
| 110 | cJSON_AddItemToArray(step_tag, cJSON_CreateString(step_str)); | 111 | cJSON_AddItemToArray(step_tag, cJSON_CreateString(step_str)); |
| 111 | cJSON_AddItemToArray(tags, step_tag); | 112 | cJSON_AddItemToArray(tags, step_tag); |
| 112 | 113 | ||
| 113 | cJSON *price_tag = cJSON_CreateArray(); | ||
| 114 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); | ||
| 115 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); | ||
| 116 | char price_str[32]; | 114 | char price_str[32]; |
| 117 | snprintf(price_str, sizeof(price_str), "%d", cfg->price_per_step); | 115 | snprintf(price_str, sizeof(price_str), "%d", cfg->price_per_step); |
| 118 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); | 116 | |
| 119 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); | 117 | int mint_count = 0; |
| 120 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(cfg->mint_url)); | 118 | const mint_status_t *mints = mint_health_get_all(&mint_count); |
| 121 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); | 119 | bool any_reachable = false; |
| 122 | cJSON_AddItemToArray(tags, price_tag); | 120 | |
| 121 | for (int i = 0; i < mint_count; i++) { | ||
| 122 | if (!mints[i].reachable) continue; | ||
| 123 | any_reachable = true; | ||
| 124 | cJSON *price_tag = cJSON_CreateArray(); | ||
| 125 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); | ||
| 126 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); | ||
| 127 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); | ||
| 128 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); | ||
| 129 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(mints[i].url)); | ||
| 130 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); | ||
| 131 | cJSON_AddItemToArray(tags, price_tag); | ||
| 132 | } | ||
| 133 | |||
| 134 | if (!any_reachable) { | ||
| 135 | cJSON *price_tag = cJSON_CreateArray(); | ||
| 136 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("price_per_step")); | ||
| 137 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("cashu")); | ||
| 138 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(price_str)); | ||
| 139 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("sat")); | ||
| 140 | cJSON_AddItemToArray(price_tag, cJSON_CreateString(cfg->mint_url)); | ||
| 141 | cJSON_AddItemToArray(price_tag, cJSON_CreateString("1")); | ||
| 142 | cJSON_AddItemToArray(tags, price_tag); | ||
| 143 | } | ||
| 123 | 144 | ||
| 124 | cJSON *tips_tag = cJSON_CreateArray(); | 145 | cJSON *tips_tag = cJSON_CreateArray(); |
| 125 | cJSON_AddItemToArray(tips_tag, cJSON_CreateString("tips")); | 146 | cJSON_AddItemToArray(tips_tag, cJSON_CreateString("tips")); |