| 2585 | } |
| 2586 | |
| 2587 | static struct command_result *json_openchannel_init(struct command *cmd, |
| 2588 | const char *buffer, |
| 2589 | const jsmntok_t *obj UNNEEDED, |
| 2590 | const jsmntok_t *params) |
| 2591 | { |
| 2592 | struct node_id *id; |
| 2593 | struct peer *peer; |
| 2594 | struct channel *channel; |
| 2595 | bool *announce_channel; |
| 2596 | u32 *feerate_per_kw_funding; |
| 2597 | u32 *feerate_per_kw; |
| 2598 | struct amount_sat *amount, psbt_val, *request_amt; |
| 2599 | struct wally_psbt *psbt; |
| 2600 | const u8 *our_upfront_shutdown_script; |
| 2601 | u32 *our_upfront_shutdown_script_wallet_index; |
| 2602 | struct open_attempt *oa; |
| 2603 | struct lease_rates *rates; |
| 2604 | struct command_result *res; |
| 2605 | int fds[2]; |
| 2606 | |
| 2607 | if (!param(cmd, buffer, params, |
| 2608 | p_req("id", param_node_id, &id), |
| 2609 | p_req("amount", param_sat, &amount), |
| 2610 | p_req("initialpsbt", param_psbt, &psbt), |
| 2611 | p_opt("commitment_feerate", param_feerate, &feerate_per_kw), |
| 2612 | p_opt("funding_feerate", param_feerate, &feerate_per_kw_funding), |
| 2613 | p_opt_def("announce", param_bool, &announce_channel, true), |
| 2614 | p_opt("close_to", param_bitcoin_address, &our_upfront_shutdown_script), |
| 2615 | p_opt_def("request_amt", param_sat, &request_amt, AMOUNT_SAT(0)), |
| 2616 | p_opt("compact_lease", param_lease_hex, &rates), |
| 2617 | NULL)) |
| 2618 | return command_param_failed(); |
| 2619 | |
| 2620 | /* Gotta expect some rates ! */ |
| 2621 | if (!amount_sat_zero(*request_amt) && !rates) |
| 2622 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2623 | "Must pass in 'compact_lease' if requesting" |
| 2624 | " funds from peer"); |
| 2625 | psbt_val = AMOUNT_SAT(0); |
| 2626 | for (size_t i = 0; i < psbt->num_inputs; i++) { |
| 2627 | struct amount_sat in_amt = psbt_input_get_amount(psbt, i); |
| 2628 | if (!amount_sat_add(&psbt_val, psbt_val, in_amt)) |
| 2629 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2630 | "Overflow in adding PSBT input" |
| 2631 | " values. %s", |
| 2632 | type_to_string(tmpctx, |
| 2633 | struct wally_psbt, |
| 2634 | psbt)); |
| 2635 | } |
| 2636 | |
| 2637 | /* If they don't pass in at least enough in the PSBT to cover |
| 2638 | * their amount, nope */ |
| 2639 | if (!amount_sat_greater(psbt_val, *amount)) |
| 2640 | return command_fail(cmd, FUND_CANNOT_AFFORD, |
| 2641 | "Provided PSBT cannot afford funding of " |
| 2642 | "amount %s. %s", |
| 2643 | type_to_string(tmpctx, |
| 2644 | struct amount_sat, |
nothing calls this directly
no test coverage detected