MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_fundchannel_complete

Function json_fundchannel_complete

lightningd/opening_control.c:966–1054  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

964}
965
966static 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. */

Callers

nothing calls this directly

Calls 12

peer_by_idFunction · 0.85
memeqFunction · 0.85
tal_bytelenFunction · 0.85
psbt_txidFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
amount_satClass · 0.70
subd_send_msgFunction · 0.70
command_still_pendingFunction · 0.70
paramFunction · 0.50
amount_sat_eqFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected