2016-01-21 21:11:48 +01:00
|
|
|
#ifndef LIGHTNING_DAEMON_JSONRPC_H
|
|
|
|
#define LIGHTNING_DAEMON_JSONRPC_H
|
|
|
|
#include "config.h"
|
|
|
|
#include "json.h"
|
|
|
|
#include <ccan/list/list.h>
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
/* Context for a command (from JSON, but might outlive the connection!)
|
|
|
|
* You can allocate off this for temporary objects. */
|
|
|
|
struct command {
|
|
|
|
/* The global state */
|
2016-01-21 21:11:49 +01:00
|
|
|
struct lightningd_state *dstate;
|
2016-01-21 21:11:48 +01:00
|
|
|
/* The 'id' which we need to include in the response. */
|
|
|
|
const char *id;
|
|
|
|
/* The connection, or NULL if it closed. */
|
|
|
|
struct json_connection *jcon;
|
|
|
|
};
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
struct json_connection {
|
|
|
|
/* The global state */
|
2016-01-21 21:11:49 +01:00
|
|
|
struct lightningd_state *dstate;
|
2016-01-21 21:11:48 +01:00
|
|
|
|
|
|
|
/* Logging for this json connection. */
|
|
|
|
struct log *log;
|
|
|
|
|
|
|
|
/* The buffer (required to interpret tokens). */
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
/* Internal state: */
|
|
|
|
/* How much is already filled. */
|
|
|
|
size_t used;
|
|
|
|
/* How much has just been filled. */
|
|
|
|
size_t len_read;
|
|
|
|
|
|
|
|
/* We've been told to stop. */
|
|
|
|
bool stop;
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
/* Current command. */
|
|
|
|
struct command *current;
|
|
|
|
|
2016-01-21 21:11:48 +01:00
|
|
|
struct list_head output;
|
|
|
|
const char *outbuf;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct json_command {
|
|
|
|
const char *name;
|
2016-01-21 21:11:48 +01:00
|
|
|
void (*dispatch)(struct command *,
|
|
|
|
const char *buffer, const jsmntok_t *params);
|
2016-01-21 21:11:48 +01:00
|
|
|
const char *description;
|
|
|
|
const char *help;
|
|
|
|
};
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
struct json_result *null_response(const tal_t *ctx);
|
2016-01-21 21:11:48 +01:00
|
|
|
void command_success(struct command *cmd, struct json_result *response);
|
|
|
|
void PRINTF_FMT(2, 3) command_fail(struct command *cmd, const char *fmt, ...);
|
2016-01-21 21:11:48 +01:00
|
|
|
|
|
|
|
/* For initialization */
|
2016-01-21 21:11:49 +01:00
|
|
|
void setup_jsonrpc(struct lightningd_state *dstate, const char *rpc_filename);
|
2016-01-21 21:11:48 +01:00
|
|
|
|
2016-09-06 09:17:49 +02:00
|
|
|
/* Peer management */
|
|
|
|
extern const struct json_command newaddr_command;
|
2016-01-21 21:11:48 +01:00
|
|
|
extern const struct json_command connect_command;
|
2016-01-21 21:15:28 +01:00
|
|
|
extern const struct json_command close_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
extern const struct json_command getpeers_command;
|
|
|
|
|
|
|
|
/* Invoice management. */
|
2016-09-06 09:17:49 +02:00
|
|
|
extern const struct json_command invoice_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
extern const struct json_command listinvoice_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
extern const struct json_command delinvoice_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
extern const struct json_command waitinvoice_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
|
|
|
|
/* Payment management. */
|
2016-08-31 08:36:08 +02:00
|
|
|
extern const struct json_command getroute_command;
|
|
|
|
extern const struct json_command sendpay_command;
|
2016-09-06 09:17:49 +02:00
|
|
|
|
|
|
|
/* Low-level commands. */
|
|
|
|
extern const struct json_command gethtlcs_command;
|
|
|
|
|
|
|
|
/* Developer commands. */
|
|
|
|
extern const struct json_command dev_add_route_command;
|
|
|
|
extern const struct json_command dev_newhtlc_command;
|
|
|
|
extern const struct json_command dev_fulfillhtlc_command;
|
|
|
|
extern const struct json_command dev_failhtlc_command;
|
|
|
|
extern const struct json_command dev_commit_command;
|
|
|
|
extern const struct json_command dev_mocktime_command;
|
|
|
|
extern const struct json_command dev_reconnect_command;
|
|
|
|
extern const struct json_command dev_disconnect_command;
|
|
|
|
extern const struct json_command dev_signcommit_command;
|
|
|
|
extern const struct json_command dev_output_command;
|
|
|
|
extern const struct json_command dev_routefail_command;
|
|
|
|
extern const struct json_command dev_feerate_command;
|
2016-01-21 21:11:48 +01:00
|
|
|
#endif /* LIGHTNING_DAEMON_JSONRPC_H */
|