MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetLabelDestination

Method GetLabelDestination

src/wallet/wallet.cpp:853–891  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

851}
852
853bool 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
893void CWallet::MarkDirty()
894{

Callers 1

GetLabelDestinationFunction · 0.80

Calls 7

GetScriptForDestinationFunction · 0.85
GetDestinationForKeyFunction · 0.85
ReadAccountMethod · 0.80
WriteAccountMethod · 0.80
IsValidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected