Browse Source

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
travis-debug
Vasil Dimov 5 years ago
committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
commit
11da88a281
  1. 2
      common/jsonrpc_errors.h
  2. 12
      lightningd/opening_control.c

2
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

12
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) {

Loading…
Cancel
Save