@@ -25,6 +25,26 @@ static void json_populate_offer(struct json_stream *response,
2525 json_add_escaped_string (response , "label" , label );
2626}
2727
28+ static const char * offer_description_from_b12 (const tal_t * ctx ,
29+ struct lightningd * ld ,
30+ const char * b12 )
31+ {
32+ struct tlv_offer * offer ;
33+ char * fail ;
34+
35+ offer = offer_decode (ctx , b12 , strlen (b12 ),
36+ NULL , NULL , & fail );
37+ if (!offer ) {
38+ log_debug (ld -> log , "Failed to decode BOLT12: %s" , fail );
39+ return NULL ;
40+ }
41+
42+ if (!offer -> offer_description )
43+ return NULL ;
44+
45+ return offer -> offer_description ;
46+ }
47+
2848static struct command_result * param_b12_offer (struct command * cmd ,
2949 const char * name ,
3050 const char * buffer ,
@@ -134,6 +154,7 @@ static struct command_result *json_listoffers(struct command *cmd,
134154 struct json_stream * response ;
135155 struct wallet * wallet = cmd -> ld -> wallet ;
136156 const char * b12 ;
157+ const char * description ;
137158 const struct json_escape * label ;
138159 bool * active_only ;
139160 enum offer_status status ;
@@ -154,6 +175,9 @@ static struct command_result *json_listoffers(struct command *cmd,
154175 json_populate_offer (response ,
155176 offer_id , b12 ,
156177 label , status );
178+ description = offer_description_from_b12 (tmpctx , cmd -> ld , b12 );
179+ if (description )
180+ json_add_stringn (response , "description" , description , tal_bytelen (description ));
157181 json_object_end (response );
158182 }
159183 } else {
@@ -170,6 +194,9 @@ static struct command_result *json_listoffers(struct command *cmd,
170194 json_populate_offer (response ,
171195 & id , b12 ,
172196 label , status );
197+ description = offer_description_from_b12 (tmpctx , cmd -> ld , b12 );
198+ if (description )
199+ json_add_stringn (response , "description" , description , tal_bytelen (description ));
173200 json_object_end (response );
174201 }
175202 }
@@ -193,6 +220,7 @@ static struct command_result *json_disableoffer(struct command *cmd,
193220 struct sha256 * offer_id ;
194221 struct wallet * wallet = cmd -> ld -> wallet ;
195222 const char * b12 ;
223+ const char * description ;
196224 const struct json_escape * label ;
197225 enum offer_status status ;
198226
@@ -216,6 +244,9 @@ static struct command_result *json_disableoffer(struct command *cmd,
216244
217245 response = json_stream_success (cmd );
218246 json_populate_offer (response , offer_id , b12 , label , status );
247+ description = offer_description_from_b12 (tmpctx , cmd -> ld , b12 );
248+ if (description )
249+ json_add_stringn (response , "description" , description , tal_bytelen (description ));
219250 return command_success (cmd , response );
220251}
221252
@@ -234,6 +265,7 @@ static struct command_result *json_enableoffer(struct command *cmd,
234265 struct sha256 * offer_id ;
235266 struct wallet * wallet = cmd -> ld -> wallet ;
236267 const char * b12 ;
268+ const char * description ;
237269 const struct json_escape * label ;
238270 enum offer_status status ;
239271
@@ -257,6 +289,9 @@ static struct command_result *json_enableoffer(struct command *cmd,
257289
258290 response = json_stream_success (cmd );
259291 json_populate_offer (response , offer_id , b12 , label , status );
292+ description = offer_description_from_b12 (tmpctx , cmd -> ld , b12 );
293+ if (description )
294+ json_add_stringn (response , "description" , description , tal_bytelen (description ));
260295 return command_success (cmd , response );
261296}
262297
0 commit comments