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.
This commit is contained in:
Dusty Daemon 2024-11-11 11:48:24 +10:30 committed by Rusty Russell
parent 8221c96eab
commit 7ce0dc6e2e

View file

@ -658,6 +658,9 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
struct pubkey pubkey; struct pubkey pubkey;
s64 keyidx; s64 keyidx;
const u8 *b32script; const u8 *b32script;
bool *add_initiator_serial_ids;
struct wally_psbt_output *output;
u64 serial_id;
if (!param_check(cmd, buffer, params, if (!param_check(cmd, buffer, params,
p_req("satoshi", param_sat, &amount), p_req("satoshi", param_sat, &amount),
@ -665,6 +668,8 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
p_opt("locktime", param_number, &locktime), p_opt("locktime", param_number, &locktime),
p_opt("destination", param_bitcoin_address, p_opt("destination", param_bitcoin_address,
&b32script), &b32script),
p_opt_def("add_initiator_serial_ids", param_bool,
&add_initiator_serial_ids, false),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -717,7 +722,13 @@ static struct command_result *json_addpsbtoutput(struct command *cmd,
} }
outnum = psbt->num_outputs; outnum = psbt->num_outputs;
psbt_append_output(psbt, b32script, *amount); output = psbt_append_output(psbt, b32script, *amount);
if (*add_initiator_serial_ids) {
serial_id = psbt_new_output_serial(psbt, TX_INITIATOR);
psbt_output_set_serial_id(psbt, output, serial_id);
}
/* Add additional weight of output */ /* Add additional weight of output */
weight = bitcoin_tx_output_weight( weight = bitcoin_tx_output_weight(
chainparams->is_elements ? BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN : BITCOIN_SCRIPTPUBKEY_P2TR_LEN); chainparams->is_elements ? BITCOIN_SCRIPTPUBKEY_P2WPKH_LEN : BITCOIN_SCRIPTPUBKEY_P2TR_LEN);