| 205 | } |
| 206 | |
| 207 | static struct command_result *json_listdatastore(struct command *cmd, |
| 208 | const char *buffer, |
| 209 | const jsmntok_t *obj UNNEEDED, |
| 210 | const jsmntok_t *params) |
| 211 | { |
| 212 | struct json_stream *response; |
| 213 | const char **key, **k, **prev_k = NULL; |
| 214 | const u8 *data; |
| 215 | u64 generation; |
| 216 | struct db_stmt *stmt; |
| 217 | |
| 218 | if (!param(cmd, buffer, params, |
| 219 | p_opt("key", param_list_or_string, &key), |
| 220 | NULL)) |
| 221 | return command_param_failed(); |
| 222 | |
| 223 | response = json_stream_success(cmd); |
| 224 | json_array_start(response, "datastore"); |
| 225 | |
| 226 | for (stmt = wallet_datastore_first(cmd, cmd->ld->wallet, key, |
| 227 | &k, &data, &generation); |
| 228 | stmt; |
| 229 | stmt = wallet_datastore_next(cmd, key, |
| 230 | stmt, &k, &data, |
| 231 | &generation)) { |
| 232 | |
| 233 | /* Don't list sub-children, except as summary to show it exists. */ |
| 234 | if (tal_count(k) > tal_count(key) + 1) { |
| 235 | if (!prev_k || !datastore_key_startswith(k, prev_k)) { |
| 236 | prev_k = tal_dup_arr(cmd, const char *, k, |
| 237 | tal_count(key) + 1, 0); |
| 238 | json_object_start(response, NULL); |
| 239 | json_add_datastore(response, prev_k, NULL, 0); |
| 240 | json_object_end(response); |
| 241 | } |
| 242 | } else { |
| 243 | json_object_start(response, NULL); |
| 244 | json_add_datastore(response, k, data, generation); |
| 245 | json_object_end(response); |
| 246 | } |
| 247 | } |
| 248 | json_array_end(response); |
| 249 | return command_success(cmd, response); |
| 250 | } |
| 251 | |
| 252 | static struct command_result *json_deldatastore(struct command *cmd, |
| 253 | const char *buffer, |
nothing calls this directly
no test coverage detected