[wallet] CreateTransaction: simplify change address check

This commit is contained in:
Sjors Provoost 2019-10-23 15:11:25 +02:00
parent 5efc25f963
commit 709f8685ac
No known key found for this signature in database
GPG Key ID: 57FF9BDBCC301009
2 changed files with 3 additions and 10 deletions

View File

@ -2630,18 +2630,11 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
// post-backup change. // post-backup change.
// Reserve a new key pair from key pool // 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; CTxDestination dest;
bool ret = reservedest.GetReservedDestination(dest, true); if (!reservedest.GetReservedDestination(dest, true)) {
if (!ret) strFailReason = _("Can't generate a change-address key. Please call keypoolrefill first.").translated;
{
strFailReason = _("Keypool ran out, please call keypoolrefill first").translated;
return false; return false;
} }
scriptChange = GetScriptForDestination(dest); scriptChange = GetScriptForDestination(dest);
} }
CTxOut change_prototype_txout(0, scriptChange); CTxOut change_prototype_txout(0, scriptChange);

View File

@ -504,7 +504,7 @@ class RawTransactionsTest(BitcoinTestFramework):
rawtx = self.nodes[1].createrawtransaction(inputs, outputs) rawtx = self.nodes[1].createrawtransaction(inputs, outputs)
# fund a transaction that requires a new key for the change output # fund a transaction that requires a new key for the change output
# creating the key must be impossible because the wallet is locked # 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. # Refill the keypool.
self.nodes[1].walletpassphrase("test", 100) self.nodes[1].walletpassphrase("test", 100)