mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
daemon: new command gethtlcs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
b0278d7152
commit
7550ec23ec
3 changed files with 74 additions and 0 deletions
|
@ -282,6 +282,7 @@ static const struct json_command *cmdlist[] = {
|
||||||
&getlog_command,
|
&getlog_command,
|
||||||
&connect_command,
|
&connect_command,
|
||||||
&getpeers_command,
|
&getpeers_command,
|
||||||
|
&gethtlcs_command,
|
||||||
&newhtlc_command,
|
&newhtlc_command,
|
||||||
&fulfillhtlc_command,
|
&fulfillhtlc_command,
|
||||||
&failhtlc_command,
|
&failhtlc_command,
|
||||||
|
|
|
@ -59,6 +59,7 @@ void setup_jsonrpc(struct lightningd_state *dstate, const char *rpc_filename);
|
||||||
/* Commands (from other files) */
|
/* Commands (from other files) */
|
||||||
extern const struct json_command connect_command;
|
extern const struct json_command connect_command;
|
||||||
extern const struct json_command getpeers_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 newhtlc_command;
|
||||||
extern const struct json_command fulfillhtlc_command;
|
extern const struct json_command fulfillhtlc_command;
|
||||||
extern const struct json_command failhtlc_command;
|
extern const struct json_command failhtlc_command;
|
||||||
|
|
|
@ -4227,6 +4227,78 @@ const struct json_command getpeers_command = {
|
||||||
"Returns a 'peers' array"
|
"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. */
|
/* To avoid freeing underneath ourselves, we free outside event loop. */
|
||||||
void cleanup_peers(struct lightningd_state *dstate)
|
void cleanup_peers(struct lightningd_state *dstate)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue