Browse Source

daemon: new command gethtlcs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
7550ec23ec
  1. 1
      daemon/jsonrpc.c
  2. 1
      daemon/jsonrpc.h
  3. 72
      daemon/peer.c

1
daemon/jsonrpc.c

@ -282,6 +282,7 @@ static const struct json_command *cmdlist[] = {
&getlog_command,
&connect_command,
&getpeers_command,
&gethtlcs_command,
&newhtlc_command,
&fulfillhtlc_command,
&failhtlc_command,

1
daemon/jsonrpc.h

@ -59,6 +59,7 @@ 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 gethtlcs_command;
extern const struct json_command newhtlc_command;
extern const struct json_command fulfillhtlc_command;
extern const struct json_command failhtlc_command;

72
daemon/peer.c

@ -4227,6 +4227,78 @@ const struct json_command getpeers_command = {
"Returns a 'peers' array"
};
static void json_gethtlcs(struct command *cmd,
const char *buffer, const jsmntok_t *params)
{
struct peer *peer;
jsmntok_t *peeridtok, *resolvedtok;
bool resolved = false;
struct json_result *response = new_json_result(cmd);
struct htlc *h;
struct htlc_map_iter it;
if (!json_get_params(buffer, params,
"peerid", &peeridtok,
"?resolved", &resolvedtok,
NULL)) {
command_fail(cmd, "Need peerid");
return;
}
peer = find_peer_json(cmd->dstate, buffer, peeridtok);
if (!peer) {
command_fail(cmd, "Could not find peer with that peerid");
return;
}
if (resolvedtok && !json_tok_bool(buffer, resolvedtok, &resolved)) {
command_fail(cmd, "resolved must be true or false");
return;
}
json_object_start(response, NULL);
json_array_start(response, "htlcs");
for (h = htlc_map_first(&peer->htlcs, &it);
h; h = htlc_map_next(&peer->htlcs, &it)) {
if (htlc_is_dead(h) && !resolved)
continue;
json_object_start(response, NULL);
json_add_u64(response, "id", h->id);
json_add_string(response, "state", htlc_state_name(h->state));
json_add_u64(response, "msatoshis", h->msatoshis);
json_add_abstime(response, "expiry", &h->expiry);
json_add_hex(response, "rhash", &h->rhash, sizeof(h->rhash));
if (h->r)
json_add_hex(response, "r", h->r, sizeof(*h->r));
if (htlc_owner(h) == LOCAL) {
json_add_num(response, "deadline", h->deadline);
if (h->src) {
json_object_start(response, "src");
json_add_pubkey(response, cmd->dstate->secpctx,
"peerid", h->src->peer->id);
json_add_u64(response, "id", h->src->id);
json_object_end(response);
}
} else {
if (h->routing)
json_add_hex(response, "routing",
h->routing, tal_count(h->routing));
}
json_object_end(response);
}
json_array_end(response);
json_object_end(response);
command_success(cmd, response);
}
const struct json_command gethtlcs_command = {
"gethtlcs",
json_gethtlcs,
"List HTLCs for {peer}; all if {resolved} is true.",
"Returns a 'htlcs' array"
};
/* To avoid freeing underneath ourselves, we free outside event loop. */
void cleanup_peers(struct lightningd_state *dstate)
{

Loading…
Cancel
Save