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

Function json_openchannel_init

lightningd/dual_open_control.c:2587–2788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2585}
2586
2587static 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,

Callers

nothing calls this directly

Calls 15

amount_sat_zeroFunction · 0.85
amount_sat_greaterFunction · 0.85
init_set_feerateFunction · 0.85
topology_syncedFunction · 0.85
peer_by_idFunction · 0.85
peer_any_unsaved_channelFunction · 0.85
derive_tmp_channel_idFunction · 0.85
psbt_add_serialsFunction · 0.85
psbt_has_required_fieldsFunction · 0.85
new_channel_open_attemptFunction · 0.85
log_infoClass · 0.85
wallet_can_spendFunction · 0.85

Tested by

no test coverage detected