1515#include <common/json_command.h>
1616#include <common/json_helpers.h>
1717#include <common/jsonrpc_errors.h>
18+ #include <common/onion.h>
1819#include <common/overflows.h>
1920#include <common/param.h>
2021#include <common/random_select.h>
@@ -167,6 +168,38 @@ struct invoice_payment_hook_payload {
167168 /* FIXME: Include raw payload! */
168169};
169170
171+ #ifdef DEVELOPER
172+ static void invoice_payment_add_tlvs (struct json_stream * stream ,
173+ struct htlc_set * hset )
174+ {
175+ struct htlc_in * hin ;
176+ struct tlv_tlv_payload * tlvs ;
177+ assert (tal_count (hset -> htlcs ) > 0 );
178+
179+ /* Pick the first HTLC as representative for the entire set. */
180+ hin = hset -> htlcs [0 ];
181+
182+ if (hin -> payload -> type != ONION_TLV_PAYLOAD )
183+ return ;
184+ tlvs = hin -> payload -> tlv ;
185+
186+ json_array_start (stream , "extratlvs" );
187+
188+ for (size_t i = 0 ; i < tal_count (tlvs -> fields ); i ++ ) {
189+ struct tlv_field * field = & tlvs -> fields [i ];
190+ /* If we have metadata attached it is not an extra TLV field. */
191+ if (field -> meta == NULL ) {
192+ json_object_start (stream , NULL );
193+ json_add_u64 (stream , "type" , field -> numtype );
194+ json_add_num (stream , "length" , field -> length );
195+ json_add_hex_talarr (stream , "value" , field -> value );
196+ json_object_end (stream );
197+ }
198+ }
199+ json_array_end (stream );
200+ }
201+ #endif
202+
170203static void
171204invoice_payment_serialize (struct invoice_payment_hook_payload * payload ,
172205 struct json_stream * stream ,
@@ -178,6 +211,9 @@ invoice_payment_serialize(struct invoice_payment_hook_payload *payload,
178211 json_add_string (stream , "msat" ,
179212 type_to_string (tmpctx , struct amount_msat ,
180213 & payload -> msat ));
214+ #ifdef DEVELOPER
215+ invoice_payment_add_tlvs (stream , payload -> set );
216+ #endif
181217 json_object_end (stream ); /* .payment */
182218}
183219
0 commit comments