| 851 | } |
| 852 | |
| 853 | bool CWallet::GetLabelDestination(CTxDestination &dest, const std::string& label, bool bForceNew) |
| 854 | { |
| 855 | WalletBatch batch(*database); |
| 856 | |
| 857 | CAccount account; |
| 858 | batch.ReadAccount(label, account); |
| 859 | |
| 860 | if (!bForceNew) { |
| 861 | if (!account.vchPubKey.IsValid()) |
| 862 | bForceNew = true; |
| 863 | else { |
| 864 | // Check if the current key has been used (TODO: check other addresses with the same key) |
| 865 | CScript scriptPubKey = GetScriptForDestination(GetDestinationForKey(account.vchPubKey, m_default_address_type)); |
| 866 | for (std::map<uint256, CWalletTx>::iterator it = mapWallet.begin(); |
| 867 | it != mapWallet.end() && account.vchPubKey.IsValid(); |
| 868 | ++it) |
| 869 | for (const CTxOut& txout : (*it).second.tx->vout) |
| 870 | if (txout.scriptPubKey == scriptPubKey) { |
| 871 | bForceNew = true; |
| 872 | break; |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | // Generate a new key |
| 878 | if (bForceNew) { |
| 879 | if (!GetKeyFromPool(account.vchPubKey, false)) |
| 880 | return false; |
| 881 | |
| 882 | LearnRelatedScripts(account.vchPubKey, m_default_address_type); |
| 883 | dest = GetDestinationForKey(account.vchPubKey, m_default_address_type); |
| 884 | SetAddressBook(dest, label, "receive"); |
| 885 | batch.WriteAccount(label, account); |
| 886 | } else { |
| 887 | dest = GetDestinationForKey(account.vchPubKey, m_default_address_type); |
| 888 | } |
| 889 | |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | void CWallet::MarkDirty() |
| 894 | { |
no test coverage detected