| 733 | } |
| 734 | |
| 735 | static void json_add_htlcs(struct lightningd *ld, |
| 736 | struct json_stream *response, |
| 737 | const struct channel *channel) |
| 738 | { |
| 739 | /* FIXME: make per-channel htlc maps! */ |
| 740 | const struct htlc_in *hin; |
| 741 | struct htlc_in_map_iter ini; |
| 742 | const struct htlc_out *hout; |
| 743 | struct htlc_out_map_iter outi; |
| 744 | u32 local_feerate = get_feerate(channel->fee_states, |
| 745 | channel->opener, LOCAL); |
| 746 | |
| 747 | /* FIXME: Add more fields. */ |
| 748 | json_array_start(response, "htlcs"); |
| 749 | for (hin = htlc_in_map_first(ld->htlcs_in, &ini); |
| 750 | hin; |
| 751 | hin = htlc_in_map_next(ld->htlcs_in, &ini)) { |
| 752 | if (hin->key.channel != channel) |
| 753 | continue; |
| 754 | |
| 755 | json_object_start(response, NULL); |
| 756 | json_add_string(response, "direction", "in"); |
| 757 | json_add_u64(response, "id", hin->key.id); |
| 758 | json_add_amount_msat(response, "amount_msat", hin->msat); |
| 759 | json_add_u32(response, "expiry", hin->cltv_expiry); |
| 760 | json_add_sha256(response, "payment_hash", &hin->payment_hash); |
| 761 | json_add_string(response, "state", |
| 762 | htlc_state_name(hin->hstate)); |
| 763 | if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate, |
| 764 | channel->our_config.dust_limit, LOCAL, |
| 765 | channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED), |
| 766 | channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX))) |
| 767 | json_add_bool(response, "local_trimmed", true); |
| 768 | if (hin->status != NULL) |
| 769 | json_add_string(response, "status", hin->status); |
| 770 | json_object_end(response); |
| 771 | } |
| 772 | |
| 773 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 774 | hout; |
| 775 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 776 | if (hout->key.channel != channel) |
| 777 | continue; |
| 778 | |
| 779 | json_object_start(response, NULL); |
| 780 | json_add_string(response, "direction", "out"); |
| 781 | json_add_u64(response, "id", hout->key.id); |
| 782 | json_add_amount_msat(response, "amount_msat", hout->msat); |
| 783 | json_add_u64(response, "expiry", hout->cltv_expiry); |
| 784 | json_add_sha256(response, "payment_hash", &hout->payment_hash); |
| 785 | json_add_string(response, "state", |
| 786 | htlc_state_name(hout->hstate)); |
| 787 | if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate, |
| 788 | channel->our_config.dust_limit, LOCAL, |
| 789 | channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED), |
| 790 | channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX))) |
| 791 | json_add_bool(response, "local_trimmed", true); |
| 792 | json_object_end(response); |
no test coverage detected