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

Function json_checkrune

lightningd/runes.c:915–975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

913}
914
915static struct command_result *json_checkrune(struct command *cmd,
916 const char *buffer,
917 const jsmntok_t *obj UNNEEDED,
918 const jsmntok_t *params)
919{
920 const jsmntok_t *methodparams;
921 struct cond_info cinfo;
922 struct rune_and_string *ras;
923 struct node_id *nodeid;
924 struct json_stream *js;
925 const char *err, *method;
926
927 if (!param(cmd, buffer, params,
928 p_req("rune", param_rune, &ras),
929 p_opt("nodeid", param_node_id, &nodeid),
930 p_opt("method", param_string, &method),
931 p_opt("params", param_params, &methodparams),
932 NULL))
933 return command_param_failed();
934
935 if (is_rune_blacklisted(cmd->ld->runes, ras->rune))
936 return command_fail(cmd, RUNE_BLACKLISTED, "Not authorized: Blacklisted rune");
937
938 cinfo.runes = cmd->ld->runes;
939 cinfo.peer = nodeid;
940 cinfo.buf = buffer;
941 cinfo.method = method;
942 cinfo.params = methodparams;
943 cinfo.now = clock_time();
944 strmap_init(&cinfo.cached_params);
945
946 err = rune_is_ours(cmd->ld, ras->rune);
947 if (err) {
948 return command_fail(cmd, RUNE_NOT_AUTHORIZED, "Not authorized: %s", err);
949 }
950
951 err = rune_test(tmpctx, cmd->ld->runes->master, ras->rune, check_condition, &cinfo);
952 strmap_clear(&cinfo.cached_params);
953
954 /* Just in case they manage to make us speak non-JSON, escape! */
955 if (err) {
956 err = json_escape(tmpctx, err)->s;
957
958 /* Turn runespeak into english! */
959 if (strstarts(err, "pname"))
960 err = tal_strcat(tmpctx, "parameter ", err + strlen("pname"));
961 else if (strstarts(err, "parr"))
962 err = tal_strcat(tmpctx, "parameter #", err + strlen("parr"));
963 else if (strstarts(err, "pnum"))
964 err = tal_strcat(tmpctx, "number of parameters", err + strlen("pnum"));
965 else if (strstarts(err, "pinv"))
966 err = tal_strcat(tmpctx, "invoice parameter ", err + strlen("pinv"));
967 return command_fail(cmd, RUNE_NOT_PERMITTED, "Not permitted: %s", err);
968 }
969
970 update_rune_usage_time(cmd->ld->runes, ras->rune, cinfo.now);
971
972 js = json_stream_success(cmd);

Callers

nothing calls this directly

Calls 11

is_rune_blacklistedFunction · 0.85
clock_timeFunction · 0.85
rune_is_oursFunction · 0.85
update_rune_usage_timeFunction · 0.85
json_add_boolFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_escapeClass · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected