Get peers that support NODE_NETWORK (full nodes). * Returns array of peer ids, or empty array if none found. */
| 305 | /* Get peers that support NODE_NETWORK (full nodes). |
| 306 | * Returns array of peer ids, or empty array if none found. */ |
| 307 | static 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. |
no test coverage detected