mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-10 07:37:05 +01:00
5e7b3d02a1
We now keep a list of commitment transaction states for "us" and "them", as well as a "struct channel_state" for staged changes. We manipulate these structures as we send out packets, receive packets, or receive acknowledgement of packets. In particular, we update the other nodes' staging_cstate as we send out our requests, and update our own staging_cstate are we receive acks. When we receive a request, we update both (as we immediately send out our ack). The RPC output is changed; rather than expose the complexity, we expose our last committed state: what would happen if we have to drop to the blockchain now. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
#ifndef LIGHTNING_DAEMON_JSONRPC_H
|
|
#define LIGHTNING_DAEMON_JSONRPC_H
|
|
#include "config.h"
|
|
#include "json.h"
|
|
#include <ccan/list/list.h>
|
|
|
|
/* Context for a command (from JSON, but might outlive the connection!)
|
|
* You can allocate off this for temporary objects. */
|
|
struct command {
|
|
/* The global state */
|
|
struct lightningd_state *dstate;
|
|
/* The 'id' which we need to include in the response. */
|
|
const char *id;
|
|
/* The connection, or NULL if it closed. */
|
|
struct json_connection *jcon;
|
|
};
|
|
|
|
struct json_connection {
|
|
/* The global state */
|
|
struct lightningd_state *dstate;
|
|
|
|
/* 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;
|
|
|
|
/* Current command. */
|
|
struct command *current;
|
|
|
|
struct list_head output;
|
|
const char *outbuf;
|
|
};
|
|
|
|
struct json_command {
|
|
const char *name;
|
|
void (*dispatch)(struct command *,
|
|
const char *buffer, const jsmntok_t *params);
|
|
const char *description;
|
|
const char *help;
|
|
};
|
|
|
|
void command_success(struct command *cmd, struct json_result *response);
|
|
void PRINTF_FMT(2, 3) command_fail(struct command *cmd, const char *fmt, ...);
|
|
|
|
/* For initialization */
|
|
void setup_jsonrpc(struct lightningd_state *dstate, const char *rpc_filename);
|
|
|
|
/* Commands (from other files) */
|
|
extern const struct json_command connect_command;
|
|
extern const struct json_command getpeers_command;
|
|
extern const struct json_command newhtlc_command;
|
|
extern const struct json_command fulfillhtlc_command;
|
|
extern const struct json_command failhtlc_command;
|
|
extern const struct json_command commit_command;
|
|
extern const struct json_command mocktime_command;
|
|
extern const struct json_command close_command;
|
|
#endif /* LIGHTNING_DAEMON_JSONRPC_H */
|