diff options
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")); |