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

Function json_listoffers

lightningd/offer.c:151–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149AUTODATA(json_command, &createoffer_command);
150
151static struct command_result *json_listoffers(struct command *cmd,
152 const char *buffer,
153 const jsmntok_t *obj UNNEEDED,
154 const jsmntok_t *params)
155{
156 struct sha256 *offer_id;
157 struct json_stream *response;
158 struct wallet *wallet = cmd->ld->wallet;
159 const char *b12;
160 const char *description;
161 const struct json_escape *label;
162 bool *active_only;
163 enum offer_status status;
164 bool force_paths;
165
166 if (!param(cmd, buffer, params,
167 p_opt("offer_id", param_sha256, &offer_id),
168 p_opt_def("active_only", param_bool, &active_only, false),
169 NULL))
170 return command_param_failed();
171
172 response = json_stream_success(cmd);
173 json_array_start(response, "offers");
174 if (offer_id) {
175 b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label,
176 &status, &force_paths);
177 if (b12 && offer_status_active(status) >= *active_only) {
178 json_object_start(response, NULL);
179 json_populate_offer(response,
180 offer_id, b12,
181 label, status, force_paths);
182 description = offer_description_from_b12(tmpctx, cmd->ld, b12);
183 if (description)
184 json_add_stringn(response, "description", description, tal_bytelen(description));
185 json_object_end(response);
186 }
187 } else {
188 struct db_stmt *stmt;
189 struct sha256 id;
190
191 for (stmt = wallet_offer_id_first(cmd->ld->wallet, &id);
192 stmt;
193 stmt = wallet_offer_id_next(cmd->ld->wallet, stmt, &id)) {
194 b12 = wallet_offer_find(tmpctx, wallet, &id,
195 &label, &status, &force_paths);
196 if (offer_status_active(status) >= *active_only) {
197 json_object_start(response, NULL);
198 json_populate_offer(response,
199 &id, b12,
200 label, status, force_paths);
201 description = offer_description_from_b12(tmpctx, cmd->ld, b12);
202 if (description)
203 json_add_stringn(response, "description", description, tal_bytelen(description));
204 json_object_end(response);
205 }
206 }
207 }
208 json_array_end(response);

Callers

nothing calls this directly

Calls 15

json_array_startFunction · 0.85
offer_status_activeFunction · 0.85
json_object_startFunction · 0.85
json_populate_offerFunction · 0.85
json_add_stringnFunction · 0.85
tal_bytelenFunction · 0.85
json_object_endFunction · 0.85
wallet_offer_id_firstFunction · 0.85
wallet_offer_id_nextFunction · 0.85
json_array_endFunction · 0.85
command_param_failedFunction · 0.70

Tested by

no test coverage detected