Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 931 Lines • ▼ Show 20 Lines | if (batch) { | ||||
batch->WriteOrderPosNext(nOrderPosNext); | batch->WriteOrderPosNext(nOrderPosNext); | ||||
} else { | } else { | ||||
WalletBatch(*database).WriteOrderPosNext(nOrderPosNext); | WalletBatch(*database).WriteOrderPosNext(nOrderPosNext); | ||||
} | } | ||||
return nRet; | return nRet; | ||||
} | } | ||||
bool CWallet::GetLabelDestination(CTxDestination &dest, | |||||
const std::string &label, bool bForceNew) { | |||||
WalletBatch batch(*database); | |||||
CAccount account; | |||||
batch.ReadAccount(label, account); | |||||
if (!bForceNew) { | |||||
if (!account.vchPubKey.IsValid()) { | |||||
bForceNew = true; | |||||
} else { | |||||
// Check if the current key has been used (TODO: check other | |||||
// addresses with the same key) | |||||
CScript scriptPubKey = GetScriptForDestination(GetDestinationForKey( | |||||
account.vchPubKey, m_default_address_type)); | |||||
for (std::map<TxId, CWalletTx>::iterator it = mapWallet.begin(); | |||||
it != mapWallet.end() && account.vchPubKey.IsValid(); ++it) { | |||||
for (const CTxOut &txout : (*it).second.tx->vout) { | |||||
if (txout.scriptPubKey == scriptPubKey) { | |||||
bForceNew = true; | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// Generate a new key | |||||
if (bForceNew) { | |||||
if (!GetKeyFromPool(account.vchPubKey, false)) { | |||||
return false; | |||||
} | |||||
LearnRelatedScripts(account.vchPubKey, m_default_address_type); | |||||
dest = GetDestinationForKey(account.vchPubKey, m_default_address_type); | |||||
SetAddressBook(dest, label, "receive"); | |||||
batch.WriteAccount(label, account); | |||||
} else { | |||||
dest = GetDestinationForKey(account.vchPubKey, m_default_address_type); | |||||
} | |||||
return true; | |||||
} | |||||
void CWallet::MarkDirty() { | void CWallet::MarkDirty() { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
item.second.MarkDirty(); | item.second.MarkDirty(); | ||||
} | } | ||||
} | } | ||||
bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose) { | bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose) { | ||||
▲ Show 20 Lines • Show All 3,053 Lines • ▼ Show 20 Lines | for (const std::pair<const CTxDestination, CAddressBookData> &item : | ||||
if (strName == label) { | if (strName == label) { | ||||
result.insert(address); | result.insert(address); | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
void CWallet::DeleteLabel(const std::string &label) { | |||||
WalletBatch batch(*database); | |||||
batch.EraseAccount(label); | |||||
} | |||||
bool CReserveKey::GetReservedKey(CPubKey &pubkey, bool internal) { | bool CReserveKey::GetReservedKey(CPubKey &pubkey, bool internal) { | ||||
if (!pwallet->CanGetAddresses(internal)) { | if (!pwallet->CanGetAddresses(internal)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (nIndex == -1) { | if (nIndex == -1) { | ||||
CKeyPool keypool; | CKeyPool keypool; | ||||
if (!pwallet->ReserveKeyFromKeyPool(nIndex, keypool, internal)) { | if (!pwallet->ReserveKeyFromKeyPool(nIndex, keypool, internal)) { | ||||
▲ Show 20 Lines • Show All 915 Lines • Show Last 20 Lines |