| 391 | } |
| 392 | |
| 393 | static struct command_result *json_showrunes(struct command *cmd, |
| 394 | const char *buffer, |
| 395 | const jsmntok_t *obj UNNEEDED, |
| 396 | const jsmntok_t *params) |
| 397 | { |
| 398 | struct json_stream *response; |
| 399 | struct rune_and_string *ras; |
| 400 | |
| 401 | if (!param(cmd, buffer, params, |
| 402 | p_opt("rune", param_rune, &ras), NULL)) |
| 403 | return command_param_failed(); |
| 404 | |
| 405 | response = json_stream_success(cmd); |
| 406 | json_array_start(response, "runes"); |
| 407 | if (ras) { |
| 408 | u64 uid = rune_unique_id(ras->rune); |
| 409 | struct timeabs last_used; |
| 410 | const char *from_db = wallet_get_rune(tmpctx, cmd->ld->wallet, uid, &last_used); |
| 411 | |
| 412 | /* This is how we indicate no timestamp: */ |
| 413 | if (!from_db) |
| 414 | last_used.ts.tv_sec = 0; |
| 415 | /* We consider it stored iff this is exactly stored */ |
| 416 | json_add_rune(cmd->ld, response, NULL, ras->runestr, ras->rune, |
| 417 | from_db && streq(from_db, ras->runestr), last_used); |
| 418 | } else { |
| 419 | struct timeabs *last_used; |
| 420 | const char **strs = wallet_get_runes(cmd, cmd->ld->wallet, &last_used); |
| 421 | for (size_t i = 0; i < tal_count(strs); i++) { |
| 422 | const struct rune *r = rune_from_base64(cmd, strs[i]); |
| 423 | json_add_rune(cmd->ld, response, NULL, strs[i], r, true, last_used[i]); |
| 424 | } |
| 425 | } |
| 426 | json_array_end(response); |
| 427 | return command_success(cmd, response); |
| 428 | } |
| 429 | |
| 430 | static const struct json_command showrunes_command = { |
| 431 | "showrunes", |
nothing calls this directly
no test coverage detected