Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 753 Lines • ▼ Show 20 Lines | |||||
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(); | ||||
} | } | ||||
} | } | ||||
void CWallet::SetUsedDestinationState(const TxId &hash, unsigned int n, | void CWallet::SetUsedDestinationState(WalletBatch &batch, const TxId &txid, | ||||
bool used) { | unsigned int n, bool used) { | ||||
const CWalletTx *srctx = GetWalletTx(hash); | AssertLockHeld(cs_wallet); | ||||
const CWalletTx *srctx = GetWalletTx(txid); | |||||
if (!srctx) { | if (!srctx) { | ||||
return; | return; | ||||
} | } | ||||
CTxDestination dst; | CTxDestination dst; | ||||
if (ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst)) { | if (ExtractDestination(srctx->tx->vout[n].scriptPubKey, dst)) { | ||||
if (IsMine(dst)) { | if (IsMine(dst)) { | ||||
LOCK(cs_wallet); | |||||
if (used && !GetDestData(dst, "used", nullptr)) { | if (used && !GetDestData(dst, "used", nullptr)) { | ||||
// p for "present", opposite of absent (null) | // p for "present", opposite of absent (null) | ||||
AddDestData(dst, "used", "p"); | AddDestData(batch, dst, "used", "p"); | ||||
} else if (!used && GetDestData(dst, "used", nullptr)) { | } else if (!used && GetDestData(dst, "used", nullptr)) { | ||||
EraseDestData(dst, "used"); | EraseDestData(batch, dst, "used"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
bool CWallet::IsUsedDestination(const CTxDestination &dst) const { | bool CWallet::IsUsedDestination(const CTxDestination &dst) const { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
return IsMine(dst) && GetDestData(dst, "used", nullptr); | return IsMine(dst) && GetDestData(dst, "used", nullptr); | ||||
Show All 12 Lines | bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose) { | ||||
WalletBatch batch(*database, "r+", fFlushOnClose); | WalletBatch batch(*database, "r+", fFlushOnClose); | ||||
const TxId &txid = wtxIn.GetId(); | const TxId &txid = wtxIn.GetId(); | ||||
if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { | if (IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) { | ||||
// Mark used destinations | // Mark used destinations | ||||
for (const CTxIn &txin : wtxIn.tx->vin) { | for (const CTxIn &txin : wtxIn.tx->vin) { | ||||
const COutPoint &op = txin.prevout; | const COutPoint &op = txin.prevout; | ||||
SetUsedDestinationState(op.GetTxId(), op.GetN(), true); | SetUsedDestinationState(batch, op.GetTxId(), op.GetN(), true); | ||||
} | } | ||||
} | } | ||||
// Inserts only if not already there, returns tx inserted or tx found. | // Inserts only if not already there, returns tx inserted or tx found. | ||||
std::pair<std::map<TxId, CWalletTx>::iterator, bool> ret = | std::pair<std::map<TxId, CWalletTx>::iterator, bool> ret = | ||||
mapWallet.insert(std::make_pair(txid, wtxIn)); | mapWallet.insert(std::make_pair(txid, wtxIn)); | ||||
CWalletTx &wtx = (*ret.first).second; | CWalletTx &wtx = (*ret.first).second; | ||||
wtx.BindWallet(this); | wtx.BindWallet(this); | ||||
▲ Show 20 Lines • Show All 3,004 Lines • ▼ Show 20 Lines | if (!wtx.isUnconfirmed() && !wtx.isAbandoned()) { | ||||
WalletLogPrintf("%s: found %s in block %s not in index\n", __func__, | WalletLogPrintf("%s: found %s in block %s not in index\n", __func__, | ||||
wtx.GetId().ToString(), | wtx.GetId().ToString(), | ||||
wtx.m_confirm.hashBlock.ToString()); | wtx.m_confirm.hashBlock.ToString()); | ||||
} | } | ||||
} | } | ||||
return nTimeSmart; | return nTimeSmart; | ||||
} | } | ||||
bool CWallet::AddDestData(const CTxDestination &dest, const std::string &key, | bool CWallet::AddDestData(WalletBatch &batch, const CTxDestination &dest, | ||||
const std::string &value) { | const std::string &key, const std::string &value) { | ||||
if (boost::get<CNoDestination>(&dest)) { | if (boost::get<CNoDestination>(&dest)) { | ||||
return false; | return false; | ||||
} | } | ||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | ||||
return WalletBatch(*database).WriteDestData(dest, key, value); | return batch.WriteDestData(dest, key, value); | ||||
} | } | ||||
bool CWallet::EraseDestData(const CTxDestination &dest, | bool CWallet::EraseDestData(WalletBatch &batch, const CTxDestination &dest, | ||||
const std::string &key) { | const std::string &key) { | ||||
if (!mapAddressBook[dest].destdata.erase(key)) { | if (!mapAddressBook[dest].destdata.erase(key)) { | ||||
return false; | return false; | ||||
} | } | ||||
return WalletBatch(*database).EraseDestData(dest, key); | return batch.EraseDestData(dest, key); | ||||
} | } | ||||
void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, | void CWallet::LoadDestData(const CTxDestination &dest, const std::string &key, | ||||
const std::string &value) { | const std::string &value) { | ||||
mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | mapAddressBook[dest].destdata.insert(std::make_pair(key, value)); | ||||
} | } | ||||
bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, | bool CWallet::GetDestData(const CTxDestination &dest, const std::string &key, | ||||
▲ Show 20 Lines • Show All 635 Lines • Show Last 20 Lines |