Skip to content

Commit 553e485

Browse files
committed
addpsbtoutput: Add serial_id flag
When set this flag tells addpsbtoutput to add the intiator serial_id to the added output. Changelog-Changed: addpsbtoutput now allows serial_id to be set while adding which is needed for splicing and dual.
1 parent bc5d606 commit 553e485

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

wallet/reservation.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <common/json_command.h>
99
#include <common/json_param.h>
1010
#include <common/key_derive.h>
11+
#include <common/psbt_open.h>
1112
#include <common/type_to_string.h>
1213
#include <lightningd/chaintopology.h>
1314
#include <lightningd/channel.h>
@@ -677,13 +678,18 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
677678
struct pubkey pubkey;
678679
s64 keyidx;
679680
const u8 *b32script;
681+
bool *add_initiator_serial_ids;
682+
struct wally_psbt_output *output;
683+
u64 serial_id;
680684

681685
if (!param_check(cmd, buffer, params,
682686
p_req("satoshi", param_sat, &amount),
683687
p_opt("initialpsbt", param_psbt, &psbt),
684688
p_opt("locktime", param_number, &locktime),
685689
p_opt("destination", param_bitcoin_address,
686690
&b32script),
691+
p_opt_def("add_initiator_serial_ids", param_bool,
692+
&add_initiator_serial_ids, false),
687693
NULL))
688694
return command_param_failed();
689695

@@ -737,7 +743,13 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
737743
}
738744

739745
outnum = psbt->num_outputs;
740-
psbt_append_output(psbt, b32script, *amount);
746+
output = psbt_append_output(psbt, b32script, *amount);
747+
748+
if (*add_initiator_serial_ids) {
749+
serial_id = psbt_new_output_serial(psbt, TX_INITIATOR);
750+
psbt_output_set_serial_id(psbt, output, serial_id);
751+
}
752+
741753
/* Add additional weight of output */
742754
weight = bitcoin_tx_output_weight(
743755
chainparams->is_elements ? BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN : BITCOIN_SCRIPTPUBKEY_P2TR_LEN);

0 commit comments

Comments
 (0)