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

Function json_fundchannel_complete

lightningd/opening_control.c:1040–1152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1038}
1039
1040static struct command_result *json_fundchannel_complete(struct command *cmd,
1041 const char *buffer,
1042 const jsmntok_t *obj UNNEEDED,
1043 const jsmntok_t *params)
1044{
1045 u8 *msg;
1046 struct node_id *id;
1047 struct bitcoin_txid *funding_txid;
1048 struct peer *peer;
1049 struct wally_psbt *funding_psbt;
1050 u32 *funding_txout_num = NULL;
1051 struct funding_channel *fc;
1052 bool *withhold;
1053
1054 if (!param_check(cmd, buffer, params,
1055 p_req("id", param_node_id, &id),
1056 p_req("psbt", param_psbt, &funding_psbt),
1057 p_opt_def("withhold", param_bool, &withhold, false),
1058 NULL))
1059 return command_param_failed();
1060
1061 peer = peer_by_id(cmd->ld, id);
1062 if (!peer) {
1063 return command_fail(cmd, FUNDING_UNKNOWN_PEER, "Unknown peer");
1064 }
1065
1066 if (peer->connected != PEER_CONNECTED)
1067 return command_fail(cmd, FUNDING_PEER_NOT_CONNECTED,
1068 "Peer %s",
1069 peer->connected == PEER_DISCONNECTED
1070 ? "not connected" : "still connecting");
1071
1072 if (!peer->uncommitted_channel
1073 || !peer->uncommitted_channel->fc
1074 || !peer->uncommitted_channel->fc->inflight)
1075 return command_fail(cmd, LIGHTNINGD, "No channel funding in progress.");
1076
1077 if (peer->uncommitted_channel->fc->cmd)
1078 return command_fail(cmd, LIGHTNINGD, "Channel funding in progress.");
1079
1080 fc = peer->uncommitted_channel->fc;
1081
1082 /* We only deal with V2 internally */
1083 if (!psbt_set_version(funding_psbt, 2)) {
1084 return command_fail(cmd, LIGHTNINGD, "Could not set PSBT version.");
1085 }
1086
1087 /* Figure out the correct output, and perform sanity checks. */
1088 for (size_t i = 0; i < funding_psbt->num_outputs; i++) {
1089 if (memeq(funding_psbt->outputs[i].script,
1090 funding_psbt->outputs[i].script_len,
1091 fc->funding_scriptpubkey,
1092 tal_bytelen(fc->funding_scriptpubkey))) {
1093 if (funding_txout_num)
1094 return command_fail(cmd, FUNDING_PSBT_INVALID,
1095 "Two outputs to open channel");
1096 funding_txout_num = tal(cmd, u32);
1097 *funding_txout_num = i;

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
peer_by_idFunction · 0.85
psbt_set_versionFunction · 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
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
subd_send_msgFunction · 0.70

Tested by

no test coverage detected