diff options
| author | Wladimir J. van der Laan <[email protected]> | 2016-06-06 16:27:48 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2016-06-06 16:28:41 +0200 |
| commit | 52c3f348bec33fab5ae0a9f1b9f14b9a74c0083f (patch) | |
| tree | 26c58cc27c5ae04f758c247ea96a6b01b7d5f603 /src/wallet/wallet.cpp | |
| parent | Merge #8007: Minor locking improvements (diff) | |
| parent | Improve CWallet API with new GetAccountPubkey function. (diff) | |
| download | discoin-52c3f348bec33fab5ae0a9f1b9f14b9a74c0083f.tar.xz discoin-52c3f348bec33fab5ae0a9f1b9f14b9a74c0083f.zip | |
Merge #8142: Improve CWallet API with new GetAccountPubkey function.
152ab23 Improve CWallet API with new GetAccountPubkey function. (Patrick Strateman)
Diffstat (limited to 'src/wallet/wallet.cpp')
| -rw-r--r-- | src/wallet/wallet.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fb56e7c1d..f3d165472 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -640,6 +640,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() { { |