mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
@@ -10,11 +10,12 @@
|
|||||||
|
|
||||||
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
|
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
|
||||||
const struct utxo **utxos,
|
const struct utxo **utxos,
|
||||||
u8 *destination,
|
const u8 *destination,
|
||||||
struct amount_sat withdraw_amount,
|
struct amount_sat withdraw_amount,
|
||||||
const struct pubkey *changekey,
|
const struct pubkey *changekey,
|
||||||
struct amount_sat change,
|
struct amount_sat change,
|
||||||
const struct ext_key *bip32_base)
|
const struct ext_key *bip32_base,
|
||||||
|
int *change_outnum)
|
||||||
{
|
{
|
||||||
struct bitcoin_tx *tx;
|
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),
|
bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey),
|
||||||
&change);
|
&change);
|
||||||
permute_outputs(tx, NULL, map);
|
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);
|
permute_inputs(tx, (const void **)utxos);
|
||||||
assert(bitcoin_tx_check(tx));
|
assert(bitcoin_tx_check(tx));
|
||||||
return tx;
|
return tx;
|
||||||
|
|||||||
@@ -22,13 +22,15 @@ struct utxo;
|
|||||||
* @changekey: (in) key to send change to (only used if change_satoshis != 0).
|
* @changekey: (in) key to send change to (only used if change_satoshis != 0).
|
||||||
* @change: (in) amount to send as change.
|
* @change: (in) amount to send as change.
|
||||||
* @bip32_base: (in) bip32 base for key derivation, or NULL.
|
* @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,
|
struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
|
||||||
const struct utxo **utxos,
|
const struct utxo **utxos,
|
||||||
u8 *destination,
|
const u8 *destination,
|
||||||
struct amount_sat withdraw_amount,
|
struct amount_sat withdraw_amount,
|
||||||
const struct pubkey *changekey,
|
const struct pubkey *changekey,
|
||||||
struct amount_sat change,
|
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 */
|
#endif /* LIGHTNING_COMMON_WITHDRAW_TX_H */
|
||||||
|
|||||||
@@ -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);
|
pubkey_from_der(ext.pub_key, sizeof(ext.pub_key), &changekey);
|
||||||
tx = withdraw_tx(tmpctx, cast_const2(const struct utxo **, utxos),
|
tx = withdraw_tx(tmpctx, cast_const2(const struct utxo **, utxos),
|
||||||
scriptpubkey, satoshi_out,
|
scriptpubkey, satoshi_out,
|
||||||
&changekey, change_out, NULL);
|
&changekey, change_out, NULL, NULL);
|
||||||
|
|
||||||
sign_all_inputs(tx, utxos);
|
sign_all_inputs(tx, utxos);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user