Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
bbac67f108
  1. 2
      common/withdraw_tx.c
  2. 22
      wallet/walletrpc.c

2
common/withdraw_tx.c

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

22
wallet/walletrpc.c

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

Loading…
Cancel
Save