| 864 | } |
| 865 | |
| 866 | static struct command_result *json_commando_rune(struct command *cmd, |
| 867 | const char *buffer, |
| 868 | const jsmntok_t *params) |
| 869 | { |
| 870 | struct rune *rune; |
| 871 | struct rune_restr **restrs; |
| 872 | struct out_req *req; |
| 873 | |
| 874 | if (!param(cmd, buffer, params, |
| 875 | p_opt("rune", param_rune, &rune), |
| 876 | p_opt("restrictions", param_restrictions, &restrs), |
| 877 | NULL)) |
| 878 | return command_param_failed(); |
| 879 | |
| 880 | if (rune) { |
| 881 | for (size_t i = 0; i < tal_count(restrs); i++) |
| 882 | rune_add_restr(rune, restrs[i]); |
| 883 | return reply_with_rune(cmd, NULL, NULL, rune); |
| 884 | } |
| 885 | |
| 886 | rune = rune_derive_start(cmd, master_rune, |
| 887 | tal_fmt(tmpctx, "%"PRIu64, |
| 888 | rune_counter ? *rune_counter : 0)); |
| 889 | for (size_t i = 0; i < tal_count(restrs); i++) |
| 890 | rune_add_restr(rune, restrs[i]); |
| 891 | |
| 892 | /* Now update datastore, before returning rune */ |
| 893 | req = jsonrpc_request_start(plugin, cmd, "datastore", |
| 894 | reply_with_rune, forward_error, rune); |
| 895 | json_array_start(req->js, "key"); |
| 896 | json_add_string(req->js, NULL, "commando"); |
| 897 | json_add_string(req->js, NULL, "rune_counter"); |
| 898 | json_array_end(req->js); |
| 899 | if (rune_counter) { |
| 900 | (*rune_counter)++; |
| 901 | json_add_string(req->js, "mode", "must-replace"); |
| 902 | } else { |
| 903 | /* This used to say "🌩🤯🧨🔫!" but our log filters are too strict :( */ |
| 904 | plugin_log(plugin, LOG_INFORM, "Commando powers enabled: BOOM!"); |
| 905 | rune_counter = tal(plugin, u64); |
| 906 | *rune_counter = 1; |
| 907 | json_add_string(req->js, "mode", "must-create"); |
| 908 | } |
| 909 | json_add_u64(req->js, "string", *rune_counter); |
| 910 | return send_outreq(plugin, req); |
| 911 | } |
| 912 | |
| 913 | #if DEVELOPER |
| 914 | static void memleak_mark_globals(struct plugin *p, struct htable *memtable) |
nothing calls this directly
no test coverage detected