| 2310 | retry_step_cb); |
| 2311 | |
| 2312 | static struct command_result * |
| 2313 | local_channel_hints_listpeers(struct command *cmd, const char *buffer, |
| 2314 | const jsmntok_t *toks, struct payment *p) |
| 2315 | { |
| 2316 | const jsmntok_t *peers, *peer, *channels, *channel, *spendsats, *scid, |
| 2317 | *dir, *connected, *max_htlc, *htlcs, *state, *alias, *alias_local; |
| 2318 | size_t i, j; |
| 2319 | peers = json_get_member(buffer, toks, "peers"); |
| 2320 | |
| 2321 | if (peers == NULL) |
| 2322 | goto done; |
| 2323 | /* cppcheck-suppress uninitvar - cppcheck can't undestand these macros. */ |
| 2324 | json_for_each_arr(i, peer, peers) { |
| 2325 | channels = json_get_member(buffer, peer, "channels"); |
| 2326 | if (channels == NULL) |
| 2327 | continue; |
| 2328 | |
| 2329 | connected = json_get_member(buffer, peer, "connected"); |
| 2330 | |
| 2331 | json_for_each_arr(j, channel, channels) { |
| 2332 | struct channel_hint h; |
| 2333 | spendsats = json_get_member(buffer, channel, "spendable_msat"); |
| 2334 | scid = json_get_member(buffer, channel, "short_channel_id"); |
| 2335 | |
| 2336 | alias = json_get_member(buffer, channel, "alias"); |
| 2337 | if (alias != NULL) |
| 2338 | alias_local = json_get_member(buffer, alias, "local"); |
| 2339 | else |
| 2340 | alias_local = NULL; |
| 2341 | |
| 2342 | dir = json_get_member(buffer, channel, "direction"); |
| 2343 | max_htlc = json_get_member(buffer, channel, "max_accepted_htlcs"); |
| 2344 | htlcs = json_get_member(buffer, channel, "htlcs"); |
| 2345 | state = json_get_member(buffer, channel, "state"); |
| 2346 | if (spendsats == NULL || |
| 2347 | (scid == NULL && alias_local == NULL) || |
| 2348 | dir == NULL || max_htlc == NULL || state == NULL || |
| 2349 | max_htlc->type != JSMN_PRIMITIVE || htlcs == NULL || |
| 2350 | htlcs->type != JSMN_ARRAY) |
| 2351 | continue; |
| 2352 | |
| 2353 | /* Filter out local channels if they are |
| 2354 | * either a) disconnected, or b) not in normal |
| 2355 | * state. */ |
| 2356 | json_to_bool(buffer, connected, &h.enabled); |
| 2357 | h.enabled &= json_tok_streq(buffer, state, "CHANNELD_NORMAL"); |
| 2358 | |
| 2359 | if (scid != NULL) |
| 2360 | json_to_short_channel_id(buffer, scid, &h.scid.scid); |
| 2361 | else |
| 2362 | json_to_short_channel_id(buffer, alias_local, &h.scid.scid); |
| 2363 | |
| 2364 | json_to_int(buffer, dir, &h.scid.dir); |
| 2365 | |
| 2366 | json_to_msat(buffer, spendsats, &h.estimated_capacity); |
| 2367 | |
| 2368 | /* Take the configured number of max_htlcs and |
| 2369 | * subtract any HTLCs that might already be added to |
nothing calls this directly
no test coverage detected