| 2486 | } |
| 2487 | |
| 2488 | static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx, |
| 2489 | const char *buffer, |
| 2490 | const jsmntok_t *tok) |
| 2491 | { |
| 2492 | struct listpeers_channel *chan; |
| 2493 | const jsmntok_t *privtok = json_get_member(buffer, tok, "private"), |
| 2494 | *statetok = json_get_member(buffer, tok, "state"), |
| 2495 | *ftxidtok = |
| 2496 | json_get_member(buffer, tok, "funding_txid"), |
| 2497 | *scidtok = |
| 2498 | json_get_member(buffer, tok, "short_channel_id"), |
| 2499 | *dirtok = json_get_member(buffer, tok, "direction"), |
| 2500 | *tmsattok = json_get_member(buffer, tok, "total_msat"), |
| 2501 | *smsattok = |
| 2502 | json_get_member(buffer, tok, "spendable_msat"), |
| 2503 | *aliastok = json_get_member(buffer, tok, "alias"), |
| 2504 | *max_htlcs = json_get_member(buffer, tok, "max_accepted_htlcs"), |
| 2505 | *htlcstok = json_get_member(buffer, tok, "htlcs"), |
| 2506 | *idtok = json_get_member(buffer, tok, "peer_id"), |
| 2507 | *conntok = json_get_member(buffer, tok, "peer_connected"); |
| 2508 | |
| 2509 | chan = tal(ctx, struct listpeers_channel); |
| 2510 | |
| 2511 | if (scidtok != NULL) { |
| 2512 | assert(dirtok != NULL); |
| 2513 | chan->scid = tal(chan, struct short_channel_id); |
| 2514 | json_to_short_channel_id(buffer, scidtok, chan->scid); |
| 2515 | } else { |
| 2516 | chan->scid = NULL; |
| 2517 | } |
| 2518 | |
| 2519 | if (aliastok != NULL) { |
| 2520 | const jsmntok_t *loctok = |
| 2521 | json_get_member(buffer, aliastok, "local"), |
| 2522 | *remtok = |
| 2523 | json_get_member(buffer, aliastok, "remote"); |
| 2524 | if (loctok) { |
| 2525 | chan->alias[LOCAL] = tal(chan, struct short_channel_id); |
| 2526 | json_to_short_channel_id(buffer, loctok, |
| 2527 | chan->alias[LOCAL]); |
| 2528 | } else |
| 2529 | chan->alias[LOCAL] = NULL; |
| 2530 | |
| 2531 | if (remtok) { |
| 2532 | chan->alias[REMOTE] = tal(chan, struct short_channel_id); |
| 2533 | json_to_short_channel_id(buffer, loctok, |
| 2534 | chan->alias[REMOTE]); |
| 2535 | } else |
| 2536 | chan->alias[REMOTE] = NULL; |
| 2537 | } else { |
| 2538 | chan->alias[LOCAL] = NULL; |
| 2539 | chan->alias[REMOTE] = NULL; |
| 2540 | } |
| 2541 | |
| 2542 | /* If we catch a channel during opening, these might not be set. |
| 2543 | * It's not a real channel (yet), so ignore it! */ |
| 2544 | if (!chan->scid && !chan->alias[LOCAL]) |
| 2545 | return tal_free(chan); |
no test coverage detected