Browse Source

Merge #7262: Reduce inefficiency of GetAccountAddress()

2409865 Reduce inefficiency of GetAccountAddress() (Chris Moore)
0.13
Wladimir J. van der Laan 9 years ago
parent
commit
fc08994000
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 21
      src/wallet/rpcwallet.cpp

21
src/wallet/rpcwallet.cpp

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

Loading…
Cancel
Save