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

Function json_createoffer

lightningd/offer.c:95–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95static struct command_result *json_createoffer(struct command *cmd,
96 const char *buffer,
97 const jsmntok_t *obj UNNEEDED,
98 const jsmntok_t *params)
99{
100 struct json_stream *response;
101 struct json_escape *label;
102 struct tlv_offer *offer;
103 struct sha256 offer_id;
104 const char *b12str;
105 bool *single_use, *force_paths;
106 enum offer_status status;
107 bool created;
108
109 if (!param(cmd, buffer, params,
110 p_req("bolt12", param_b12_offer, &offer),
111 p_opt("label", param_label, &label),
112 p_opt_def("single_use", param_bool, &single_use, false),
113 p_opt_def("force_paths", param_bool, &force_paths, false),
114 NULL))
115 return command_param_failed();
116
117 if (*single_use)
118 status = OFFER_SINGLE_USE_UNUSED;
119 else
120 status = OFFER_MULTIPLE_USE_UNUSED;
121 b12str = offer_encode(cmd, offer);
122 offer_offer_id(offer, &offer_id);
123
124 /* If it already exists, we use that one instead (and then
125 * the offer plugin will complain if it's inactive or expired) */
126 if (!wallet_offer_create(cmd->ld->wallet, &offer_id,
127 b12str, label, status, *force_paths)) {
128 if (!wallet_offer_find(cmd, cmd->ld->wallet, &offer_id,
129 cast_const2(const struct json_escape **,
130 &label),
131 &status, force_paths)) {
132 return command_fail(cmd, LIGHTNINGD,
133 "Could not create, nor find offer");
134 }
135 created = false;
136 } else
137 created = true;
138
139 response = json_stream_success(cmd);
140 json_populate_offer(response, &offer_id, b12str, label, status, *force_paths);
141 json_add_bool(response, "created", created);
142 return command_success(cmd, response);
143}
144
145static const struct json_command createoffer_command = {
146 "createoffer",

Callers

nothing calls this directly

Calls 11

offer_encodeFunction · 0.85
offer_offer_idFunction · 0.85
wallet_offer_createFunction · 0.85
json_populate_offerFunction · 0.85
json_add_boolFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
wallet_offer_findFunction · 0.50

Tested by

no test coverage detected