aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcwallet.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-06-02 23:16:42 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2016-06-06 07:02:05 -0700
commit152ab236ea1c1106340196f45918fd84f57a0b63 (patch)
treeec99b28f0b317d83a6828efe3e39538b17633966 /src/wallet/rpcwallet.cpp
parent243ac0c75b1b2a9b6ed4eaa0e430c0d5d6c472f0 (diff)
Improve CWallet API with new GetAccountPubkey function.
Remove one more caller that is passing CWalletDB.
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r--src/wallet/rpcwallet.cpp34
1 files changed, 4 insertions, 30 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 42b37ea778..5e6afcd7cb 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -146,38 +146,12 @@ UniValue getnewaddress(const UniValue& params, bool fHelp)
CBitcoinAddress GetAccountAddress(string strAccount, bool bForceNew=false)
{
- CWalletDB walletdb(pwalletMain->strWalletFile);
-
- CAccount account;
- walletdb.ReadAccount(strAccount, account);
-
- 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 (bForceNew) {
- if (!pwalletMain->GetKeyFromPool(account.vchPubKey))
- throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
-
- pwalletMain->SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
- walletdb.WriteAccount(strAccount, account);
+ CPubKey pubKey;
+ if (!pwalletMain->GetAccountPubkey(pubKey, strAccount, bForceNew)) {
+ throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
}
- return CBitcoinAddress(account.vchPubKey.GetID());
+ return CBitcoinAddress(pubKey.GetID());
}
UniValue getaccountaddress(const UniValue& params, bool fHelp)