| 263 | AUTODATA(json_command, &disableoffer_command); |
| 264 | |
| 265 | static struct command_result *json_enableoffer(struct command *cmd, |
| 266 | const char *buffer, |
| 267 | const jsmntok_t *obj UNNEEDED, |
| 268 | const jsmntok_t *params) |
| 269 | { |
| 270 | struct json_stream *response; |
| 271 | struct sha256 *offer_id; |
| 272 | struct wallet *wallet = cmd->ld->wallet; |
| 273 | const char *b12; |
| 274 | const char *description; |
| 275 | const struct json_escape *label; |
| 276 | enum offer_status status; |
| 277 | bool force_paths; |
| 278 | |
| 279 | if (!param_check(cmd, buffer, params, |
| 280 | p_req("offer_id", param_sha256, &offer_id), |
| 281 | NULL)) |
| 282 | return command_param_failed(); |
| 283 | |
| 284 | b12 = wallet_offer_find(tmpctx, wallet, offer_id, |
| 285 | &label, &status, &force_paths); |
| 286 | if (!b12) |
| 287 | return command_fail(cmd, LIGHTNINGD, "Unknown offer"); |
| 288 | |
| 289 | if (offer_status_active(status)) |
| 290 | return command_fail(cmd, OFFER_ALREADY_ENABLED, |
| 291 | "offer already active"); |
| 292 | |
| 293 | if (offer_status_single(status) && offer_status_used(status)) |
| 294 | return command_fail(cmd, OFFER_USED_SINGLE_USE, |
| 295 | "cannot activate an used single use offer"); |
| 296 | |
| 297 | if (command_check_only(cmd)) |
| 298 | return command_check_done(cmd); |
| 299 | |
| 300 | status = wallet_offer_enable(wallet, offer_id, status); |
| 301 | |
| 302 | response = json_stream_success(cmd); |
| 303 | json_populate_offer(response, offer_id, b12, label, status, force_paths); |
| 304 | description = offer_description_from_b12(tmpctx, cmd->ld, b12); |
| 305 | if (description) |
| 306 | json_add_stringn(response, "description", description, tal_bytelen(description)); |
| 307 | return command_success(cmd, response); |
| 308 | } |
| 309 | |
| 310 | static const struct json_command enableoffer_command = { |
| 311 | "enableoffer", |
nothing calls this directly
no test coverage detected