| 1344 | } |
| 1345 | |
| 1346 | static void lookup_currency(struct command *cmd, |
| 1347 | struct bkpr *bkpr, |
| 1348 | enum mvt_tag primary_tag, |
| 1349 | u64 timestamp, |
| 1350 | struct refresh_info *rinfo) |
| 1351 | { |
| 1352 | struct out_req *req; |
| 1353 | struct currency_time *ctime; |
| 1354 | u64 now; |
| 1355 | |
| 1356 | /* If we already have the timestamp, we're done */ |
| 1357 | if (covering_currencyrate(bkpr, timestamp) != NULL) |
| 1358 | return; |
| 1359 | |
| 1360 | /* If it's more than 60 seconds old, we should not apply the current |
| 1361 | * conversion. This can definitely happen when we first turn on |
| 1362 | * currency conversion though, so don't print in that case. */ |
| 1363 | now = clock_time().ts.tv_sec; |
| 1364 | if (now > timestamp + CURRENCYRATE_TOLERANCE_SECONDS) { |
| 1365 | if (!uintmap_empty(bkpr->currency_rates) |
| 1366 | && !bkpr->warned_currency_fail) { |
| 1367 | plugin_log(cmd->plugin, LOG_BROKEN, |
| 1368 | "Event %s timestamp %"PRIu64" is %"PRIu64" seconds old: too old for current %s currencyrate (only logging first such event: there may be others)", |
| 1369 | mvt_tag_str(primary_tag), |
| 1370 | timestamp, now - timestamp, |
| 1371 | bkpr->currency->name); |
| 1372 | bkpr->warned_currency_fail = true; |
| 1373 | } |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | ctime = tal(cmd, struct currency_time); |
| 1378 | ctime->timestamp = timestamp; |
| 1379 | ctime->currency = bkpr->currency; |
| 1380 | ctime->rinfo = use_rinfo(rinfo); |
| 1381 | req = jsonrpc_request_start(cmd, |
| 1382 | "currencyrate", |
| 1383 | currency_done, |
| 1384 | currency_error, |
| 1385 | ctime); |
| 1386 | json_add_string(req->js, "currency", bkpr->currency->name); |
| 1387 | send_outreq(req); |
| 1388 | } |
| 1389 | |
| 1390 | static enum mvt_tag *json_to_tags(const tal_t *ctx, const char *buffer, const jsmntok_t *tok) |
| 1391 | { |
no test coverage detected