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

Function get_fullnode_peers

plugins/bcli.c:307–341  ·  view source on GitHub ↗

Get peers that support NODE_NETWORK (full nodes). * Returns array of peer ids, or empty array if none found. */

Source from the content-addressed store, hash-verified

305/* Get peers that support NODE_NETWORK (full nodes).
306 * Returns array of peer ids, or empty array if none found. */
307static int *get_fullnode_peers(const tal_t *ctx, struct command *cmd)
308{
309 struct bcli_result *res;
310 const jsmntok_t *t, *toks;
311 int *peers = tal_arr(ctx, int, 0);
312 size_t i;
313
314 res = run_bitcoin_cli(cmd, cmd->plugin, "getpeerinfo", NULL);
315 if (res->exitstatus != 0)
316 return peers;
317
318 toks = json_parse_simple(res->output, res->output, res->output_len);
319 if (!toks)
320 return peers;
321
322 json_for_each_arr(i, t, toks) {
323 int id;
324 u8 *services;
325
326 if (json_scan(tmpctx, res->output, t, "{id:%,services:%}",
327 JSON_SCAN(json_to_int, &id),
328 JSON_SCAN_TAL(tmpctx, json_tok_bin_from_hex, &services)) == NULL) {
329 /* From bitcoin source:
330 * NODE_NETWORK means that the node is capable of serving the complete block chain.
331 * It is currently set by all Bitcoin Core non pruned nodes, and is unset by SPV
332 * clients or other light clients.
333 * NODE_NETWORK = (1 << 0)
334 */
335 if (tal_count(services) > 0 && (services[tal_count(services)-1] & (1 << 0)))
336 tal_arr_expand(&peers, id);
337 }
338 }
339
340 return peers;
341}
342
343/* Get a raw block given its height.
344 * Calls `getblockhash` then `getblock` to retrieve it from bitcoin_cli.

Callers 1

getrawblockbyheightFunction · 0.85

Calls 3

run_bitcoin_cliFunction · 0.85
json_parse_simpleFunction · 0.85
json_scanFunction · 0.50

Tested by

no test coverage detected