From 11da88a281fa0a88857b3611c338786b36fd2ea1 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Sat, 4 Jan 2020 21:10:04 +0100 Subject: [PATCH] common: add 2 specific error codes wrt funding Add "peer not connected" and "unknown peer" as error codes, so that users can check against numeric error codes instead of textual error messages. Will ease https://github.com/ElementsProject/lightning/issues/3366 Changelog-None --- common/jsonrpc_errors.h | 2 ++ lightningd/opening_control.c | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/jsonrpc_errors.h b/common/jsonrpc_errors.h index 36738151e..86f58e765 100644 --- a/common/jsonrpc_errors.h +++ b/common/jsonrpc_errors.h @@ -41,6 +41,8 @@ #define FUND_OUTPUT_IS_DUST 302 #define FUNDING_BROADCAST_FAIL 303 #define FUNDING_STILL_SYNCING_BITCOIN 304 +#define FUNDING_PEER_NOT_CONNECTED 305 +#define FUNDING_UNKNOWN_PEER 306 /* Errors from `invoice` command */ #define INVOICE_LABEL_ALREADY_EXISTS 900 diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index aed9f877a..614293484 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -1024,7 +1024,7 @@ static struct command_result *json_fund_channel_complete(struct command *cmd, funding_txout = *funding_txout_num; peer = peer_by_id(cmd->ld, id); if (!peer) { - return command_fail(cmd, LIGHTNINGD, "Unknown peer"); + return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); } channel = peer_active_channel(peer); @@ -1033,7 +1033,8 @@ static struct command_result *json_fund_channel_complete(struct command *cmd, channel_state_name(channel)); if (!peer->uncommitted_channel) - return command_fail(cmd, LIGHTNINGD, "Peer not connected"); + return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, + "Peer not connected"); if (!peer->uncommitted_channel->fc || !peer->uncommitted_channel->fc->inflight) return command_fail(cmd, LIGHTNINGD, "No channel funding in progress."); @@ -1071,7 +1072,7 @@ static struct command_result *json_fund_channel_cancel(struct command *cmd, peer = peer_by_id(cmd->ld, id); if (!peer) { - return command_fail(cmd, LIGHTNINGD, "Unknown peer"); + return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); } if (peer->uncommitted_channel) { @@ -1185,7 +1186,7 @@ static struct command_result *json_fund_channel_start(struct command *cmd, peer = peer_by_id(cmd->ld, id); if (!peer) { - return command_fail(cmd, LIGHTNINGD, "Unknown peer"); + return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); } channel = peer_active_channel(peer); @@ -1195,7 +1196,8 @@ static struct command_result *json_fund_channel_start(struct command *cmd, } if (!peer->uncommitted_channel) { - return command_fail(cmd, LIGHTNINGD, "Peer not connected"); + return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, + "Peer not connected"); } if (peer->uncommitted_channel->fc) {