Browse Source

common/withdraw_tx: tell caller where we put the change output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
htlc_accepted_hook
Rusty Russell 6 years ago
parent
commit
92da5ef5f4
  1. 10
      common/withdraw_tx.c
  2. 6
      common/withdraw_tx.h
  3. 2
      hsmd/hsmd.c

10
common/withdraw_tx.c

@ -10,11 +10,12 @@
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct utxo **utxos,
u8 *destination,
const u8 *destination,
struct amount_sat withdraw_amount,
const struct pubkey *changekey,
struct amount_sat change,
const struct ext_key *bip32_base)
const struct ext_key *bip32_base,
int *change_outnum)
{
struct bitcoin_tx *tx;
@ -30,7 +31,10 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey),
&change);
permute_outputs(tx, NULL, map);
}
if (change_outnum)
*change_outnum = ptr2int(map[1]);
} else if (change_outnum)
*change_outnum = -1;
permute_inputs(tx, (const void **)utxos);
assert(bitcoin_tx_check(tx));
return tx;

6
common/withdraw_tx.h

@ -22,13 +22,15 @@ struct utxo;
* @changekey: (in) key to send change to (only used if change_satoshis != 0).
* @change: (in) amount to send as change.
* @bip32_base: (in) bip32 base for key derivation, or NULL.
* @change_outnum: (out) set to output index of change output or -1 if none, unless NULL.
*/
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
const struct utxo **utxos,
u8 *destination,
const u8 *destination,
struct amount_sat withdraw_amount,
const struct pubkey *changekey,
struct amount_sat change,
const struct ext_key *bip32_base);
const struct ext_key *bip32_base,
int *change_outnum);
#endif /* LIGHTNING_COMMON_WITHDRAW_TX_H */

2
hsmd/hsmd.c

@ -1456,7 +1456,7 @@ static struct io_plan *handle_sign_withdrawal_tx(struct io_conn *conn,
pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey);
tx = withdraw_tx(tmpctx, cast_const2(const struct utxo **, utxos),
scriptpubkey, satoshi_out,
&changekey, change_out, NULL);
&changekey, change_out, NULL, NULL);
sign_all_inputs(tx, utxos);

Loading…
Cancel
Save