mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-09 09:04:25 +01:00
withdraw_tx: don't create empty output if no change.
We were using changekey as the flag to produce change, not changesat, but the caller was using changesat as the flag. Also, don't allocate changekey at all if we don't need it; this means valgrind will complain if we use it at all, too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
abafcae5a6
commit
bbac67f108
@@ -17,7 +17,7 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx,
|
||||
const struct ext_key *bip32_base)
|
||||
{
|
||||
struct bitcoin_tx *tx =
|
||||
bitcoin_tx(ctx, tal_count(utxos), changekey ? 2 : 1);
|
||||
bitcoin_tx(ctx, tal_count(utxos), changesat ? 2 : 1);
|
||||
for (size_t i = 0; i < tal_count(utxos); i++) {
|
||||
tx->input[i].txid = utxos[i]->txid;
|
||||
tx->input[i].index = utxos[i]->outnum;
|
||||
|
||||
@@ -271,7 +271,10 @@ static void json_withdraw(struct command *cmd,
|
||||
if (withdraw->changesatoshi <= 546)
|
||||
withdraw->changesatoshi = 0;
|
||||
|
||||
withdraw->change_key_index = wallet_get_newindex(cmd->ld);
|
||||
if (withdraw->changesatoshi)
|
||||
withdraw->change_key_index = wallet_get_newindex(cmd->ld);
|
||||
else
|
||||
withdraw->change_key_index = 0;
|
||||
|
||||
utxos = from_utxoptr_arr(withdraw, withdraw->utxos);
|
||||
u8 *msg = towire_hsm_sign_withdrawal(cmd,
|
||||
@@ -292,14 +295,17 @@ static void json_withdraw(struct command *cmd,
|
||||
fatal("HSM gave bad sign_withdrawal_reply %s",
|
||||
tal_hex(withdraw, msg));
|
||||
|
||||
if (bip32_key_from_parent(cmd->ld->wallet->bip32_base,
|
||||
withdraw->change_key_index,
|
||||
BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) {
|
||||
command_fail(cmd, "Changekey generation failure");
|
||||
return;
|
||||
}
|
||||
if (withdraw->changesatoshi) {
|
||||
if (bip32_key_from_parent(cmd->ld->wallet->bip32_base,
|
||||
withdraw->change_key_index,
|
||||
BIP32_FLAG_KEY_PUBLIC, &ext)
|
||||
!= WALLY_OK) {
|
||||
command_fail(cmd, "Changekey generation failure");
|
||||
return;
|
||||
}
|
||||
|
||||
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(withdraw, withdraw->utxos, withdraw->destination,
|
||||
withdraw->amount, &changekey, withdraw->changesatoshi,
|
||||
cmd->ld->wallet->bip32_base);
|
||||
|
||||
Reference in New Issue
Block a user