upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-18 14:37:29 +0530
committerYour Name <you@example.com>2026-05-18 14:37:29 +0530
commitb9477ef84e14f473793391a2b1d61ccb58c8de0d (patch)
tree9ff2d6a89c8527c85b5fc8fa7e56936b2fc1afbf
parentd7e27c66ef9c263ca6d3cf5d2eebe5e6443d6972 (diff)
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
-rw-r--r--main/cashu.c7
-rw-r--r--main/config.c25
-rw-r--r--main/config.h4
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)
267{ 267{
268 if (!mint_url || mint_url[0] == '\0') return false; 268 if (!mint_url || mint_url[0] == '\0') return false;
269 const tollgate_config_t *cfg = tollgate_config_get(); 269 const tollgate_config_t *cfg = tollgate_config_get();
270 if (strstr(mint_url, cfg->mint_url) != NULL) return true; 270 for (int i = 0; i < cfg->accepted_mint_count; i++) {
271 return (strcmp(mint_url, cfg->mint_url) == 0); 271 if (strstr(mint_url, cfg->accepted_mints[i]) != NULL) return true;
272 if (strcmp(mint_url, cfg->accepted_mints[i]) == 0) return true;
273 }
274 return false;
272} 275}
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)
58 "]," 58 "],"
59 "\"ap_password\":\"\"," 59 "\"ap_password\":\"\","
60 "\"mint_url\":\"https://testnut.cashu.space\"," 60 "\"mint_url\":\"https://testnut.cashu.space\","
61 "\"accepted_mints\":[\"https://testnut.cashu.space\"],"
61 "\"price_per_step\":21," 62 "\"price_per_step\":21,"
62 "\"step_size_ms\":60000," 63 "\"step_size_ms\":60000,"
63 "\"nostr_geohash\":\"u281w0dfz\"," 64 "\"nostr_geohash\":\"u281w0dfz\","
@@ -131,6 +132,20 @@ esp_err_t tollgate_config_init(void)
131 cJSON *mint = cJSON_GetObjectItem(root, "mint_url"); 132 cJSON *mint = cJSON_GetObjectItem(root, "mint_url");
132 if (mint) strncpy(g_config.mint_url, mint->valuestring, sizeof(g_config.mint_url) - 1); 133 if (mint) strncpy(g_config.mint_url, mint->valuestring, sizeof(g_config.mint_url) - 1);
133 134
135 cJSON *acc_mints = cJSON_GetObjectItem(root, "accepted_mints");
136 if (acc_mints && cJSON_IsArray(acc_mints)) {
137 int mcount = cJSON_GetArraySize(acc_mints);
138 if (mcount > TOLLGATE_MAX_MINT_URLS) mcount = TOLLGATE_MAX_MINT_URLS;
139 for (int i = 0; i < mcount; i++) {
140 cJSON *m = cJSON_GetArrayItem(acc_mints, i);
141 if (m && cJSON_IsString(m)) {
142 strncpy(g_config.accepted_mints[i], m->valuestring,
143 sizeof(g_config.accepted_mints[i]) - 1);
144 g_config.accepted_mint_count++;
145 }
146 }
147 }
148
134 cJSON *lnurl = cJSON_GetObjectItem(root, "lnurl_url"); 149 cJSON *lnurl = cJSON_GetObjectItem(root, "lnurl_url");
135 if (lnurl) strncpy(g_config.lnurl_url, lnurl->valuestring, sizeof(g_config.lnurl_url) - 1); 150 if (lnurl) strncpy(g_config.lnurl_url, lnurl->valuestring, sizeof(g_config.lnurl_url) - 1);
136 151
@@ -264,15 +279,21 @@ esp_err_t tollgate_config_init(void)
264 279
265 cJSON_Delete(root); 280 cJSON_Delete(root);
266 281
282 if (g_config.accepted_mint_count == 0 && g_config.mint_url[0] != '\0') {
283 strncpy(g_config.accepted_mints[0], g_config.mint_url,
284 sizeof(g_config.accepted_mints[0]) - 1);
285 g_config.accepted_mint_count = 1;
286 }
287
267 if (g_config.nostr_relay_count == 0) { 288 if (g_config.nostr_relay_count == 0) {
268 strncpy(g_config.nostr_relays[0], "wss://relay.damus.io", sizeof(g_config.nostr_relays[0]) - 1); 289 strncpy(g_config.nostr_relays[0], "wss://relay.damus.io", sizeof(g_config.nostr_relays[0]) - 1);
269 strncpy(g_config.nostr_relays[1], "wss://nos.lol", sizeof(g_config.nostr_relays[1]) - 1); 290 strncpy(g_config.nostr_relays[1], "wss://nos.lol", sizeof(g_config.nostr_relays[1]) - 1);
270 g_config.nostr_relay_count = 2; 291 g_config.nostr_relay_count = 2;
271 } 292 }
272 293
273 ESP_LOGI(TAG, "Config loaded: nsec=%s...%s, %d WiFi networks, price=%d sats/%dms", 294 ESP_LOGI(TAG, "Config loaded: nsec=%s...%s, %d WiFi networks, %d accepted mints, price=%d sats/%dms",
274 g_config.nsec, g_config.nsec + 60, g_config.network_count, 295 g_config.nsec, g_config.nsec + 60, g_config.network_count,
275 g_config.price_per_step, g_config.step_size_ms); 296 g_config.accepted_mint_count, g_config.price_per_step, g_config.step_size_ms);
276 return ESP_OK; 297 return ESP_OK;
277} 298}
278 299
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 @@
9#include "lightning_payout.h" 9#include "lightning_payout.h"
10 10
11#define TOLLGATE_MAX_WIFI_NETWORKS 5 11#define TOLLGATE_MAX_WIFI_NETWORKS 5
12#define TOLLGATE_MAX_MINT_URLS 3 12#define TOLLGATE_MAX_MINT_URLS 8
13#define TOLLGATE_MAX_AP_SSID_LEN 32 13#define TOLLGATE_MAX_AP_SSID_LEN 32
14#define TOLLGATE_MAX_AP_PASS_LEN 64 14#define TOLLGATE_MAX_AP_PASS_LEN 64
15#define TOLLGATE_MAX_RELAYS 4 15#define TOLLGATE_MAX_RELAYS 4
@@ -40,6 +40,8 @@ typedef struct {
40 char ap_ip_str[16]; 40 char ap_ip_str[16];
41 41
42 char mint_url[256]; 42 char mint_url[256];
43 char accepted_mints[TOLLGATE_MAX_MINT_URLS][256];
44 int accepted_mint_count;
43 char lnurl_url[256]; 45 char lnurl_url[256];
44 int price_per_step; 46 int price_per_step;
45 int step_size_ms; 47 int step_size_ms;