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