Browse Source

daemon: add-route RPC command.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
b1ac490bea
  1. 11
      daemon/jsonrpc.c
  2. 2
      daemon/jsonrpc.h
  3. 10
      daemon/peer.c
  4. 67
      daemon/routing.c

11
daemon/jsonrpc.c

@ -264,6 +264,7 @@ static const struct json_command *cmdlist[] = {
&disconnect_command,
&signcommit_command,
&output_command,
&add_route_command,
};
static void json_help(struct command *cmd,
@ -314,6 +315,16 @@ static void json_result(struct json_connection *jcon,
io_wake(jcon);
}
struct json_result *null_response(const tal_t *ctx)
{
struct json_result *response;
response = new_json_result(ctx);
json_object_start(response, NULL);
json_object_end(response);
return response;
}
void command_success(struct command *cmd, struct json_result *result)
{
struct json_connection *jcon = cmd->jcon;

2
daemon/jsonrpc.h

@ -49,6 +49,7 @@ struct json_command {
const char *help;
};
struct json_result *null_response(const tal_t *ctx);
void command_success(struct command *cmd, struct json_result *response);
void PRINTF_FMT(2, 3) command_fail(struct command *cmd, const char *fmt, ...);
@ -69,4 +70,5 @@ extern const struct json_command disconnect_command;
extern const struct json_command signcommit_command;
extern const struct json_command output_command;
extern const struct json_command accept_payment_command;
extern const struct json_command add_route_command;
#endif /* LIGHTNING_DAEMON_JSONRPC_H */

10
daemon/peer.c

@ -75,16 +75,6 @@ static struct peer *find_peer_json(struct lightningd_state *dstate,
return find_peer(dstate, &peerid);
}
static struct json_result *null_response(const tal_t *ctx)
{
struct json_result *response;
response = new_json_result(ctx);
json_object_start(response, NULL);
json_object_end(response);
return response;
}
static bool peer_uncommitted_changes(const struct peer *peer)
{
/* Not initialized yet? */

67
daemon/routing.c

@ -1,3 +1,4 @@
#include "jsonrpc.h"
#include "lightningd.h"
#include "log.h"
#include "overflows.h"
@ -232,3 +233,69 @@ struct peer *find_route(struct lightningd_state *dstate,
return first;
}
static void json_add_route(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
jsmntok_t *srctok, *dsttok, *basetok, *vartok, *delaytok, *minblockstok;
struct pubkey src, dst;
struct node *from, *to;
u32 base, var, delay, minblocks;
if (!json_get_params(buffer, params,
"src", &srctok,
"dst", &dsttok,
"base", &basetok,
"var", &vartok,
"delay", &delaytok,
"minblocks", &minblockstok,
NULL)) {
command_fail(cmd, "Need src, dst, base, var, delay & minblocks");
return;
}
if (!pubkey_from_hexstr(cmd->dstate->secpctx,
buffer + srctok->start,
srctok->end - srctok->start, &src)) {
command_fail(cmd, "src %.*s not valid",
srctok->end - srctok->start,
buffer + srctok->start);
return;
}
if (!pubkey_from_hexstr(cmd->dstate->secpctx,
buffer + dsttok->start,
dsttok->end - dsttok->start, &dst)) {
command_fail(cmd, "dst %.*s not valid",
dsttok->end - dsttok->start,
buffer + dsttok->start);
return;
}
if (!json_tok_number(buffer, basetok, &base)
|| !json_tok_number(buffer, vartok, &var)
|| !json_tok_number(buffer, delaytok, &delay)
|| !json_tok_number(buffer, minblockstok, &minblocks)) {
command_fail(cmd,
"base, var, delay and minblocks must be numbers");
return;
}
from = get_node(cmd->dstate, &src);
if (!from)
from = new_node(cmd->dstate, &src);
to = get_node(cmd->dstate, &dst);
if (!to)
to = new_node(cmd->dstate, &dst);
add_connection(cmd->dstate, from, to, base, var, delay, minblocks);
command_success(cmd, null_response(cmd));
}
const struct json_command add_route_command = {
"add-route",
json_add_route,
"Add route from {src} to {dst}, {base} rate in msatoshi, {var} rate in msatoshi, {delay} blocks delay and {minblocks} minimum timeout",
"Returns an empty result on success"
};

Loading…
Cancel
Save