| 427 | } |
| 428 | |
| 429 | static void json_add_htlcs(struct lightningd *ld, |
| 430 | struct json_stream *response, |
| 431 | const struct channel *channel) |
| 432 | { |
| 433 | /* FIXME: make per-channel htlc maps! */ |
| 434 | const struct htlc_in *hin; |
| 435 | struct htlc_in_map_iter ini; |
| 436 | const struct htlc_out *hout; |
| 437 | struct htlc_out_map_iter outi; |
| 438 | u32 local_feerate = get_feerate(channel->fee_states, |
| 439 | channel->opener, LOCAL); |
| 440 | |
| 441 | /* FIXME: Add more fields. */ |
| 442 | json_array_start(response, "htlcs"); |
| 443 | for (hin = htlc_in_map_first(&ld->htlcs_in, &ini); |
| 444 | hin; |
| 445 | hin = htlc_in_map_next(&ld->htlcs_in, &ini)) { |
| 446 | if (hin->key.channel != channel) |
| 447 | continue; |
| 448 | |
| 449 | json_object_start(response, NULL); |
| 450 | json_add_string(response, "direction", "in"); |
| 451 | json_add_u64(response, "id", hin->key.id); |
| 452 | json_add_amount_msat_compat(response, hin->msat, |
| 453 | "msatoshi", "amount_msat"); |
| 454 | json_add_u32(response, "expiry", hin->cltv_expiry); |
| 455 | json_add_sha256(response, "payment_hash", &hin->payment_hash); |
| 456 | json_add_string(response, "state", |
| 457 | htlc_state_name(hin->hstate)); |
| 458 | if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate, |
| 459 | channel->our_config.dust_limit, LOCAL, |
| 460 | channel_has(channel, OPT_ANCHOR_OUTPUTS))) |
| 461 | json_add_bool(response, "local_trimmed", true); |
| 462 | if (hin->status != NULL) |
| 463 | json_add_string(response, "status", hin->status); |
| 464 | json_object_end(response); |
| 465 | } |
| 466 | |
| 467 | for (hout = htlc_out_map_first(&ld->htlcs_out, &outi); |
| 468 | hout; |
| 469 | hout = htlc_out_map_next(&ld->htlcs_out, &outi)) { |
| 470 | if (hout->key.channel != channel) |
| 471 | continue; |
| 472 | |
| 473 | json_object_start(response, NULL); |
| 474 | json_add_string(response, "direction", "out"); |
| 475 | json_add_u64(response, "id", hout->key.id); |
| 476 | json_add_amount_msat_compat(response, hout->msat, |
| 477 | "msatoshi", "amount_msat"); |
| 478 | json_add_u64(response, "expiry", hout->cltv_expiry); |
| 479 | json_add_sha256(response, "payment_hash", &hout->payment_hash); |
| 480 | json_add_string(response, "state", |
| 481 | htlc_state_name(hout->hstate)); |
| 482 | if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate, |
| 483 | channel->our_config.dust_limit, LOCAL, |
| 484 | channel_has(channel, OPT_ANCHOR_OUTPUTS))) |
| 485 | json_add_bool(response, "local_trimmed", true); |
| 486 | json_object_end(response); |
no test coverage detected