MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_notify

Function handle_notify

cli/lightning-cli.c:461–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459}
460
461static bool handle_notify(const char *buf, jsmntok_t *toks,
462 enum log_level notification_level,
463 bool *last_was_progress)
464{
465 const jsmntok_t *id, *method, *params;
466
467 if (toks->type != JSMN_OBJECT)
468 return false;
469
470 id = json_get_member(buf, toks, "id");
471 if (id)
472 return false;
473
474 method = json_get_member(buf, toks, "method");
475 if (!method)
476 return false;
477
478 params = json_get_member(buf, toks, "params");
479 if (!params)
480 return false;
481
482 /* Print nothing if --notifications=none */
483 if (notification_level == LOG_LEVEL_MAX + 1)
484 return true;
485
486 /* We try to be robust if malformed */
487 if (json_tok_streq(buf, method, "message")) {
488 const jsmntok_t *message, *leveltok;
489 enum log_level level;
490
491 leveltok = json_get_member(buf, params, "level");
492 if (!leveltok
493 || !log_level_parse(buf + leveltok->start,
494 leveltok->end - leveltok->start,
495 &level)
496 || level < notification_level)
497 return true;
498
499 if (*last_was_progress)
500 printf("\n");
501 *last_was_progress = false;
502 message = json_get_member(buf, params, "message");
503 if (!message)
504 return true;
505
506 printf("# %.*s\n",
507 message->end - message->start,
508 buf + message->start);
509 } else if (json_tok_streq(buf, method, "progress")) {
510 const jsmntok_t *num, *total, *stage;
511 u32 n, tot;
512 char bar[60 + 1];
513 char totstr[STR_MAX_CHARS(u32)];
514
515 num = json_get_member(buf, params, "num");
516 total = json_get_member(buf, params, "total");
517 if (!num || !total)
518 return true;

Callers 1

mainFunction · 0.85

Calls 4

json_get_memberFunction · 0.85
json_tok_streqFunction · 0.85
log_level_parseFunction · 0.85
json_to_u32Function · 0.50

Tested by

no test coverage detected