| 1368 | } |
| 1369 | |
| 1370 | static void lookup_currency(struct command *cmd, |
| 1371 | struct bkpr *bkpr, |
| 1372 | enum mvt_tag primary_tag, |
| 1373 | u64 timestamp, |
| 1374 | struct refresh_info *rinfo) |
| 1375 | { |
| 1376 | struct out_req *req; |
| 1377 | struct currency_time *ctime; |
| 1378 | u64 now; |
| 1379 | |
| 1380 | /* If we already have the timestamp, we're done */ |
| 1381 | if (covering_currencyrate(bkpr, timestamp) != NULL) |
| 1382 | return; |
| 1383 | |
| 1384 | /* If it's more than 60 seconds old, we should not apply the current |
| 1385 | * conversion. This can definitely happen when we first turn on |
| 1386 | * currency conversion though, so don't print in that case. */ |
| 1387 | now = clock_time().ts.tv_sec; |
| 1388 | if (now > timestamp + CURRENCYRATE_TOLERANCE_SECONDS) { |
| 1389 | if (!uintmap_empty(bkpr->currency_rates) |
| 1390 | && !bkpr->warned_currency_fail) { |
| 1391 | plugin_log(cmd->plugin, LOG_BROKEN, |
| 1392 | "Event %s timestamp %"PRIu64" is %"PRIu64" seconds old: too old for current %s currencyrate (only logging first such event: there may be others)", |
| 1393 | mvt_tag_str(primary_tag), |
| 1394 | timestamp, now - timestamp, |
| 1395 | bkpr->currency->name); |
| 1396 | bkpr->warned_currency_fail = true; |
| 1397 | } |
| 1398 | return; |
| 1399 | } |
| 1400 | |
| 1401 | ctime = tal(cmd, struct currency_time); |
| 1402 | ctime->timestamp = timestamp; |
| 1403 | ctime->currency = bkpr->currency; |
| 1404 | ctime->rinfo = use_rinfo(rinfo); |
| 1405 | req = jsonrpc_request_start(cmd, |
| 1406 | "currencyrate", |
| 1407 | currency_done, |
| 1408 | currency_error, |
| 1409 | ctime); |
| 1410 | json_add_string(req->js, "currency", bkpr->currency->name); |
| 1411 | send_outreq(req); |
| 1412 | } |
| 1413 | |
| 1414 | static enum mvt_tag *json_to_tags(const tal_t *ctx, const char *buffer, const jsmntok_t *tok) |
| 1415 | { |
no test coverage detected