| 3471 | } |
| 3472 | |
| 3473 | static struct command_result *json_openchannel_init(struct command *cmd, |
| 3474 | const char *buffer, |
| 3475 | const jsmntok_t *obj UNNEEDED, |
| 3476 | const jsmntok_t *params) |
| 3477 | { |
| 3478 | struct openchannel_init_info *info = tal(cmd, struct openchannel_init_info); |
| 3479 | struct peer *peer; |
| 3480 | struct amount_sat psbt_val; |
| 3481 | struct command_result *res; |
| 3482 | |
| 3483 | info->cmd = cmd; |
| 3484 | if (!param_check(cmd, buffer, params, |
| 3485 | p_req("id", param_node_id, &info->id), |
| 3486 | p_req("amount", param_sat, &info->amount), |
| 3487 | p_req("initialpsbt", param_psbt, &info->psbt), |
| 3488 | p_opt("commitment_feerate", param_feerate, &info->feerate_per_kw), |
| 3489 | p_opt("funding_feerate", param_feerate, &info->feerate_per_kw_funding), |
| 3490 | p_opt_def("announce", param_bool, &info->announce_channel, true), |
| 3491 | p_opt("close_to", param_bitcoin_address, &info->our_upfront_shutdown_script), |
| 3492 | p_opt_def("request_amt", param_sat, &info->request_amt, AMOUNT_SAT(0)), |
| 3493 | p_opt("compact_lease", param_lease_hex, &info->rates), |
| 3494 | p_opt("channel_type", param_channel_type, &info->ctype), |
| 3495 | NULL)) |
| 3496 | return command_param_failed(); |
| 3497 | |
| 3498 | /* We only deal in v2 */ |
| 3499 | if (!psbt_set_version(info->psbt, 2)) { |
| 3500 | return command_fail(cmd, LIGHTNINGD, "Could not set PSBT version."); |
| 3501 | } |
| 3502 | |
| 3503 | /* Gotta expect some rates ! */ |
| 3504 | if (!amount_sat_is_zero(*info->request_amt) && !info->rates) |
| 3505 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 3506 | "Must pass in 'compact_lease' if requesting" |
| 3507 | " funds from peer"); |
| 3508 | psbt_val = AMOUNT_SAT(0); |
| 3509 | for (size_t i = 0; i < info->psbt->num_inputs; i++) { |
| 3510 | struct amount_sat in_amt = psbt_input_get_amount(info->psbt, i); |
| 3511 | if (!amount_sat_add(&psbt_val, psbt_val, in_amt)) |
| 3512 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 3513 | "Overflow in adding PSBT input" |
| 3514 | " values. %s", |
| 3515 | fmt_wally_psbt(tmpctx, info->psbt)); |
| 3516 | } |
| 3517 | |
| 3518 | /* If they don't pass in at least enough in the PSBT to cover |
| 3519 | * their amount, nope */ |
| 3520 | if (!amount_sat_greater(psbt_val, *info->amount)) |
| 3521 | return command_fail(cmd, FUND_CANNOT_AFFORD, |
| 3522 | "Provided PSBT cannot afford funding of " |
| 3523 | "amount %s. %s", |
| 3524 | fmt_amount_sat(tmpctx, *info->amount), |
| 3525 | fmt_wally_psbt(tmpctx, info->psbt)); |
| 3526 | |
| 3527 | res = init_set_feerate(cmd, &info->feerate_per_kw, &info->feerate_per_kw_funding); |
| 3528 | if (res) |
| 3529 | return res; |
| 3530 |
nothing calls this directly
no test coverage detected