Merge #7262: Reduce inefficiency of GetAccountAddress()

2409865 Reduce inefficiency of GetAccountAddress() (Chris Moore)
This commit is contained in:
Wladimir J. van der Laan 2016-01-22 15:30:54 +01:00 committed by Alexander Block
parent 43700eef36
commit 643181fe15

View File

@ -159,26 +159,25 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
CAccount account; CAccount account;
walletdb.ReadAccount(strAccount, account); walletdb.ReadAccount(strAccount, account);
bool bKeyUsed = false; if (!bForceNew) {
if (!account.vchPubKey.IsValid())
bForceNew = true;
else {
// Check if the current key has been used // Check if the current key has been used
if (account.vchPubKey.IsValid())
{
CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID()); CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid(); it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
++it) ++it)
{ BOOST_FOREACH(const CTxOut& txout, (*it).second.vout)
const CWalletTx& wtx = (*it).second; if (txout.scriptPubKey == scriptPubKey) {
BOOST_FOREACH(const CTxOut& txout, wtx.vout) bForceNew = true;
if (txout.scriptPubKey == scriptPubKey) break;
bKeyUsed = true; }
} }
} }
// Generate a new key // Generate a new key
if (!account.vchPubKey.IsValid() || bForceNew || bKeyUsed) if (bForceNew) {
{
if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false)) if (!pwalletMain->GetKeyFromPool(account.vchPubKey, false))
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first"); throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");