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

Function json_fundchannel_complete

lightningd/opening_control.c:1030–1142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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