| 991 | } |
| 992 | |
| 993 | static struct command_result *json_utxopsbt(struct command *cmd, |
| 994 | const char *buffer, |
| 995 | const jsmntok_t *obj UNNEEDED, |
| 996 | const jsmntok_t *params) |
| 997 | { |
| 998 | struct utxo **utxos; |
| 999 | u32 *feerate_per_kw, *weight, *min_witness_weight; |
| 1000 | bool all, *reserved_ok, *excess_as_change, *keep_emergency_funds; |
| 1001 | struct amount_sat *amount, input, excess, change; |
| 1002 | u32 current_height, *locktime, *reserve; |
| 1003 | |
| 1004 | if (!param_check(cmd, buffer, params, |
| 1005 | p_req("satoshi", param_sat_or_all, &amount), |
| 1006 | p_req("feerate", param_feerate, &feerate_per_kw), |
| 1007 | p_req("startweight", param_number, &weight), |
| 1008 | p_req("utxos", param_txout, &utxos), |
| 1009 | p_opt_def("reserve", param_number, &reserve, |
| 1010 | RESERVATION_DEFAULT), |
| 1011 | p_opt_def("reservedok", param_bool, &reserved_ok, false), |
| 1012 | p_opt("locktime", param_number, &locktime), |
| 1013 | p_opt_def("min_witness_weight", param_number, |
| 1014 | &min_witness_weight, 0), |
| 1015 | p_opt_def("excess_as_change", param_bool, |
| 1016 | &excess_as_change, false), |
| 1017 | p_opt_def("opening_anchor_channel", param_bool, |
| 1018 | &keep_emergency_funds, false), |
| 1019 | NULL)) |
| 1020 | return command_param_failed(); |
| 1021 | |
| 1022 | /* If we have anchor channels, we definitely need to keep |
| 1023 | * emergency funds. */ |
| 1024 | if (have_anchor_channel(cmd->ld)) |
| 1025 | *keep_emergency_funds = true; |
| 1026 | |
| 1027 | all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL)); |
| 1028 | |
| 1029 | input = AMOUNT_SAT(0); |
| 1030 | current_height = get_block_height(cmd->ld->topology); |
| 1031 | for (size_t i = 0; i < tal_count(utxos); i++) { |
| 1032 | const struct utxo *utxo = utxos[i]; |
| 1033 | |
| 1034 | if (!*reserved_ok && utxo_is_reserved(utxo, current_height)) |
| 1035 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1036 | "UTXO %s already reserved", |
| 1037 | fmt_bitcoin_outpoint(tmpctx, |
| 1038 | &utxo->outpoint)); |
| 1039 | if (utxo_is_csv_locked(utxo, current_height)) |
| 1040 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1041 | "UTXO %s is csv locked (%u)", |
| 1042 | fmt_bitcoin_outpoint(tmpctx, |
| 1043 | &utxo->outpoint), |
| 1044 | utxo->close_info->csv); |
| 1045 | |
| 1046 | |
| 1047 | /* It supplies more input. */ |
| 1048 | if (!amount_sat_add(&input, input, utxo->amount)) |
| 1049 | return command_fail(cmd, LIGHTNINGD, |
| 1050 | "impossible UTXO value"); |
nothing calls this directly
no test coverage detected