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

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-06-05 14:58:57 +09:30
parent 09d9abf12e
commit 92da5ef5f4
3 changed files with 12 additions and 6 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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);