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

Function json_add_forwarding_object

lightningd/peer_htlcs.c:2813–2877  ·  view source on GitHub ↗

Warp this process to ensure the consistent json object structure * between 'listforwards' API and 'forward_event' notification. */

Source from the content-addressed store, hash-verified

2811/* Warp this process to ensure the consistent json object structure
2812 * between 'listforwards' API and 'forward_event' notification. */
2813void json_add_forwarding_object(struct json_stream *response,
2814 const char *fieldname,
2815 const struct forwarding *cur,
2816 const struct sha256 *payment_hash)
2817{
2818 json_object_start(response, fieldname);
2819
2820 /* Only for forward_event */
2821 if (payment_hash)
2822 json_add_sha256(response, "payment_hash", payment_hash);
2823 json_add_short_channel_id(response, "in_channel", &cur->channel_in);
2824
2825#ifdef COMPAT_V0121
2826 if (cur->htlc_id_in != HTLC_INVALID_ID)
2827#endif
2828 json_add_u64(response, "in_htlc_id", cur->htlc_id_in);
2829
2830 /* This can be unknown if we failed before channel lookup */
2831 if (cur->channel_out.u64 != 0) {
2832 json_add_short_channel_id(response, "out_channel",
2833 &cur->channel_out);
2834 if (cur->htlc_id_out)
2835 json_add_u64(response, "out_htlc_id", *cur->htlc_id_out);
2836 }
2837 json_add_amount_msat_compat(response,
2838 cur->msat_in,
2839 "in_msatoshi", "in_msat");
2840
2841 /* These can be unset (aka zero) if we failed before channel lookup */
2842 if (!amount_msat_eq(cur->msat_out, AMOUNT_MSAT(0))) {
2843 json_add_amount_msat_compat(response,
2844 cur->msat_out,
2845 "out_msatoshi", "out_msat");
2846 json_add_amount_msat_compat(response,
2847 cur->fee,
2848 "fee", "fee_msat");
2849 }
2850 json_add_string(response, "status", forward_status_name(cur->status));
2851
2852 if (cur->failcode != 0) {
2853 json_add_num(response, "failcode", cur->failcode);
2854 json_add_string(response, "failreason",
2855 onion_wire_name(cur->failcode));
2856 }
2857
2858 /* Old forwards don't have this field */
2859 if (cur->forward_style != FORWARD_STYLE_UNKNOWN)
2860 json_add_string(response, "style",
2861 forward_style_name(cur->forward_style));
2862
2863#ifdef COMPAT_V070
2864 /* If a forwarding doesn't have received_time it was created
2865 * before we added the tracking, do not include it here. */
2866 if (cur->received_time.ts.tv_sec) {
2867 json_add_timeabs(response, "received_time", cur->received_time);
2868 if (cur->resolved_time)
2869 json_add_timeabs(response, "resolved_time", *cur->resolved_time);
2870 }

Calls 13

forward_status_nameFunction · 0.85
onion_wire_nameFunction · 0.85
forward_style_nameFunction · 0.85
json_object_startFunction · 0.50
json_add_sha256Function · 0.50
json_add_u64Function · 0.50
amount_msat_eqFunction · 0.50
json_add_stringFunction · 0.50
json_add_numFunction · 0.50
json_add_timeabsFunction · 0.50

Tested by

no test coverage detected