wallet: allow psbt_using_utxos to take a starter psbt.

It will append inputs to this PSBT instead of allocating a new one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-04-10 09:49:56 +09:30
parent d502a7ecbb
commit f1deeda123
2 changed files with 20 additions and 7 deletions

View File

@ -261,17 +261,21 @@ static bool inputs_sufficient(struct amount_sat input,
return false;
}
static struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
struct wallet *wallet,
struct utxo **utxos,
u32 nlocktime,
u32 nsequence)
struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
struct wallet *wallet,
struct utxo **utxos,
u32 nlocktime,
u32 nsequence,
struct wally_psbt *base)
{
struct pubkey key;
u8 *scriptSig, *scriptPubkey, *redeemscript;
struct wally_psbt *psbt;
psbt = create_psbt(ctx, tal_count(utxos), 0, nlocktime);
if (base)
psbt = base;
else
psbt = create_psbt(ctx, tal_count(utxos), 0, nlocktime);
for (size_t i = 0; i < tal_count(utxos); i++) {
u32 this_nsequence;
@ -357,7 +361,8 @@ static struct command_result *finish_psbt(struct command *cmd,
}
psbt = psbt_using_utxos(cmd, cmd->ld->wallet, utxos,
*locktime, BITCOIN_TX_RBF_SEQUENCE);
*locktime, BITCOIN_TX_RBF_SEQUENCE,
NULL);
assert(psbt->version == 2);
/* Should we add a change output for the excess? */
if (excess_as_change) {

View File

@ -1748,4 +1748,12 @@ struct wallet_htlc_iter *wallet_htlcs_next(struct wallet *w,
struct amount_msat *msat,
struct sha256 *payment_hash,
enum htlc_state *hstate);
/* Make a PSBT from these utxos, or enhance @base if non-NULL. */
struct wally_psbt *psbt_using_utxos(const tal_t *ctx,
struct wallet *wallet,
struct utxo **utxos,
u32 nlocktime,
u32 nsequence,
struct wally_psbt *base);
#endif /* LIGHTNING_WALLET_WALLET_H */