| 1893 | } |
| 1894 | |
| 1895 | static void json_add_peer(struct lightningd *ld, |
| 1896 | struct json_stream *response, |
| 1897 | struct peer *p, |
| 1898 | const enum log_level *ll) |
| 1899 | { |
| 1900 | struct channel *channel; |
| 1901 | |
| 1902 | json_object_start(response, NULL); |
| 1903 | json_add_node_id(response, "id", &p->id); |
| 1904 | |
| 1905 | json_add_bool(response, "connected", p->connected == PEER_CONNECTED); |
| 1906 | |
| 1907 | /* If it's not connected, features are unreliable: we don't |
| 1908 | * store them in the database, and they would only reflect |
| 1909 | * their features *last* time they connected. */ |
| 1910 | if (p->connected == PEER_CONNECTED) { |
| 1911 | json_array_start(response, "netaddr"); |
| 1912 | json_add_string(response, NULL, |
| 1913 | type_to_string(tmpctx, |
| 1914 | struct wireaddr_internal, |
| 1915 | &p->addr)); |
| 1916 | json_array_end(response); |
| 1917 | /* If peer reports our IP remote_addr, add that here */ |
| 1918 | if (p->remote_addr) |
| 1919 | json_add_string(response, "remote_addr", |
| 1920 | fmt_wireaddr(response, p->remote_addr)); |
| 1921 | json_add_hex_talarr(response, "features", p->their_features); |
| 1922 | } |
| 1923 | |
| 1924 | json_array_start(response, "channels"); |
| 1925 | json_add_uncommitted_channel(response, p->uncommitted_channel); |
| 1926 | |
| 1927 | list_for_each(&p->channels, channel, list) { |
| 1928 | if (channel_unsaved(channel)) |
| 1929 | json_add_unsaved_channel(response, channel); |
| 1930 | else |
| 1931 | json_add_channel(ld, response, NULL, channel); |
| 1932 | } |
| 1933 | json_array_end(response); |
| 1934 | |
| 1935 | if (ll) |
| 1936 | json_add_log(response, ld->log_book, &p->id, *ll); |
| 1937 | json_object_end(response); |
| 1938 | } |
| 1939 | |
| 1940 | static struct command_result *json_listpeers(struct command *cmd, |
| 1941 | const char *buffer, |
no test coverage detected