| 280 | } |
| 281 | |
| 282 | static struct command_result *json_deldatastore(struct command *cmd, |
| 283 | const char *buffer, |
| 284 | const jsmntok_t *obj UNNEEDED, |
| 285 | const jsmntok_t *params) |
| 286 | { |
| 287 | struct json_stream *response; |
| 288 | const char **key, **k; |
| 289 | const u8 *data; |
| 290 | u64 *generation; |
| 291 | u64 actual_gen; |
| 292 | struct db_stmt *stmt; |
| 293 | |
| 294 | if (!param(cmd, buffer, params, |
| 295 | p_req("key", param_list_or_string, &key), |
| 296 | p_opt("generation", param_u64, &generation), |
| 297 | NULL)) |
| 298 | return command_param_failed(); |
| 299 | |
| 300 | stmt = wallet_datastore_first(cmd, cmd->ld->wallet, key, |
| 301 | &k, &data, &actual_gen); |
| 302 | tal_free(stmt); |
| 303 | |
| 304 | if (!stmt || !datastore_key_eq(k, key)) { |
| 305 | return command_fail(cmd, DATASTORE_DEL_DOES_NOT_EXIST, |
| 306 | "Key does not exist"); |
| 307 | } |
| 308 | if (generation && actual_gen != *generation) |
| 309 | return command_fail(cmd, DATASTORE_DEL_WRONG_GENERATION, |
| 310 | "generation is different"); |
| 311 | |
| 312 | wallet_datastore_remove(cmd->ld->wallet, key); |
| 313 | |
| 314 | response = json_stream_success(cmd); |
| 315 | json_add_datastore(response, key, data, actual_gen); |
| 316 | return command_success(cmd, response); |
| 317 | } |
| 318 | |
| 319 | static const struct json_command datastore_command = { |
| 320 | "datastore", |
nothing calls this directly
no test coverage detected