| 964 | } |
| 965 | |
| 966 | static struct command_result *json_fundchannel_complete(struct command *cmd, |
| 967 | const char *buffer, |
| 968 | const jsmntok_t *obj UNNEEDED, |
| 969 | const jsmntok_t *params) |
| 970 | { |
| 971 | u8 *msg; |
| 972 | struct node_id *id; |
| 973 | struct bitcoin_txid *funding_txid; |
| 974 | struct peer *peer; |
| 975 | struct wally_psbt *funding_psbt; |
| 976 | u32 *funding_txout_num = NULL; |
| 977 | struct funding_channel *fc; |
| 978 | |
| 979 | if (!param(cmd, buffer, params, |
| 980 | p_req("id", param_node_id, &id), |
| 981 | p_req("psbt", param_psbt, &funding_psbt), |
| 982 | NULL)) |
| 983 | return command_param_failed(); |
| 984 | |
| 985 | peer = peer_by_id(cmd->ld, id); |
| 986 | if (!peer) { |
| 987 | return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer"); |
| 988 | } |
| 989 | |
| 990 | if (peer->connected != PEER_CONNECTED) |
| 991 | return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED, |
| 992 | "Peer %s", |
| 993 | peer->connected == PEER_DISCONNECTED |
| 994 | ? "not connected" : "still connecting"); |
| 995 | |
| 996 | if (!peer->uncommitted_channel |
| 997 | || !peer->uncommitted_channel->fc |
| 998 | || !peer->uncommitted_channel->fc->inflight) |
| 999 | return command_fail(cmd, LIGHTNINGD, "No channel funding in progress."); |
| 1000 | |
| 1001 | if (peer->uncommitted_channel->fc->cmd) |
| 1002 | return command_fail(cmd, LIGHTNINGD, "Channel funding in progress."); |
| 1003 | |
| 1004 | fc = peer->uncommitted_channel->fc; |
| 1005 | |
| 1006 | /* Figure out the correct output, and perform sanity checks. */ |
| 1007 | for (size_t i = 0; i < funding_psbt->tx->num_outputs; i++) { |
| 1008 | if (memeq(funding_psbt->tx->outputs[i].script, |
| 1009 | funding_psbt->tx->outputs[i].script_len, |
| 1010 | fc->funding_scriptpubkey, |
| 1011 | tal_bytelen(fc->funding_scriptpubkey))) { |
| 1012 | if (funding_txout_num) |
| 1013 | return command_fail(cmd, FUNDING_PSBT_INVALID, |
| 1014 | "Two outputs to open channel"); |
| 1015 | funding_txout_num = tal(cmd, u32); |
| 1016 | *funding_txout_num = i; |
| 1017 | } |
| 1018 | } |
| 1019 | if (!funding_txout_num) |
| 1020 | return command_fail(cmd, FUNDING_PSBT_INVALID, |
| 1021 | "No output to open channel"); |
| 1022 | |
| 1023 | /* Can't really check amounts for elements. */ |
nothing calls this directly
no test coverage detected