Browse Source

psbt: populate scriptsigs + witnesses

Pass scriptSig + witness info down to the PSBT struct
nifty/pset-pre
niftynei 5 years ago
committed by Rusty Russell
parent
commit
a848df67f1
  1. 17
      bitcoin/tx.c

17
bitcoin/tx.c

@ -318,12 +318,12 @@ void bitcoin_tx_output_get_amount_sat(struct bitcoin_tx *tx, int outnum,
*amount = amount_asset_to_sat(&asset_amt); *amount = amount_asset_to_sat(&asset_amt);
} }
void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum, void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
u8 **witness) u8 **witness)
{ {
struct wally_tx_witness_stack *stack = NULL; struct wally_tx_witness_stack *stack = NULL;
size_t stack_size = tal_count(witness); size_t stack_size = tal_count(witness);
struct wally_psbt_input *in;
/* Free any lingering witness */ /* Free any lingering witness */
if (witness) { if (witness) {
@ -333,15 +333,30 @@ void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
tal_bytelen(witness[i])); tal_bytelen(witness[i]));
} }
wally_tx_set_input_witness(tx->wtx, innum, stack); wally_tx_set_input_witness(tx->wtx, innum, stack);
/* Also add to the psbt */
if (stack) {
assert(innum < tx->psbt->num_inputs);
in = &tx->psbt->inputs[innum];
wally_psbt_input_set_final_witness(in, stack);
}
if (stack) if (stack)
wally_tx_witness_stack_free(stack); wally_tx_witness_stack_free(stack);
if (taken(witness)) if (taken(witness))
tal_free(witness); tal_free(witness);
} }
void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script) void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script)
{ {
struct wally_psbt_input *in;
wally_tx_set_input_script(tx->wtx, innum, script, tal_bytelen(script)); wally_tx_set_input_script(tx->wtx, innum, script, tal_bytelen(script));
/* Also add to the psbt */
assert(innum < tx->psbt->num_inputs);
in = &tx->psbt->inputs[innum];
wally_psbt_input_set_final_script_sig(in, script, tal_bytelen(script));
} }
const u8 *bitcoin_tx_input_get_witness(const tal_t *ctx, const u8 *bitcoin_tx_input_get_witness(const tal_t *ctx,

Loading…
Cancel
Save