diff options
Diffstat (limited to 'main/config.c')
| -rw-r--r-- | main/config.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/main/config.c b/main/config.c index c074410..9257397 100644 --- a/main/config.c +++ b/main/config.c | |||
| @@ -26,6 +26,11 @@ esp_err_t tollgate_config_init(void) | |||
| 26 | g_config.client_steps_to_buy = 1; | 26 | g_config.client_steps_to_buy = 1; |
| 27 | g_config.client_renewal_threshold_pct = 20; | 27 | g_config.client_renewal_threshold_pct = 20; |
| 28 | g_config.client_retry_interval_ms = 30000; | 28 | g_config.client_retry_interval_ms = 30000; |
| 29 | g_config.payout.enabled = true; | ||
| 30 | g_config.payout.fee_tolerance_pct = 10; | ||
| 31 | g_config.payout.check_interval_s = 60; | ||
| 32 | g_config.payout.recipient_count = 0; | ||
| 33 | g_config.payout.mint_count = 0; | ||
| 29 | 34 | ||
| 30 | esp_vfs_spiffs_conf_t conf = { | 35 | esp_vfs_spiffs_conf_t conf = { |
| 31 | .base_path = "/spiffs", | 36 | .base_path = "/spiffs", |
| @@ -166,6 +171,75 @@ esp_err_t tollgate_config_init(void) | |||
| 166 | cJSON *client_retry = cJSON_GetObjectItem(root, "client_retry_interval_ms"); | 171 | cJSON *client_retry = cJSON_GetObjectItem(root, "client_retry_interval_ms"); |
| 167 | if (client_retry) g_config.client_retry_interval_ms = client_retry->valueint; | 172 | if (client_retry) g_config.client_retry_interval_ms = client_retry->valueint; |
| 168 | 173 | ||
| 174 | cJSON *payout = cJSON_GetObjectItem(root, "payout"); | ||
| 175 | if (payout && cJSON_IsObject(payout)) { | ||
| 176 | cJSON *p_en = cJSON_GetObjectItem(payout, "enabled"); | ||
| 177 | if (p_en && cJSON_IsBool(p_en)) g_config.payout.enabled = cJSON_IsTrue(p_en); | ||
| 178 | |||
| 179 | cJSON *p_fee = cJSON_GetObjectItem(payout, "fee_tolerance_pct"); | ||
| 180 | if (p_fee) g_config.payout.fee_tolerance_pct = (uint64_t)p_fee->valuedouble; | ||
| 181 | |||
| 182 | cJSON *p_interval = cJSON_GetObjectItem(payout, "check_interval_s"); | ||
| 183 | if (p_interval) g_config.payout.check_interval_s = p_interval->valueint; | ||
| 184 | |||
| 185 | cJSON *recipients = cJSON_GetObjectItem(payout, "recipients"); | ||
| 186 | if (recipients && cJSON_IsArray(recipients)) { | ||
| 187 | int rcount = cJSON_GetArraySize(recipients); | ||
| 188 | if (rcount > PAYOUT_MAX_RECIPIENTS) rcount = PAYOUT_MAX_RECIPIENTS; | ||
| 189 | for (int i = 0; i < rcount; i++) { | ||
| 190 | cJSON *r = cJSON_GetArrayItem(recipients, i); | ||
| 191 | cJSON *addr = cJSON_GetObjectItem(r, "lightning_address"); | ||
| 192 | cJSON *factor = cJSON_GetObjectItem(r, "factor"); | ||
| 193 | if (addr && cJSON_IsString(addr)) { | ||
| 194 | strncpy(g_config.payout.recipients[i].lightning_address, addr->valuestring, | ||
| 195 | sizeof(g_config.payout.recipients[i].lightning_address) - 1); | ||
| 196 | } | ||
| 197 | if (factor && cJSON_IsNumber(factor)) { | ||
| 198 | g_config.payout.recipients[i].factor = factor->valuedouble; | ||
| 199 | } | ||
| 200 | } | ||
| 201 | g_config.payout.recipient_count = rcount; | ||
| 202 | } | ||
| 203 | |||
| 204 | cJSON *mints = cJSON_GetObjectItem(payout, "mints"); | ||
| 205 | if (mints && cJSON_IsArray(mints)) { | ||
| 206 | int mcount = cJSON_GetArraySize(mints); | ||
| 207 | if (mcount > PAYOUT_MAX_MINTS) mcount = PAYOUT_MAX_MINTS; | ||
| 208 | for (int i = 0; i < mcount; i++) { | ||
| 209 | cJSON *m = cJSON_GetArrayItem(mints, i); | ||
| 210 | cJSON *murl = cJSON_GetObjectItem(m, "url"); | ||
| 211 | cJSON *mbal = cJSON_GetObjectItem(m, "min_balance"); | ||
| 212 | cJSON *mpay = cJSON_GetObjectItem(m, "min_payout_amount"); | ||
| 213 | if (murl && cJSON_IsString(murl)) { | ||
| 214 | strncpy(g_config.payout.mints[i].url, murl->valuestring, | ||
| 215 | sizeof(g_config.payout.mints[i].url) - 1); | ||
| 216 | } | ||
| 217 | if (mbal && cJSON_IsNumber(mbal)) { | ||
| 218 | g_config.payout.mints[i].min_balance = (uint64_t)mbal->valuedouble; | ||
| 219 | } | ||
| 220 | if (mpay && cJSON_IsNumber(mpay)) { | ||
| 221 | g_config.payout.mints[i].min_payout_amount = (uint64_t)mpay->valuedouble; | ||
| 222 | } | ||
| 223 | } | ||
| 224 | g_config.payout.mint_count = mcount; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | if (g_config.payout.mint_count == 0 && g_config.mint_url[0] != '\0') { | ||
| 229 | strncpy(g_config.payout.mints[0].url, g_config.mint_url, | ||
| 230 | sizeof(g_config.payout.mints[0].url) - 1); | ||
| 231 | g_config.payout.mints[0].min_balance = 64; | ||
| 232 | g_config.payout.mints[0].min_payout_amount = 128; | ||
| 233 | g_config.payout.mint_count = 1; | ||
| 234 | } | ||
| 235 | |||
| 236 | if (g_config.payout.recipient_count == 0) { | ||
| 237 | strncpy(g_config.payout.recipients[0].lightning_address, "TollGate@coinos.io", | ||
| 238 | sizeof(g_config.payout.recipients[0].lightning_address) - 1); | ||
| 239 | g_config.payout.recipients[0].factor = 1.0; | ||
| 240 | g_config.payout.recipient_count = 1; | ||
| 241 | } | ||
| 242 | |||
| 169 | cJSON_Delete(root); | 243 | cJSON_Delete(root); |
| 170 | 244 | ||
| 171 | if (g_config.nostr_relay_count == 0) { | 245 | if (g_config.nostr_relay_count == 0) { |