diff --git a/doc/lightning-utxopsbt.7 b/doc/lightning-utxopsbt.7 index d732c9f05..6523fa027 100644 --- a/doc/lightning-utxopsbt.7 +++ b/doc/lightning-utxopsbt.7 @@ -3,7 +3,7 @@ lightning-utxopsbt - Command to populate PSBT inputs from given UTXOs .SH SYNOPSIS -\fButxopsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR \fIutxos\fR [\fIreserve\fR] +\fButxopsbt\fR \fIsatoshi\fR \fIfeerate\fR \fIstartweight\fR \fIutxos\fR [\fIreserve\fR] [\fIreservedok\fR] .SH DESCRIPTION @@ -23,6 +23,10 @@ the resulting transaction plus \fIstartweight\fR at the given \fIfeerate\fR, with at least \fIsatoshi\fR left over (unless \fIsatoshi\fR is \fBall\fR, which is equivalent to setting it to zero)\. + +Unless \fIreservedok\fR is set to true (default is false) it will also fail +if any of the \fIutxos\fR are already reserved\. + .SH RETURN VALUE On success, returns the \fIpsbt\fR containing the inputs, \fIfeerate_per_kw\fR diff --git a/doc/lightning-utxopsbt.7.md b/doc/lightning-utxopsbt.7.md index 808bc3cb7..b1279ccd7 100644 --- a/doc/lightning-utxopsbt.7.md +++ b/doc/lightning-utxopsbt.7.md @@ -4,7 +4,7 @@ lightning-utxopsbt -- Command to populate PSBT inputs from given UTXOs SYNOPSIS -------- -**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] +**utxopsbt** *satoshi* *feerate* *startweight* *utxos* \[*reserve*\] \[*reservedok*\] DESCRIPTION ----------- @@ -23,6 +23,9 @@ the resulting transaction plus *startweight* at the given *feerate*, with at least *satoshi* left over (unless *satoshi* is **all**, which is equivalent to setting it to zero). +Unless *reservedok* is set to true (default is false) it will also fail +if any of the *utxos* are already reserved. + RETURN VALUE ------------ diff --git a/wallet/reservation.c b/wallet/reservation.c index 7db5950d0..1ea8aa194 100644 --- a/wallet/reservation.c +++ b/wallet/reservation.c @@ -420,8 +420,9 @@ static struct command_result *json_utxopsbt(struct command *cmd, { struct utxo **utxos; u32 *feerate_per_kw, *weight; - bool all, *reserve; + bool all, *reserve, *reserved_ok; struct amount_sat *amount, input, excess; + u32 current_height; if (!param(cmd, buffer, params, p_req("satoshi", param_sat_or_all, &amount), @@ -429,15 +430,25 @@ static struct command_result *json_utxopsbt(struct command *cmd, p_req("startweight", param_number, &weight), p_req("utxos", param_txout, &utxos), p_opt_def("reserve", param_bool, &reserve, true), + p_opt_def("reservedok", param_bool, &reserved_ok, false), NULL)) return command_param_failed(); all = amount_sat_eq(*amount, AMOUNT_SAT(-1ULL)); input = AMOUNT_SAT(0); + current_height = get_block_height(cmd->ld->topology); for (size_t i = 0; i < tal_count(utxos); i++) { const struct utxo *utxo = utxos[i]; + if (!*reserved_ok && is_reserved(utxo, current_height)) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "UTXO %s:%u already reserved", + type_to_string(tmpctx, + struct bitcoin_txid, + &utxo->txid), + utxo->outnum); + /* It supplies more input. */ if (!amount_sat_add(&input, input, utxo->amount)) return command_fail(cmd, LIGHTNINGD,