MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_add_htlcs

Function json_add_htlcs

lightningd/peer_control.c:710–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

708}
709
710static void json_add_htlcs(struct lightningd *ld,
711 struct json_stream *response,
712 const struct channel *channel)
713{
714 /* FIXME: make per-channel htlc maps! */
715 const struct htlc_in *hin;
716 struct htlc_in_map_iter ini;
717 const struct htlc_out *hout;
718 struct htlc_out_map_iter outi;
719 u32 local_feerate = get_feerate(channel->fee_states,
720 channel->opener, LOCAL);
721
722 /* FIXME: Add more fields. */
723 json_array_start(response, "htlcs");
724 for (hin = htlc_in_map_first(ld->htlcs_in, &ini);
725 hin;
726 hin = htlc_in_map_next(ld->htlcs_in, &ini)) {
727 if (hin->key.channel != channel)
728 continue;
729
730 json_object_start(response, NULL);
731 json_add_string(response, "direction", "in");
732 json_add_u64(response, "id", hin->key.id);
733 json_add_amount_msat(response, "amount_msat", hin->msat);
734 json_add_u32(response, "expiry", hin->cltv_expiry);
735 json_add_sha256(response, "payment_hash", &hin->payment_hash);
736 json_add_string(response, "state",
737 htlc_state_name(hin->hstate));
738 if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate,
739 channel->our_config.dust_limit, LOCAL,
740 channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED),
741 channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX)))
742 json_add_bool(response, "local_trimmed", true);
743 if (hin->status != NULL)
744 json_add_string(response, "status", hin->status);
745 json_object_end(response);
746 }
747
748 for (hout = htlc_out_map_first(ld->htlcs_out, &outi);
749 hout;
750 hout = htlc_out_map_next(ld->htlcs_out, &outi)) {
751 if (hout->key.channel != channel)
752 continue;
753
754 json_object_start(response, NULL);
755 json_add_string(response, "direction", "out");
756 json_add_u64(response, "id", hout->key.id);
757 json_add_amount_msat(response, "amount_msat", hout->msat);
758 json_add_u64(response, "expiry", hout->cltv_expiry);
759 json_add_sha256(response, "payment_hash", &hout->payment_hash);
760 json_add_string(response, "state",
761 htlc_state_name(hout->hstate));
762 if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate,
763 channel->our_config.dust_limit, LOCAL,
764 channel_has(channel, OPT_ANCHOR_OUTPUTS_DEPRECATED),
765 channel_has(channel, OPT_ANCHORS_ZERO_FEE_HTLC_TX)))
766 json_add_bool(response, "local_trimmed", true);
767 json_object_end(response);

Callers 1

peer_control.cFile · 0.85

Calls 14

json_array_startFunction · 0.85
json_object_startFunction · 0.85
json_add_u64Function · 0.85
json_add_amount_msatFunction · 0.85
json_add_u32Function · 0.85
json_add_sha256Function · 0.85
htlc_is_trimmedFunction · 0.85
json_add_boolFunction · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85
channel_hasFunction · 0.70
get_feerateFunction · 0.50

Tested by

no test coverage detected