Skip to content

Commit

Permalink
[wallet] CreateTransaction: simplify change address check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Feb 4, 2020
1 parent 5efc25f commit 709f868
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
11 changes: 2 additions & 9 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,18 +2630,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
// post-backup change.

// Reserve a new key pair from key pool
if (!CanGetAddresses(true)) {
strFailReason = _("Can't generate a change-address key. No keys in the internal keypool and can't generate any keys.").translated;
return false;
}
CTxDestination dest;
bool ret = reservedest.GetReservedDestination(dest, true);
if (!ret)
{
strFailReason = _("Keypool ran out, please call keypoolrefill first").translated;
if (!reservedest.GetReservedDestination(dest, true)) {
strFailReason = _("Can't generate a change-address key. Please call keypoolrefill first.").translated;
return false;
}

scriptChange = GetScriptForDestination(dest);
}
CTxOut change_prototype_txout(0, scriptChange);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def test_locked_wallet(self):
rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
# fund a transaction that requires a new key for the change output
# creating the key must be impossible because the wallet is locked
assert_raises_rpc_error(-4, "Keypool ran out, please call keypoolrefill first", self.nodes[1].fundrawtransaction, rawtx)
assert_raises_rpc_error(-4, "Can't generate a change-address key. Please call keypoolrefill first.", self.nodes[1].fundrawtransaction, rawtx)

# Refill the keypool.
self.nodes[1].walletpassphrase("test", 100)
Expand Down

0 comments on commit 709f868

Please sign in to comment.