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
@@ -1026,6 +1026,44 @@ bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmoun
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew)
|
||||
{
|
||||
CWalletDB walletdb(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 = mapWallet.begin();
|
||||
it != 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 (!GetKeyFromPool(account.vchPubKey))
|
||||
return false;
|
||||
|
||||
SetAddressBook(account.vchPubKey.GetID(), strAccount, "receive");
|
||||
walletdb.WriteAccount(strAccount, account);
|
||||
}
|
||||
|
||||
pubKey = account.vchPubKey;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CWallet::MarkDirty()
|
||||
{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user