|
@ -699,6 +699,7 @@ static void opener_psbt_changed(struct subd *dualopend, |
|
|
json_add_psbt(response, "psbt", psbt); |
|
|
json_add_psbt(response, "psbt", psbt); |
|
|
json_add_bool(response, "commitments_secured", false); |
|
|
json_add_bool(response, "commitments_secured", false); |
|
|
|
|
|
|
|
|
|
|
|
uc->cid = cid; |
|
|
uc->fc->inflight = true; |
|
|
uc->fc->inflight = true; |
|
|
uc->fc->cmd = NULL; |
|
|
uc->fc->cmd = NULL; |
|
|
was_pending(command_success(cmd, response)); |
|
|
was_pending(command_success(cmd, response)); |
|
@ -1009,32 +1010,25 @@ static struct command_result *json_open_channel_signed(struct command *cmd, |
|
|
const jsmntok_t *params) |
|
|
const jsmntok_t *params) |
|
|
{ |
|
|
{ |
|
|
struct wally_psbt *psbt; |
|
|
struct wally_psbt *psbt; |
|
|
struct node_id *id; |
|
|
struct channel_id *cid; |
|
|
struct peer *peer; |
|
|
|
|
|
struct channel *channel; |
|
|
struct channel *channel; |
|
|
struct bitcoin_txid txid; |
|
|
struct bitcoin_txid txid; |
|
|
|
|
|
|
|
|
if (!param(cmd, buffer, params, |
|
|
if (!param(cmd, buffer, params, |
|
|
p_req("id", param_node_id, &id), |
|
|
p_req("channel_id", param_channel_id, &cid), |
|
|
p_req("signed_psbt", param_psbt, &psbt), |
|
|
p_req("signed_psbt", param_psbt, &psbt), |
|
|
NULL)) |
|
|
NULL)) |
|
|
return command_param_failed(); |
|
|
return command_param_failed(); |
|
|
|
|
|
|
|
|
peer = peer_by_id(cmd->ld, id); |
|
|
channel = channel_by_cid(cmd->ld, cid, NULL); |
|
|
if (!peer) |
|
|
|
|
|
return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); |
|
|
|
|
|
|
|
|
|
|
|
channel = peer_active_channel(peer); |
|
|
|
|
|
if (!channel) |
|
|
if (!channel) |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, |
|
|
"Peer has no active channel"); |
|
|
"Unknown channel"); |
|
|
|
|
|
|
|
|
if (!channel->pps) |
|
|
if (!channel->pps) |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
"Missing per-peer-state for channel, " |
|
|
"Missing per-peer-state for channel, " |
|
|
"are you in the right state to call " |
|
|
"are you in the right state to call " |
|
|
"this method?"); |
|
|
"this method?"); |
|
|
|
|
|
|
|
|
if (channel->psbt) |
|
|
if (channel->psbt) |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
"Already have a finalized PSBT for " |
|
|
"Already have a finalized PSBT for " |
|
@ -1053,7 +1047,6 @@ static struct command_result *json_open_channel_signed(struct command *cmd, |
|
|
type_to_string(tmpctx, struct bitcoin_txid, |
|
|
type_to_string(tmpctx, struct bitcoin_txid, |
|
|
&txid)); |
|
|
&txid)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Go ahead and try to finalize things, or what we can */ |
|
|
/* Go ahead and try to finalize things, or what we can */ |
|
|
psbt_finalize(psbt); |
|
|
psbt_finalize(psbt); |
|
|
|
|
|
|
|
@ -1082,47 +1075,48 @@ static struct command_result *json_open_channel_update(struct command *cmd, |
|
|
const jsmntok_t *params) |
|
|
const jsmntok_t *params) |
|
|
{ |
|
|
{ |
|
|
struct wally_psbt *psbt; |
|
|
struct wally_psbt *psbt; |
|
|
struct node_id *id; |
|
|
struct channel_id *cid; |
|
|
struct peer *peer; |
|
|
|
|
|
struct channel *channel; |
|
|
struct channel *channel; |
|
|
|
|
|
struct uncommitted_channel *uc; |
|
|
u8 *msg; |
|
|
u8 *msg; |
|
|
|
|
|
|
|
|
if (!param(cmd, buffer, params, |
|
|
if (!param(cmd, buffer, params, |
|
|
p_req("id", param_node_id, &id), |
|
|
p_req("channel_id", param_channel_id, &cid), |
|
|
p_req("psbt", param_psbt, &psbt), |
|
|
p_req("psbt", param_psbt, &psbt), |
|
|
NULL)) |
|
|
NULL)) |
|
|
return command_param_failed(); |
|
|
return command_param_failed(); |
|
|
|
|
|
|
|
|
peer = peer_by_id(cmd->ld, id); |
|
|
/* We expect this to return NULL, as the channel hasn't been
|
|
|
if (!peer) |
|
|
* created yet. Instead, the uncommitted channel is populated */ |
|
|
return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); |
|
|
channel = channel_by_cid(cmd->ld, cid, &uc); |
|
|
|
|
|
|
|
|
channel = peer_active_channel(peer); |
|
|
|
|
|
if (channel) |
|
|
if (channel) |
|
|
return command_fail(cmd, LIGHTNINGD, "Peer already %s", |
|
|
return command_fail(cmd, LIGHTNINGD, "Channel already %s", |
|
|
channel_state_name(channel)); |
|
|
channel_state_name(channel)); |
|
|
|
|
|
|
|
|
if (!peer->uncommitted_channel) |
|
|
if (!uc) |
|
|
return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, |
|
|
return command_fail(cmd, FUNDING_UNKNOWN_CHANNEL, |
|
|
"Peer not connected"); |
|
|
"Unknown channel"); |
|
|
|
|
|
|
|
|
if (!peer->uncommitted_channel->fc || !peer->uncommitted_channel->fc->inflight) |
|
|
if (!uc->fc || !uc->fc->inflight) |
|
|
return command_fail(cmd, LIGHTNINGD, "No channel funding in progress"); |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
|
|
|
"No channel funding in progress"); |
|
|
|
|
|
|
|
|
if (peer->uncommitted_channel->fc->cmd) |
|
|
if (uc->fc->cmd) |
|
|
return command_fail(cmd, LIGHTNINGD, "Channel funding in progress"); |
|
|
return command_fail(cmd, LIGHTNINGD, |
|
|
|
|
|
"Channel funding in progress"); |
|
|
|
|
|
|
|
|
/* Add serials to PSBT */ |
|
|
/* Add serials to PSBT */ |
|
|
psbt_add_serials(psbt, TX_INITIATOR); |
|
|
psbt_add_serials(psbt, TX_INITIATOR); |
|
|
if (!psbt_has_required_fields(psbt)) |
|
|
if (!psbt_has_required_fields(psbt)) |
|
|
return command_fail(cmd, FUNDING_PSBT_INVALID, |
|
|
return command_fail(cmd, FUNDING_PSBT_INVALID, |
|
|
"PSBT is missing required fields %s", |
|
|
"PSBT is missing required fields %s", |
|
|
type_to_string(tmpctx, struct wally_psbt, psbt)); |
|
|
type_to_string(tmpctx, struct wally_psbt, |
|
|
|
|
|
psbt)); |
|
|
|
|
|
|
|
|
peer->uncommitted_channel->fc->cmd = cmd; |
|
|
uc->fc->cmd = cmd; |
|
|
|
|
|
|
|
|
msg = towire_dual_open_psbt_updated(NULL, psbt); |
|
|
msg = towire_dual_open_psbt_updated(NULL, psbt); |
|
|
subd_send_msg(peer->uncommitted_channel->open_daemon, take(msg)); |
|
|
subd_send_msg(uc->open_daemon, take(msg)); |
|
|
return command_still_pending(cmd); |
|
|
return command_still_pending(cmd); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|