| 569 | } |
| 570 | |
| 571 | static struct command_result *json_createrune(struct command *cmd, |
| 572 | const char *buffer, |
| 573 | const jsmntok_t *obj UNNEEDED, |
| 574 | const jsmntok_t *params) |
| 575 | { |
| 576 | struct rune_and_string *ras; |
| 577 | struct rune_restr **restrs; |
| 578 | |
| 579 | if (!param(cmd, buffer, params, |
| 580 | p_opt("rune", param_rune, &ras), |
| 581 | p_opt("restrictions", param_restrictions, &restrs), |
| 582 | NULL)) |
| 583 | return command_param_failed(); |
| 584 | |
| 585 | if (ras != NULL ) { |
| 586 | for (size_t i = 0; i < tal_count(restrs); i++) |
| 587 | rune_add_restr(ras->rune, restrs[i]); |
| 588 | return reply_with_rune(cmd, NULL, NULL, ras->rune); |
| 589 | } |
| 590 | |
| 591 | ras = tal(cmd, struct rune_and_string); |
| 592 | ras->rune = rune_derive_start(cmd, cmd->ld->runes->master, |
| 593 | tal_fmt(tmpctx, "%"PRIu64, |
| 594 | cmd->ld->runes->next_unique_id)); |
| 595 | ras->runestr = rune_to_base64(tmpctx, ras->rune); |
| 596 | |
| 597 | for (size_t i = 0; i < tal_count(restrs); i++) |
| 598 | rune_add_restr(ras->rune, restrs[i]); |
| 599 | |
| 600 | /* Insert into DB*/ |
| 601 | wallet_rune_insert(cmd->ld->wallet, ras->rune); |
| 602 | cmd->ld->runes->next_unique_id = cmd->ld->runes->next_unique_id + 1; |
| 603 | return reply_with_rune(cmd, NULL, NULL, ras->rune); |
| 604 | } |
| 605 | |
| 606 | static const struct json_command creatrune_command = { |
| 607 | "createrune", |
nothing calls this directly
no test coverage detected