Skip to content

Commit

Permalink
fundpsbt: let caller specify locktime.
Browse files Browse the repository at this point in the history
Required for dual funding where the opener sets it.

Changelog-Added: JSON-RPC: fundpsbt takes a new `locktime` parameter
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Aug 18, 2020
1 parent 6371a49 commit 7e4b204
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ def unreserveinputs(self, psbt):
}
return self.call("unreserveinputs", payload)

def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True):
def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True, locktime=None):
"""
Create a PSBT with inputs sufficient to give an output of satoshi.
"""
Expand All @@ -1136,6 +1136,7 @@ def fundpsbt(self, satoshi, feerate, startweight, minconf=None, reserve=True):
"startweight": startweight,
"minconf": minconf,
"reserve": reserve,
"locktime": locktime,
}
return self.call("fundpsbt", payload)

Expand Down
6 changes: 5 additions & 1 deletion doc/lightning-fundpsbt.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-fundpsbt.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lightning-fundpsbt -- Command to populate PSBT inputs from the wallet
SYNOPSIS
--------

**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\]
**fundpsbt** *satoshi* *feerate* *startweight* \[*minconf*\] \[*reserve*\] \[*locktime*\]

DESCRIPTION
-----------
Expand Down Expand Up @@ -36,6 +36,9 @@ outputs should have. Default is 1.
*reserve* is a boolean: if true (the default), then *reserveinputs* is
called (successfully, with *exclusive* true) on the returned PSBT.

*locktime* is an optional locktime: if not set, it is set to a recent
block height.

EXAMPLE USAGE
-------------

Expand Down
16 changes: 10 additions & 6 deletions wallet/reservation.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
u32 *minconf, *weight;
struct amount_sat *amount, input, diff;
bool all, *reserve;
u32 locktime, maxheight, current_height;
u32 *locktime, maxheight, current_height;
struct bitcoin_tx *tx;

if (!param(cmd, buffer, params,
Expand All @@ -228,6 +228,7 @@ static struct command_result *json_fundpsbt(struct command *cmd,
p_req("startweight", param_number, &weight),
p_opt_def("minconf", param_number, &minconf, 1),
p_opt_def("reserve", param_bool, &reserve, true),
p_opt("locktime", param_u32, &locktime),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -303,18 +304,21 @@ static struct command_result *json_fundpsbt(struct command *cmd,
* 0xFFFFFFFD by default. Other wallets are likely to implement
* this too).
*/
locktime = current_height;
if (!locktime) {
locktime = tal(cmd, u32);
*locktime = current_height;

/* Eventually fuzz it too. */
if (locktime > 100 && pseudorand(10) == 0)
locktime -= pseudorand(100);
/* Eventually fuzz it too. */
if (*locktime > 100 && pseudorand(10) == 0)
*locktime -= pseudorand(100);
}

/* FIXME: tx_spending_utxos does more than we need, but there
* are other users right now. */
tx = tx_spending_utxos(cmd, chainparams,
cast_const2(const struct utxo **, utxos),
cmd->ld->wallet->bip32_base,
false, 0, locktime,
false, 0, *locktime,
BITCOIN_TX_RBF_SEQUENCE);

response = json_stream_success(cmd);
Expand Down

0 comments on commit 7e4b204

Please sign in to comment.