| 640 | } |
| 641 | |
| 642 | static struct command_result *json_utxopsbt(struct command *cmd, |
| 643 | const char *buffer, |
| 644 | const jsmntok_t *obj UNNEEDED, |
| 645 | const jsmntok_t *params) |
| 646 | { |
| 647 | struct utxo **utxos; |
| 648 | u32 *feerate_per_kw, *weight, *min_witness_weight; |
| 649 | bool all, *reserved_ok, *excess_as_change; |
| 650 | struct amount_sat *amount, input, excess; |
| 651 | u32 current_height, *locktime, *reserve; |
| 652 | |
| 653 | if (!param(cmd, buffer, params, |
| 654 | p_req("satoshi", param_sat_or_all, &amount), |
| 655 | p_req("feerate", param_feerate, &feerate_per_kw), |
| 656 | p_req("startweight", param_number, &weight), |
| 657 | p_req("utxos", param_txout, &utxos), |
| 658 | p_opt_def("reserve", param_reserve_num, &reserve, |
| 659 | RESERVATION_DEFAULT), |
| 660 | p_opt_def("reservedok", param_bool, &reserved_ok, false), |
| 661 | p_opt("locktime", param_number, &locktime), |
| 662 | p_opt_def("min_witness_weight", param_number, |
| 663 | &min_witness_weight, 0), |
| 664 | p_opt_def("excess_as_change", param_bool, |
| 665 | &excess_as_change, false), |
| 666 | NULL)) |
| 667 | return command_param_failed(); |
| 668 | |
| 669 | all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL)); |
| 670 | |
| 671 | input = AMOUNT_SAT(0); |
| 672 | current_height = get_block_height(cmd->ld->topology); |
| 673 | for (size_t i = 0; i < tal_count(utxos); i++) { |
| 674 | const struct utxo *utxo = utxos[i]; |
| 675 | |
| 676 | if (!*reserved_ok && utxo_is_reserved(utxo, current_height)) |
| 677 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 678 | "UTXO %s already reserved", |
| 679 | type_to_string(tmpctx, |
| 680 | struct bitcoin_outpoint, |
| 681 | &utxo->outpoint)); |
| 682 | if (utxo_is_csv_locked(utxo, current_height)) |
| 683 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 684 | "UTXO %s is csv locked (%u)", |
| 685 | type_to_string(tmpctx, |
| 686 | struct bitcoin_outpoint, |
| 687 | &utxo->outpoint), |
| 688 | utxo->close_info->csv); |
| 689 | |
| 690 | |
| 691 | /* It supplies more input. */ |
| 692 | if (!amount_sat_add(&input, input, utxo->amount)) |
| 693 | return command_fail(cmd, LIGHTNINGD, |
| 694 | "impossible UTXO value"); |
| 695 | |
| 696 | /* But also adds weight */ |
| 697 | *weight += utxo_spend_weight(utxo, *min_witness_weight); |
| 698 | } |
| 699 |
nothing calls this directly
no test coverage detected