aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChris Moore <[email protected]>2015-12-28 16:56:53 -0800
committerChris Moore <[email protected]>2015-12-28 16:56:53 -0800
commit2409865e14dca0704e5618915d6ef902610d91be (patch)
treefaf29f45833e39c11f836092251acd3e2a5830bd /src
parentMerge pull request #7214 (diff)
downloaddiscoin-2409865e14dca0704e5618915d6ef902610d91be.tar.xz
discoin-2409865e14dca0704e5618915d6ef902610d91be.zip
Reduce inefficiency of GetAccountAddress()
Don't scan the wallet to see if the current key has been used if we're going to make a new key anyway. Stop scanning the wallet as soon as we see that the current key has been used. Don't call isValid() twice on the current key.
Diffstat (limited to 'src')
-rw-r--r--src/wallet/rpcwallet.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index db60e498d..f5b1a7de9 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -137,26 +137,25 @@ CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
CAccount account;
walletdb.ReadAccount(strAccount, account);
- bool bKeyUsed = false;
-
- // 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;
+ if (!bForceNew) {
+ if (!account.vchPubKey.IsValid())
+ bForceNew = true;
+ else {
+ // Check if the current key has been used
+ CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID());
+ for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin();
+ it != pwalletMain->mapWallet.end() && account.vchPubKey.IsValid();
+ ++it)
+ 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");