mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
jsonrpc: populate ld->jsonrpc ourselves, so we can use it.
Next patch will call commands to get usage inside jsonrpc_new(): to do this it will need access to ld->jsonrpc, so we can't use the current pattern. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -803,20 +803,19 @@ bool jsonrpc_command_add(struct jsonrpc *rpc, struct json_command *command)
|
||||
return true;
|
||||
}
|
||||
|
||||
struct jsonrpc *jsonrpc_new(const tal_t *ctx, struct lightningd *ld)
|
||||
void jsonrpc_setup(struct lightningd *ld)
|
||||
{
|
||||
struct jsonrpc *jsonrpc = tal(ctx, struct jsonrpc);
|
||||
struct json_command **commands = get_cmdlist();
|
||||
|
||||
jsonrpc->commands = tal_arr(jsonrpc, struct json_command *, 0);
|
||||
jsonrpc->log = new_log(jsonrpc, ld->log_book, "jsonrpc");
|
||||
ld->jsonrpc = tal(ld, struct jsonrpc);
|
||||
ld->jsonrpc->commands = tal_arr(ld->jsonrpc, struct json_command *, 0);
|
||||
ld->jsonrpc->log = new_log(ld->jsonrpc, ld->log_book, "jsonrpc");
|
||||
for (size_t i=0; i<num_cmdlist; i++) {
|
||||
if (!jsonrpc_command_add_perm(jsonrpc, commands[i]))
|
||||
if (!jsonrpc_command_add_perm(ld->jsonrpc, commands[i]))
|
||||
fatal("Cannot add duplicate command %s",
|
||||
commands[i]->name);
|
||||
}
|
||||
jsonrpc->rpc_listener = NULL;
|
||||
return jsonrpc;
|
||||
ld->jsonrpc->rpc_listener = NULL;
|
||||
}
|
||||
|
||||
bool command_usage_only(const struct command *cmd)
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <lightningd/json_stream.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct jsonrpc;
|
||||
|
||||
/* The command mode tells param() how to process. */
|
||||
enum command_mode {
|
||||
/* Normal command processing */
|
||||
@@ -152,8 +154,10 @@ struct command_result *command_its_complicated(const char *why);
|
||||
* This doesn't setup the listener yet, see `jsonrpc_listen` for
|
||||
* that. This just creates the container for all jsonrpc-related
|
||||
* information so we can start gathering it before actually starting.
|
||||
*
|
||||
* It initializes ld->jsonrpc.
|
||||
*/
|
||||
struct jsonrpc *jsonrpc_new(const tal_t *ctx, struct lightningd *ld);
|
||||
void jsonrpc_setup(struct lightningd *ld);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -207,7 +207,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
|
||||
* lightningd needs to have something to put those in. This
|
||||
* is that :-)
|
||||
*/
|
||||
ld->jsonrpc = jsonrpc_new(ld, ld);
|
||||
jsonrpc_setup(ld);
|
||||
|
||||
/*~ We run a number of plugins (subprocesses that we talk JSON-RPC with)
|
||||
*alongside this process. This allows us to have an easy way for users
|
||||
|
||||
@@ -94,9 +94,9 @@ void htlcs_notify_new_block(struct lightningd *ld UNNEEDED, u32 height UNNEEDED)
|
||||
/* Generated stub for jsonrpc_listen */
|
||||
void jsonrpc_listen(struct jsonrpc *rpc UNNEEDED, struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "jsonrpc_listen called!\n"); abort(); }
|
||||
/* Generated stub for jsonrpc_new */
|
||||
struct jsonrpc *jsonrpc_new(const tal_t *ctx UNNEEDED, struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "jsonrpc_new called!\n"); abort(); }
|
||||
/* Generated stub for jsonrpc_setup */
|
||||
void jsonrpc_setup(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "jsonrpc_setup called!\n"); abort(); }
|
||||
/* Generated stub for load_channels_from_wallet */
|
||||
void load_channels_from_wallet(struct lightningd *ld UNNEEDED)
|
||||
{ fprintf(stderr, "load_channels_from_wallet called!\n"); abort(); }
|
||||
|
||||
Reference in New Issue
Block a user