diff options
| author | Your Name <you@example.com> | 2026-05-16 15:32:55 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-16 15:32:55 +0530 |
| commit | 133e40c82afb4d7659758b1fa57925ac57af4621 (patch) | |
| tree | 130f43e668f42f8fcc8ef55808ba89b6db40f615 /main/tollgate_main.c | |
| parent | 8f0aeb7d7b8216f1fc906cf855e5be9e90ecc0a8 (diff) | |
Phase 3: on-device Cashu wallet with mbedTLS secp256k1 + SPIFFS persistence + PSRAM
- wallet.c/h: secp256k1 ECP primitives (hash_to_curve, scalar_mul, point_add)
- wallet_persist.c/h: SPIFFS persistence with threshold-based write protection
- Fee accounting for swap (input_fee_ppk from /v1/keysets)
- Keyset fetch via /v1/keysets (586 bytes vs 21KB for /v1/keys)
- Wallet API: GET /wallet, POST /wallet/swap, POST /wallet/send
- Payment proofs auto-stored to wallet + persisted on SPIFFS
- PSRAM enabled for large allocations (ESP32-S3 has 8MB)
- Wallet init deferred to dedicated task (avoids sys_evt stack overflow)
- Cashu proof ID buffer size fixed (66 hex chars, not 16)
- HTTP client: added fetch_headers() call for proper response handling
- persist_threshold_sats config parameter (default: 1 sat)
Diffstat (limited to 'main/tollgate_main.c')
| -rw-r--r-- | main/tollgate_main.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 9d2c392..d4b29bc 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "firewall.h" | 16 | #include "firewall.h" |
| 17 | #include "session.h" | 17 | #include "session.h" |
| 18 | #include "tollgate_api.h" | 18 | #include "tollgate_api.h" |
| 19 | #include "wallet.h" | ||
| 19 | 20 | ||
| 20 | #define MAX_STA_RETRY 5 | 21 | #define MAX_STA_RETRY 5 |
| 21 | static const char *TAG = "tollgate_main"; | 22 | static const char *TAG = "tollgate_main"; |
| @@ -88,6 +89,14 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, | |||
| 88 | } | 89 | } |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 92 | static void wallet_init_task(void *pvParameters) | ||
| 93 | { | ||
| 94 | const tollgate_config_t *cfg = tollgate_config_get(); | ||
| 95 | wallet_init(); | ||
| 96 | wallet_fetch_keysets(cfg->mint_url); | ||
| 97 | vTaskDelete(NULL); | ||
| 98 | } | ||
| 99 | |||
| 91 | static void start_services(void) | 100 | static void start_services(void) |
| 92 | { | 101 | { |
| 93 | if (s_services_mutex) xSemaphoreTake(s_services_mutex, portMAX_DELAY); | 102 | if (s_services_mutex) xSemaphoreTake(s_services_mutex, portMAX_DELAY); |
| @@ -107,6 +116,8 @@ static void start_services(void) | |||
| 107 | firewall_init(ap_ip_info.ip); | 116 | firewall_init(ap_ip_info.ip); |
| 108 | session_manager_init(); | 117 | session_manager_init(); |
| 109 | 118 | ||
| 119 | xTaskCreate(wallet_init_task, "wallet_init", 32768, NULL, 5, NULL); | ||
| 120 | |||
| 110 | const tollgate_config_t *cfg = tollgate_config_get(); | 121 | const tollgate_config_t *cfg = tollgate_config_get(); |
| 111 | dns_server_start(ap_ip_info.ip, upstream_dns); | 122 | dns_server_start(ap_ip_info.ip, upstream_dns); |
| 112 | captive_portal_start(cfg->ap_ip_str); | 123 | captive_portal_start(cfg->ap_ip_str); |