mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
utxopsbt: make default to only allow unreserved utxos.
This more closely mirrors fundpsbt (which will only select unreserved ones) but you can turn it off if you want to e.g. rbf in future. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: New low-level command `utxopsbt` to create PSBT from existing utxos.
This commit is contained in:
6
doc/lightning-utxopsbt.7
generated
6
doc/lightning-utxopsbt.7
generated
@@ -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
|
||||
|
||||
@@ -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
|
||||
------------
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user