| 78 | } |
| 79 | |
| 80 | static struct command_result *json_reserveinputs(struct command *cmd, |
| 81 | const char *buffer, |
| 82 | const jsmntok_t *obj UNNEEDED, |
| 83 | const jsmntok_t *params) |
| 84 | { |
| 85 | struct json_stream *response; |
| 86 | struct wally_psbt *psbt; |
| 87 | struct utxo **utxos = tal_arr(cmd, struct utxo *, 0); |
| 88 | bool *exclusive; |
| 89 | u32 *reserve, current_height; |
| 90 | |
| 91 | if (!param(cmd, buffer, params, |
| 92 | p_req("psbt", param_psbt, &psbt), |
| 93 | p_opt_def("exclusive", param_bool, &exclusive, true), |
| 94 | p_opt_def("reserve", param_number, &reserve, |
| 95 | RESERVATION_DEFAULT), |
| 96 | NULL)) |
| 97 | return command_param_failed(); |
| 98 | |
| 99 | current_height = get_block_height(cmd->ld->topology); |
| 100 | for (size_t i = 0; i < psbt->tx->num_inputs; i++) { |
| 101 | struct bitcoin_outpoint outpoint; |
| 102 | struct utxo *utxo; |
| 103 | |
| 104 | wally_tx_input_get_outpoint(&psbt->tx->inputs[i], &outpoint); |
| 105 | utxo = wallet_utxo_get(cmd, cmd->ld->wallet, &outpoint); |
| 106 | if (!utxo) |
| 107 | continue; |
| 108 | if (*exclusive && utxo_is_reserved(utxo, current_height)) { |
| 109 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 110 | "%s already reserved", |
| 111 | type_to_string(tmpctx, |
| 112 | struct bitcoin_outpoint, |
| 113 | &utxo->outpoint)); |
| 114 | } |
| 115 | if (utxo->status == OUTPUT_STATE_SPENT) |
| 116 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 117 | "%s already spent", |
| 118 | type_to_string(tmpctx, |
| 119 | struct bitcoin_outpoint, |
| 120 | &utxo->outpoint)); |
| 121 | tal_arr_expand(&utxos, utxo); |
| 122 | } |
| 123 | |
| 124 | response = json_stream_success(cmd); |
| 125 | reserve_and_report(response, cmd->ld->wallet, current_height, *reserve, utxos); |
| 126 | return command_success(cmd, response); |
| 127 | } |
| 128 | |
| 129 | static const struct json_command reserveinputs_command = { |
| 130 | "reserveinputs", |
nothing calls this directly
no test coverage detected