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

Function build_utxopsbt_request

plugins/funder.c:536–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534};
535
536static struct out_req *
537build_utxopsbt_request(struct command *cmd,
538 struct open_info *info,
539 struct bitcoin_outpoint **prev_outs,
540 struct amount_sat requested_funds,
541 struct amount_sat committed_funds,
542 struct funder_utxo **avail_utxos)
543{
544 struct out_req *req;
545
546 req = jsonrpc_request_start(cmd,
547 "utxopsbt",
548 &psbt_funded,
549 &psbt_fund_failed,
550 info);
551 /* Add every prev_out */
552 json_array_start(req->js, "utxos");
553 for (size_t i = 0; i < tal_count(prev_outs); i++)
554 json_add_outpoint(req->js, NULL, prev_outs[i]);
555
556 /* Next add available utxos until we surpass the
557 * requested funds goal */
558 /* FIXME: Update `utxopsbt` to automatically add more inputs? */
559 for (size_t i = 0; i < tal_count(avail_utxos); i++) {
560 /* If we've already hit our goal, break */
561 if (amount_sat_greater_eq(committed_funds, requested_funds))
562 break;
563
564 /* Add this output to the UTXO */
565 json_add_outpoint(req->js, NULL, &avail_utxos[i]->out);
566
567 /* Account for it */
568 if (!amount_sat_add(&committed_funds, committed_funds,
569 avail_utxos[i]->val))
570 /* This should really never happen */
571 plugin_err(cmd->plugin, "overflow adding committed");
572 }
573 json_array_end(req->js);
574 return req;
575}
576
577static struct command_result *
578listfunds_success(struct command *cmd,

Callers 1

listfunds_successFunction · 0.85

Calls 6

json_array_startFunction · 0.85
json_add_outpointFunction · 0.85
json_array_endFunction · 0.85
plugin_errFunction · 0.70
amount_sat_greater_eqFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected