| 534 | }; |
| 535 | |
| 536 | static struct out_req * |
| 537 | build_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 | |
| 577 | static struct command_result * |
| 578 | listfunds_success(struct command *cmd, |
no test coverage detected