| 575 | }; |
| 576 | |
| 577 | static struct out_req * |
| 578 | build_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 | |
| 618 | static struct command_result * |
| 619 | listfunds_success(struct command *cmd, |
no test coverage detected