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

Function json_add_peer

lightningd/peer_control.c:2585–2619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2583}
2584
2585static void json_add_peer(struct lightningd *ld,
2586 struct json_stream *response,
2587 struct peer *p,
2588 const enum log_level *ll)
2589{
2590 struct channel *channel;
2591 u32 num_channels;
2592
2593 json_object_start(response, NULL);
2594 json_add_node_id(response, "id", &p->id);
2595
2596 json_add_bool(response, "connected", p->connected == PEER_CONNECTED);
2597 num_channels = 0;
2598 list_for_each(&p->channels, channel, list)
2599 num_channels++;
2600 json_add_num(response, "num_channels", num_channels);
2601
2602 if (p->connected == PEER_CONNECTED) {
2603 json_array_start(response, "netaddr");
2604 json_add_string(response, NULL,
2605 fmt_wireaddr_internal(tmpctx, &p->addr));
2606 json_array_end(response);
2607 /* If peer reports our IP remote_addr, add that here */
2608 if (p->remote_addr)
2609 json_add_string(response, "remote_addr",
2610 fmt_wireaddr(tmpctx, p->remote_addr));
2611 }
2612
2613 /* Note: If !PEER_CONNECTED, peer may use different features on reconnect */
2614 json_add_hex_talarr(response, "features", p->their_features);
2615
2616 if (ll)
2617 json_add_log(response, ld->log_book, &p->id, *ll);
2618 json_object_end(response);
2619}
2620
2621static struct command_result *json_listpeers(struct command *cmd,
2622 const char *buffer,

Callers 1

json_listpeersFunction · 0.85

Calls 12

json_object_startFunction · 0.85
json_add_node_idFunction · 0.85
json_add_boolFunction · 0.85
json_add_numFunction · 0.85
json_array_startFunction · 0.85
fmt_wireaddr_internalFunction · 0.85
json_array_endFunction · 0.85
fmt_wireaddrFunction · 0.85
json_add_hex_talarrFunction · 0.85
json_object_endFunction · 0.85
json_add_logFunction · 0.70
json_add_stringFunction · 0.50

Tested by

no test coverage detected