| 168 | } |
| 169 | |
| 170 | static struct command_result *json_listoffers(struct command *cmd, |
| 171 | const char *buffer, |
| 172 | const jsmntok_t *obj UNNEEDED, |
| 173 | const jsmntok_t *params) |
| 174 | { |
| 175 | struct sha256 *offer_id; |
| 176 | struct json_stream *response; |
| 177 | struct wallet *wallet = cmd->ld->wallet; |
| 178 | const char *b12; |
| 179 | const struct json_escape *label; |
| 180 | bool *active_only; |
| 181 | enum offer_status status; |
| 182 | |
| 183 | if (!param(cmd, buffer, params, |
| 184 | p_opt("offer_id", param_sha256, &offer_id), |
| 185 | p_opt_def("active_only", param_bool, &active_only, false), |
| 186 | NULL)) |
| 187 | return command_param_failed(); |
| 188 | |
| 189 | response = json_stream_success(cmd); |
| 190 | json_array_start(response, "offers"); |
| 191 | if (offer_id) { |
| 192 | b12 = wallet_offer_find(tmpctx, wallet, offer_id, &label, |
| 193 | &status); |
| 194 | if (b12 && offer_status_active(status) >= *active_only) { |
| 195 | json_object_start(response, NULL); |
| 196 | json_populate_offer(response, |
| 197 | offer_id, b12, |
| 198 | offer_str_nosig(tmpctx, cmd->ld, b12), |
| 199 | label, status); |
| 200 | json_object_end(response); |
| 201 | } |
| 202 | } else { |
| 203 | struct db_stmt *stmt; |
| 204 | struct sha256 id; |
| 205 | |
| 206 | for (stmt = wallet_offer_id_first(cmd->ld->wallet, &id); |
| 207 | stmt; |
| 208 | stmt = wallet_offer_id_next(cmd->ld->wallet, stmt, &id)) { |
| 209 | b12 = wallet_offer_find(tmpctx, wallet, &id, |
| 210 | &label, &status); |
| 211 | if (offer_status_active(status) >= *active_only) { |
| 212 | json_object_start(response, NULL); |
| 213 | json_populate_offer(response, |
| 214 | &id, b12, |
| 215 | offer_str_nosig(tmpctx, |
| 216 | cmd->ld, b12), |
| 217 | label, status); |
| 218 | json_object_end(response); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | json_array_end(response); |
| 223 | return command_success(cmd, response); |
| 224 | } |
| 225 | |
| 226 | static const struct json_command listoffers_command = { |
| 227 | "listoffers", |
nothing calls this directly
no test coverage detected