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

Function build_utxopsbt_request

plugins/funder.c:577–616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

575};
576
577static struct out_req *
578build_utxopsbt_request(struct command *cmd,
579 struct open_info *info,
580 struct bitcoin_outpoint **prev_outs,
581 struct amount_sat requested_funds,
582 struct amount_sat committed_funds,
583 struct funder_utxo **avail_utxos)
584{
585 struct out_req *req;
586
587 req = jsonrpc_request_start(cmd,
588 "utxopsbt",
589 &psbt_funded,
590 &psbt_fund_failed,
591 info);
592 /* Add every prev_out */
593 json_array_start(req->js, "utxos");
594 for (size_t i = 0; i < tal_count(prev_outs); i++)
595 json_add_outpoint(req->js, NULL, prev_outs[i]);
596
597 /* Next add available utxos until we surpass the
598 * requested funds goal */
599 /* FIXME: Update `utxopsbt` to automatically add more inputs? */
600 for (size_t i = 0; i < tal_count(avail_utxos); i++) {
601 /* If we've already hit our goal, break */
602 if (amount_sat_greater_eq(committed_funds, requested_funds))
603 break;
604
605 /* Add this output to the UTXO */
606 json_add_outpoint(req->js, NULL, &avail_utxos[i]->out);
607
608 /* Account for it */
609 if (!amount_sat_add(&committed_funds, committed_funds,
610 avail_utxos[i]->val))
611 /* This should really never happen */
612 plugin_err(cmd->plugin, "overflow adding committed");
613 }
614 json_array_end(req->js);
615 return req;
616}
617
618static struct command_result *
619listfunds_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