From b9477ef84e14f473793391a2b1d61ccb58c8de0d Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 18 May 2026 14:37:29 +0530 Subject: feat: multi-mint config array and acceptance check (Phase 1+2) - config.h: increase TOLLGATE_MAX_MINT_URLS to 8, add accepted_mints[] to config struct - config.c: parse accepted_mints JSON array, fallback to mint_url for backward compat - cashu.c: cashu_is_mint_accepted() iterates accepted_mints[] instead of single mint_url --- main/cashu.c | 7 +++++-- main/config.c | 25 +++++++++++++++++++++++-- main/config.h | 4 +++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/main/cashu.c b/main/cashu.c index ec0566c..2912d1d 100644 --- a/main/cashu.c +++ b/main/cashu.c @@ -267,6 +267,9 @@ bool cashu_is_mint_accepted(const char *mint_url) { if (!mint_url || mint_url[0] == '\0') return false; const tollgate_config_t *cfg = tollgate_config_get(); - if (strstr(mint_url, cfg->mint_url) != NULL) return true; - return (strcmp(mint_url, cfg->mint_url) == 0); + for (int i = 0; i < cfg->accepted_mint_count; i++) { + if (strstr(mint_url, cfg->accepted_mints[i]) != NULL) return true; + if (strcmp(mint_url, cfg->accepted_mints[i]) == 0) return true; + } + return false; } diff --git a/main/config.c b/main/config.c index 6753f40..45eb8ff 100644 --- a/main/config.c +++ b/main/config.c @@ -58,6 +58,7 @@ esp_err_t tollgate_config_init(void) "]," "\"ap_password\":\"\"," "\"mint_url\":\"https://testnut.cashu.space\"," + "\"accepted_mints\":[\"https://testnut.cashu.space\"]," "\"price_per_step\":21," "\"step_size_ms\":60000," "\"nostr_geohash\":\"u281w0dfz\"," @@ -131,6 +132,20 @@ esp_err_t tollgate_config_init(void) cJSON *mint = cJSON_GetObjectItem(root, "mint_url"); if (mint) strncpy(g_config.mint_url, mint->valuestring, sizeof(g_config.mint_url) - 1); + cJSON *acc_mints = cJSON_GetObjectItem(root, "accepted_mints"); + if (acc_mints && cJSON_IsArray(acc_mints)) { + int mcount = cJSON_GetArraySize(acc_mints); + if (mcount > TOLLGATE_MAX_MINT_URLS) mcount = TOLLGATE_MAX_MINT_URLS; + for (int i = 0; i < mcount; i++) { + cJSON *m = cJSON_GetArrayItem(acc_mints, i); + if (m && cJSON_IsString(m)) { + strncpy(g_config.accepted_mints[i], m->valuestring, + sizeof(g_config.accepted_mints[i]) - 1); + g_config.accepted_mint_count++; + } + } + } + cJSON *lnurl = cJSON_GetObjectItem(root, "lnurl_url"); if (lnurl) strncpy(g_config.lnurl_url, lnurl->valuestring, sizeof(g_config.lnurl_url) - 1); @@ -264,15 +279,21 @@ esp_err_t tollgate_config_init(void) cJSON_Delete(root); + if (g_config.accepted_mint_count == 0 && g_config.mint_url[0] != '\0') { + strncpy(g_config.accepted_mints[0], g_config.mint_url, + sizeof(g_config.accepted_mints[0]) - 1); + g_config.accepted_mint_count = 1; + } + if (g_config.nostr_relay_count == 0) { strncpy(g_config.nostr_relays[0], "wss://relay.damus.io", sizeof(g_config.nostr_relays[0]) - 1); strncpy(g_config.nostr_relays[1], "wss://nos.lol", sizeof(g_config.nostr_relays[1]) - 1); g_config.nostr_relay_count = 2; } - ESP_LOGI(TAG, "Config loaded: nsec=%s...%s, %d WiFi networks, price=%d sats/%dms", + ESP_LOGI(TAG, "Config loaded: nsec=%s...%s, %d WiFi networks, %d accepted mints, price=%d sats/%dms", g_config.nsec, g_config.nsec + 60, g_config.network_count, - g_config.price_per_step, g_config.step_size_ms); + g_config.accepted_mint_count, g_config.price_per_step, g_config.step_size_ms); return ESP_OK; } diff --git a/main/config.h b/main/config.h index fa4d95c..8e12878 100644 --- a/main/config.h +++ b/main/config.h @@ -9,7 +9,7 @@ #include "lightning_payout.h" #define TOLLGATE_MAX_WIFI_NETWORKS 5 -#define TOLLGATE_MAX_MINT_URLS 3 +#define TOLLGATE_MAX_MINT_URLS 8 #define TOLLGATE_MAX_AP_SSID_LEN 32 #define TOLLGATE_MAX_AP_PASS_LEN 64 #define TOLLGATE_MAX_RELAYS 4 @@ -40,6 +40,8 @@ typedef struct { char ap_ip_str[16]; char mint_url[256]; + char accepted_mints[TOLLGATE_MAX_MINT_URLS][256]; + int accepted_mint_count; char lnurl_url[256]; int price_per_step; int step_size_ms; -- cgit v1.2.3