Skip to content

Commit 4ffedc3

Browse files
ShahanaFarooquierdoganishe
authored andcommitted
lightningd: Updated offer methods
1 parent d16f83b commit 4ffedc3

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

lightningd/offer.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ static void json_populate_offer(struct json_stream *response,
1414
const struct sha256 *offer_id,
1515
const char *b12,
1616
const struct json_escape *label,
17-
const char *description,
1817
enum offer_status status)
1918
{
2019
json_add_sha256(response, "offer_id", offer_id);
2120
json_add_bool(response, "active", offer_status_active(status));
2221
json_add_bool(response, "single_use", offer_status_single(status));
2322
json_add_string(response, "bolt12", b12);
24-
if (description)
25-
json_add_string(response, "description", description);
2623
json_add_bool(response, "used", offer_status_used(status));
2724
if (label)
2825
json_add_escaped_string(response, "label", label);
@@ -35,8 +32,8 @@ static const char *offer_description_from_b12(const tal_t *ctx,
3532
struct tlv_offer *offer;
3633
char *fail;
3734

38-
offer = offer_decode(ctx, b12, strlen(b12),
39-
ld->our_features, chainparams, &fail);
35+
offer = offer_decode(ctx, b12, strlen(b12),
36+
NULL, NULL, &fail);
4037
if (!offer) {
4138
log_debug(ld->log, "Failed to decode BOLT12: %s", fail);
4239
return NULL;
@@ -45,7 +42,7 @@ static const char *offer_description_from_b12(const tal_t *ctx,
4542
if (!offer->offer_description)
4643
return NULL;
4744

48-
return (const char *)offer->offer_description;
45+
return offer->offer_description;
4946
}
5047

5148
static struct command_result *param_b12_offer(struct command *cmd,
@@ -137,8 +134,7 @@ static struct command_result *json_createoffer(struct command *cmd,
137134
created = true;
138135

139136
response = json_stream_success(cmd);
140-
json_populate_offer(response, &offer_id, b12str, label,
141-
offer->offer_description, status);
137+
json_populate_offer(response, &offer_id, b12str, label, status);
142138
json_add_bool(response, "created", created);
143139
return command_success(cmd, response);
144140
}
@@ -174,12 +170,14 @@ static struct command_result *json_listoffers(struct command *cmd,
174170
if (offer_id) {
175171
b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label,
176172
&status);
177-
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
178173
if (b12 && offer_status_active(status) >= *active_only) {
179174
json_object_start(response, NULL);
180175
json_populate_offer(response,
181176
offer_id, b12,
182-
label, description, status);
177+
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));
183181
json_object_end(response);
184182
}
185183
} else {
@@ -191,12 +189,14 @@ static struct command_result *json_listoffers(struct command *cmd,
191189
stmt = wallet_offer_id_next(cmd->ld->wallet, stmt, &id)) {
192190
b12 = wallet_offer_find(tmpctx, wallet, &id,
193191
&label, &status);
194-
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
195192
if (offer_status_active(status) >= *active_only) {
196193
json_object_start(response, NULL);
197194
json_populate_offer(response,
198195
&id, b12,
199-
label, description, status);
196+
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));
200200
json_object_end(response);
201201
}
202202
}
@@ -230,7 +230,6 @@ static struct command_result *json_disableoffer(struct command *cmd,
230230
return command_param_failed();
231231

232232
b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label, &status);
233-
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
234233
if (!b12)
235234
return command_fail(cmd, LIGHTNINGD, "Unknown offer");
236235

@@ -244,7 +243,10 @@ static struct command_result *json_disableoffer(struct command *cmd,
244243
status = wallet_offer_disable(wallet, offer_id, status);
245244

246245
response = json_stream_success(cmd);
247-
json_populate_offer(response, offer_id, b12, label, description, status);
246+
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));
248250
return command_success(cmd, response);
249251
}
250252

@@ -273,7 +275,6 @@ static struct command_result *json_enableoffer(struct command *cmd,
273275
return command_param_failed();
274276

275277
b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label, &status);
276-
description = offer_description_from_b12(tmpctx, cmd->ld, b12);
277278
if (!b12)
278279
return command_fail(cmd, LIGHTNINGD, "Unknown offer");
279280

@@ -287,7 +288,10 @@ static struct command_result *json_enableoffer(struct command *cmd,
287288
status = wallet_offer_enable(wallet, offer_id, status);
288289

289290
response = json_stream_success(cmd);
290-
json_populate_offer(response, offer_id, b12, label, description, status);
291+
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));
291295
return command_success(cmd, response);
292296
}
293297

0 commit comments

Comments
 (0)