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

Function json_openchannel_init

lightningd/dual_open_control.c:3192–3326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3190}
3191
3192static struct command_result *json_openchannel_init(struct command *cmd,
3193 const char *buffer,
3194 const jsmntok_t *obj UNNEEDED,
3195 const jsmntok_t *params)
3196{
3197 struct openchannel_init_info *info = tal(cmd, struct openchannel_init_info);
3198 struct peer *peer;
3199 struct amount_sat psbt_val;
3200 struct command_result *res;
3201
3202 info->cmd = cmd;
3203 if (!param_check(cmd, buffer, params,
3204 p_req("id", param_node_id, &info->id),
3205 p_req("amount", param_sat, &info->amount),
3206 p_req("initialpsbt", param_psbt, &info->psbt),
3207 p_opt("commitment_feerate", param_feerate, &info->feerate_per_kw),
3208 p_opt("funding_feerate", param_feerate, &info->feerate_per_kw_funding),
3209 p_opt_def("announce", param_bool, &info->announce_channel, true),
3210 p_opt("close_to", param_bitcoin_address, &info->our_upfront_shutdown_script),
3211 p_opt_def("request_amt", param_sat, &info->request_amt, AMOUNT_SAT(0)),
3212 p_opt("compact_lease", param_lease_hex, &info->rates),
3213 p_opt("channel_type", param_channel_type, &info->ctype),
3214 NULL))
3215 return command_param_failed();
3216
3217 /* We only deal in v2 */
3218 if (!psbt_set_version(info->psbt, 2)) {
3219 return command_fail(cmd, LIGHTNINGD, "Could not set PSBT version.");
3220 }
3221
3222 /* Gotta expect some rates ! */
3223 if (!amount_sat_is_zero(*info->request_amt) && !info->rates)
3224 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
3225 "Must pass in 'compact_lease' if requesting"
3226 " funds from peer");
3227 psbt_val = AMOUNT_SAT(0);
3228 for (size_t i = 0; i < info->psbt->num_inputs; i++) {
3229 struct amount_sat in_amt = psbt_input_get_amount(info->psbt, i);
3230 if (!amount_sat_add(&psbt_val, psbt_val, in_amt))
3231 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
3232 "Overflow in adding PSBT input"
3233 " values. %s",
3234 fmt_wally_psbt(tmpctx, info->psbt));
3235 }
3236
3237 /* If they don't pass in at least enough in the PSBT to cover
3238 * their amount, nope */
3239 if (!amount_sat_greater(psbt_val, *info->amount))
3240 return command_fail(cmd, FUND_CANNOT_AFFORD,
3241 "Provided PSBT cannot afford funding of "
3242 "amount %s. %s",
3243 fmt_amount_sat(tmpctx, *info->amount),
3244 fmt_wally_psbt(tmpctx, info->psbt));
3245
3246 res = init_set_feerate(cmd, &info->feerate_per_kw, &info->feerate_per_kw_funding);
3247 if (res)
3248 return res;
3249

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
psbt_set_versionFunction · 0.85
amount_sat_is_zeroFunction · 0.85
psbt_input_get_amountFunction · 0.85
fmt_wally_psbtFunction · 0.85
amount_sat_greaterFunction · 0.85
init_set_feerateFunction · 0.85
peer_by_idFunction · 0.85
feature_negotiatedFunction · 0.85
desired_channel_typeFunction · 0.85
channel_type_acceptFunction · 0.85
psbt_add_serialsFunction · 0.85

Tested by

no test coverage detected