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

Function json_fundpsbt

wallet/reservation.c:460–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458}
459
460static struct command_result *json_fundpsbt(struct command *cmd,
461 const char *buffer,
462 const jsmntok_t *obj UNNEEDED,
463 const jsmntok_t *params)
464{
465 struct utxo **utxos;
466 u32 *feerate_per_kw;
467 u32 *minconf, *weight, *min_witness_weight;
468 struct amount_sat *amount, input, diff;
469 bool all, *excess_as_change;
470 u32 *locktime, *reserve, maxheight;
471
472 if (!param(cmd, buffer, params,
473 p_req("satoshi", param_sat_or_all, &amount),
474 p_req("feerate", param_feerate, &feerate_per_kw),
475 p_req("startweight", param_number, &weight),
476 p_opt_def("minconf", param_number, &minconf, 1),
477 p_opt_def("reserve", param_reserve_num, &reserve,
478 RESERVATION_DEFAULT),
479 p_opt("locktime", param_number, &locktime),
480 p_opt_def("min_witness_weight", param_number,
481 &min_witness_weight, 0),
482 p_opt_def("excess_as_change", param_bool,
483 &excess_as_change, false),
484 NULL))
485 return command_param_failed();
486
487 all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL));
488 maxheight = minconf_to_maxheight(*minconf, cmd->ld);
489
490 /* We keep adding until we meet their output requirements. */
491 utxos = tal_arr(cmd, struct utxo *, 0);
492
493 input = AMOUNT_SAT(0);
494 while (!inputs_sufficient(input, *amount, *feerate_per_kw, *weight,
495 &diff)) {
496 struct utxo *utxo;
497 struct amount_sat fee;
498 u32 utxo_weight;
499
500 utxo = wallet_find_utxo(utxos, cmd->ld->wallet,
501 cmd->ld->topology->tip->height,
502 &diff,
503 *feerate_per_kw,
504 maxheight,
505 cast_const2(const struct utxo **, utxos));
506 if (utxo) {
507 utxo_weight = utxo_spend_weight(utxo,
508 *min_witness_weight);
509 fee = amount_tx_fee(*feerate_per_kw, utxo_weight);
510
511 /* Uneconomic to add this utxo, skip it */
512 if (!all && amount_sat_greater_eq(fee, utxo->amount))
513 continue;
514
515 tal_arr_expand(&utxos, utxo);
516
517 /* It supplies more input. */

Callers

nothing calls this directly

Calls 14

minconf_to_maxheightFunction · 0.85
inputs_sufficientFunction · 0.85
wallet_find_utxoFunction · 0.85
utxo_spend_weightFunction · 0.85
topology_syncedFunction · 0.85
finish_psbtFunction · 0.85
paramFunction · 0.50
command_param_failedFunction · 0.50
amount_sat_eqFunction · 0.50
amount_tx_feeFunction · 0.50
amount_sat_greater_eqFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected