mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
channel: remove 'uncommitted_channel' from channel lookup
We're going to be removing "uncommitted_channel" from v2 open stat
This commit is contained in:
parent
4baa10ef68
commit
50b8655cbe
@ -441,30 +441,24 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid)
|
||||
}
|
||||
|
||||
struct channel *channel_by_cid(struct lightningd *ld,
|
||||
const struct channel_id *cid,
|
||||
struct uncommitted_channel **uc)
|
||||
const struct channel_id *cid)
|
||||
{
|
||||
struct peer *p;
|
||||
struct channel *channel;
|
||||
|
||||
list_for_each(&ld->peers, p, list) {
|
||||
if (p->uncommitted_channel) {
|
||||
if (channel_id_eq(&p->uncommitted_channel->cid, cid)) {
|
||||
if (uc)
|
||||
*uc = p->uncommitted_channel;
|
||||
/* We can't use this method for old, uncommitted
|
||||
* channels; there's no "channel" struct here! */
|
||||
if (channel_id_eq(&p->uncommitted_channel->cid, cid))
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
list_for_each(&p->channels, channel, list) {
|
||||
if (channel_id_eq(&channel->cid, cid)) {
|
||||
if (uc)
|
||||
*uc = p->uncommitted_channel;
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uc)
|
||||
*uc = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -311,10 +311,9 @@ struct channel *active_channel_by_scid(struct lightningd *ld,
|
||||
struct channel *any_channel_by_scid(struct lightningd *ld,
|
||||
const struct short_channel_id *scid);
|
||||
|
||||
/* Get channel by channel_id, optionally returning uncommitted_channel. */
|
||||
/* Get channel by channel_id */
|
||||
struct channel *channel_by_cid(struct lightningd *ld,
|
||||
const struct channel_id *cid,
|
||||
struct uncommitted_channel **uc);
|
||||
const struct channel_id *cid);
|
||||
|
||||
void channel_set_last_tx(struct channel *channel,
|
||||
struct bitcoin_tx *tx,
|
||||
|
@ -1702,7 +1702,6 @@ json_openchannel_signed(struct command *cmd,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
struct wally_psbt *psbt;
|
||||
struct uncommitted_channel *uc;
|
||||
struct channel_id *cid;
|
||||
struct channel *channel;
|
||||
struct bitcoin_txid txid;
|
||||
@ -1713,11 +1712,7 @@ json_openchannel_signed(struct command *cmd,
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
channel = channel_by_cid(cmd->ld, cid, &uc);
|
||||
if (uc)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Commitments for this channel not "
|
||||
"yet secured, see `openchannel_update`");
|
||||
channel = channel_by_cid(cmd->ld, cid);
|
||||
if (!channel)
|
||||
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
|
||||
"Unknown channel");
|
||||
@ -1729,8 +1724,7 @@ json_openchannel_signed(struct command *cmd,
|
||||
"this channel");
|
||||
if (channel->openchannel_signed_cmd)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Already sent sigs, waiting for"
|
||||
" peer's");
|
||||
"Already sent sigs, waiting for peer's");
|
||||
|
||||
/* Verify that the psbt's txid matches that of the
|
||||
* funding txid for this channel */
|
||||
@ -1786,7 +1780,6 @@ static struct command_result *json_openchannel_update(struct command *cmd,
|
||||
struct wally_psbt *psbt;
|
||||
struct channel_id *cid;
|
||||
struct channel *channel;
|
||||
struct uncommitted_channel *uc;
|
||||
u8 *msg;
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
@ -1795,27 +1788,13 @@ static struct command_result *json_openchannel_update(struct command *cmd,
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
/* We expect this to return NULL, as the channel hasn't been
|
||||
* created yet. Instead, the uncommitted channel is populated */
|
||||
channel = channel_by_cid(cmd->ld, cid, &uc);
|
||||
if (channel)
|
||||
return command_fail(cmd, LIGHTNINGD, "Channel already %s",
|
||||
channel_state_name(channel));
|
||||
|
||||
if (!uc)
|
||||
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL,
|
||||
channel = channel_by_cid(cmd->ld, cid);
|
||||
if (!channel)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Unknown channel %s",
|
||||
type_to_string(tmpctx, struct channel_id,
|
||||
cid));
|
||||
|
||||
if (!uc->fc || !uc->fc->inflight)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"No channel funding in progress");
|
||||
|
||||
if (uc->fc->cmd)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"Channel funding in progress");
|
||||
|
||||
/* Add serials to PSBT */
|
||||
psbt_add_serials(psbt, TX_INITIATOR);
|
||||
if (!psbt_has_required_fields(psbt))
|
||||
@ -1824,10 +1803,9 @@ static struct command_result *json_openchannel_update(struct command *cmd,
|
||||
type_to_string(tmpctx, struct wally_psbt,
|
||||
psbt));
|
||||
|
||||
uc->fc->cmd = cmd;
|
||||
|
||||
msg = towire_dualopend_psbt_updated(NULL, psbt);
|
||||
subd_send_msg(uc->open_daemon, take(msg));
|
||||
/* FIXME: daemon? */
|
||||
subd_send_msg(NULL, take(msg));
|
||||
return command_still_pending(cmd);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user