Skip to content

Commit

Permalink
json-rpc: add rpc to provide bound alt-addr
Browse files Browse the repository at this point in the history
Signed-off-by: Max Rantil <[email protected]>
  • Loading branch information
maxrantil committed Jul 22, 2024
1 parent e5fb0f0 commit 81bbeaa
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lightningd/channel_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -2361,3 +2361,56 @@ static const struct json_command dev_quiesce_command = {
.dev_only = true,
};
AUTODATA(json_command, &dev_quiesce_command);

static struct command_result *json_alt_addr(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct node_id *p_id;
struct peer *peer;
struct channel *channel;
const char *our_alt_addr;
bool more_than_one;

if (!param_check(cmd, buffer, params,
p_req("node_id", param_node_id, &p_id),
p_req("alt_addr", param_string, &our_alt_addr),
NULL))
return command_param_failed();

peer = peer_by_id(cmd->ld, p_id);
if (!peer) {
return command_fail(cmd, JSONRPC2_INVALID_REQUEST,
"No such peer: %s",
fmt_node_id(cmd, p_id));
}

channel = peer_any_channel(peer, channel_state_can_add_htlc, &more_than_one);
if (!channel || !channel->owner)
return command_fail(cmd, LIGHTNINGD, "Peer bad state");
/* This is a dev command: fix the api if you need this! */
if (more_than_one)
return command_fail(cmd, LIGHTNINGD, "More than one channel");

if (command_check_only(cmd))
return command_check_done(cmd);

u8 *msg = towire_channeld_peer_alt_addr(peer, (u8 *)our_alt_addr);
subd_send_msg(channel->owner, take(msg));

wallet_add_alt_addr(cmd->ld->wallet->db, p_id, our_alt_addr, true);

/* FIXME(maxrantil), We need to add this to 'listnodes' command too! */

return command_success(cmd, json_stream_success(cmd));
}

static const struct json_command alt_addr_command = {
"alt-addr",
"developer",
json_alt_addr,
"Select an alternative private address for peer-to-peer connections",
.dev_only = true,
};
AUTODATA(json_command, &alt_addr_command);

0 comments on commit 81bbeaa

Please sign in to comment.