Improve CWallet API with new GetAccountPubkey function.
Remove one more caller that is passing CWalletDB.
This commit is contained in:
committed by
lateminer
parent
acf8c3d9ce
commit
e94e583f48
@@ -169,38 +169,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;
|
||||
}
|
||||
}
|
||||
CPubKey pubKey;
|
||||
if (!pwalletMain->GetAccountPubkey(pubKey, strAccount, bForceNew)) {
|
||||
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return CBitcoinAddress(account.vchPubKey.GetID());
|
||||
return CBitcoinAddress(pubKey.GetID());
|
||||
}
|
||||
|
||||
UniValue getaccountaddress(const UniValue& params, bool fHelp)
|
||||
|
||||
Reference in New Issue
Block a user