MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_commando_rune

Function json_commando_rune

plugins/commando.c:866–911  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

864}
865
866static 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
914static void memleak_mark_globals(struct plugin *p, struct htable *memtable)

Callers

nothing calls this directly

Calls 11

rune_add_restrFunction · 0.85
reply_with_runeFunction · 0.85
rune_derive_startFunction · 0.85
command_param_failedFunction · 0.70
plugin_logFunction · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50
json_array_startFunction · 0.50
json_add_stringFunction · 0.50
json_array_endFunction · 0.50
json_add_u64Function · 0.50

Tested by

no test coverage detected