mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
libplugin: allow lightningd to give us non-numeric ids.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -97,6 +97,10 @@ int htlc_state_flags(enum htlc_state state UNNEEDED)
|
|||||||
/* Generated stub for htlc_state_name */
|
/* Generated stub for htlc_state_name */
|
||||||
const char *htlc_state_name(enum htlc_state s UNNEEDED)
|
const char *htlc_state_name(enum htlc_state s UNNEEDED)
|
||||||
{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
|
{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
|
||||||
|
/* Generated stub for json_get_id */
|
||||||
|
const char *json_get_id(const tal_t *ctx UNNEEDED,
|
||||||
|
const char *buffer UNNEEDED, const jsmntok_t *obj UNNEEDED)
|
||||||
|
{ fprintf(stderr, "json_get_id called!\n"); abort(); }
|
||||||
/* Generated stub for json_get_member */
|
/* Generated stub for json_get_member */
|
||||||
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
|
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
|
||||||
const char *label UNNEEDED)
|
const char *label UNNEEDED)
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ int htlc_state_flags(enum htlc_state state UNNEEDED)
|
|||||||
/* Generated stub for htlc_state_name */
|
/* Generated stub for htlc_state_name */
|
||||||
const char *htlc_state_name(enum htlc_state s UNNEEDED)
|
const char *htlc_state_name(enum htlc_state s UNNEEDED)
|
||||||
{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
|
{ fprintf(stderr, "htlc_state_name called!\n"); abort(); }
|
||||||
|
/* Generated stub for json_get_id */
|
||||||
|
const char *json_get_id(const tal_t *ctx UNNEEDED,
|
||||||
|
const char *buffer UNNEEDED, const jsmntok_t *obj UNNEEDED)
|
||||||
|
{ fprintf(stderr, "json_get_id called!\n"); abort(); }
|
||||||
/* Generated stub for json_get_member */
|
/* Generated stub for json_get_member */
|
||||||
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
|
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
|
||||||
const char *label UNNEEDED)
|
const char *label UNNEEDED)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <ccan/read_write_all/read_write_all.h>
|
#include <ccan/read_write_all/read_write_all.h>
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <common/daemon.h>
|
#include <common/daemon.h>
|
||||||
|
#include <common/json_parse_simple.h>
|
||||||
#include <common/json_stream.h>
|
#include <common/json_stream.h>
|
||||||
#include <common/memleak.h>
|
#include <common/memleak.h>
|
||||||
#include <common/route.h>
|
#include <common/route.h>
|
||||||
@@ -211,7 +212,7 @@ static struct json_stream *jsonrpc_stream_start(struct command *cmd)
|
|||||||
|
|
||||||
json_object_start(js, NULL);
|
json_object_start(js, NULL);
|
||||||
json_add_string(js, "jsonrpc", "2.0");
|
json_add_string(js, "jsonrpc", "2.0");
|
||||||
json_add_u64(js, "id", *cmd->id);
|
json_add_string(js, "id", cmd->id);
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
@@ -1236,7 +1237,7 @@ struct json_stream *plugin_notify_start(struct command *cmd, const char *method)
|
|||||||
json_add_string(js, "method", method);
|
json_add_string(js, "method", method);
|
||||||
|
|
||||||
json_object_start(js, "params");
|
json_object_start(js, "params");
|
||||||
json_add_u64(js, "id", *cmd->id);
|
json_add_string(js, "id", cmd->id);
|
||||||
|
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
@@ -1379,10 +1380,9 @@ void plugin_set_memleak_handler(struct plugin *plugin,
|
|||||||
static void ld_command_handle(struct plugin *plugin,
|
static void ld_command_handle(struct plugin *plugin,
|
||||||
const jsmntok_t *toks)
|
const jsmntok_t *toks)
|
||||||
{
|
{
|
||||||
const jsmntok_t *idtok, *methtok, *paramstok;
|
const jsmntok_t *methtok, *paramstok;
|
||||||
struct command *cmd;
|
struct command *cmd;
|
||||||
|
|
||||||
idtok = json_get_member(plugin->buffer, toks, "id");
|
|
||||||
methtok = json_get_member(plugin->buffer, toks, "method");
|
methtok = json_get_member(plugin->buffer, toks, "method");
|
||||||
paramstok = json_get_member(plugin->buffer, toks, "params");
|
paramstok = json_get_member(plugin->buffer, toks, "params");
|
||||||
|
|
||||||
@@ -1394,16 +1394,9 @@ static void ld_command_handle(struct plugin *plugin,
|
|||||||
|
|
||||||
cmd = tal(plugin, struct command);
|
cmd = tal(plugin, struct command);
|
||||||
cmd->plugin = plugin;
|
cmd->plugin = plugin;
|
||||||
cmd->id = NULL;
|
|
||||||
cmd->usage_only = false;
|
cmd->usage_only = false;
|
||||||
cmd->methodname = json_strdup(cmd, plugin->buffer, methtok);
|
cmd->methodname = json_strdup(cmd, plugin->buffer, methtok);
|
||||||
if (idtok) {
|
cmd->id = json_get_id(cmd, plugin->buffer, toks);
|
||||||
cmd->id = tal(cmd, u64);
|
|
||||||
if (!json_to_u64(plugin->buffer, idtok, cmd->id))
|
|
||||||
plugin_err(plugin, "JSON id '%*.s' is not a number",
|
|
||||||
json_tok_full_len(idtok),
|
|
||||||
json_tok_full(plugin->buffer, idtok));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!plugin->manifested) {
|
if (!plugin->manifested) {
|
||||||
if (streq(cmd->methodname, "getmanifest")) {
|
if (streq(cmd->methodname, "getmanifest")) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ struct out_req {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct command {
|
struct command {
|
||||||
u64 *id;
|
const char *id;
|
||||||
const char *methodname;
|
const char *methodname;
|
||||||
bool usage_only;
|
bool usage_only;
|
||||||
struct plugin *plugin;
|
struct plugin *plugin;
|
||||||
|
|||||||
Reference in New Issue
Block a user