Skip to content

Commit

Permalink
utxopsbt: make default to only allow unreserved utxos.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rustyrussell committed Aug 18, 2020
1 parent b07327a commit bf5e994
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion doc/lightning-utxopsbt.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion doc/lightning-utxopsbt.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -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
------------

Expand Down
13 changes: 12 additions & 1 deletion wallet/reservation.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,24 +420,35 @@ 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),
p_req("feerate", param_feerate, &feerate_per_kw),
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,
Expand Down

0 comments on commit bf5e994

Please sign in to comment.