Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,910 Lines • ▼ Show 20 Lines | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
int nDepth = wtx.GetDepthInMainChain(); | int nDepth = wtx.GetDepthInMainChain(); | ||||
if (!wtx.IsCoinBase() && (nDepth == 0 && !wtx.isAbandoned())) { | if (!wtx.IsCoinBase() && (nDepth == 0 && !wtx.isAbandoned())) { | ||||
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx)); | mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx)); | ||||
} | } | ||||
} | } | ||||
// Try to add wallet transactions to memory pool. | // Try to add wallet transactions to memory pool. | ||||
for (std::pair<const int64_t, CWalletTx *> &item : mapSorted) { | for (const std::pair<const int64_t, CWalletTx *> &item : mapSorted) { | ||||
CWalletTx &wtx = *(item.second); | CWalletTx &wtx = *(item.second); | ||||
CValidationState state; | CValidationState state; | ||||
wtx.AcceptToMemoryPool(maxTxFee, state); | wtx.AcceptToMemoryPool(maxTxFee, state); | ||||
} | } | ||||
} | } | ||||
bool CWalletTx::RelayWalletTransaction(CConnman *connman) { | bool CWalletTx::RelayWalletTransaction(CConnman *connman) { | ||||
assert(pwallet->GetBroadcastTransactions()); | assert(pwallet->GetBroadcastTransactions()); | ||||
▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
// Don't rebroadcast if newer than nTime: | // Don't rebroadcast if newer than nTime: | ||||
if (wtx.nTimeReceived > nTime) { | if (wtx.nTimeReceived > nTime) { | ||||
continue; | continue; | ||||
} | } | ||||
mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); | mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); | ||||
} | } | ||||
for (std::pair<const unsigned int, CWalletTx *> &item : mapSorted) { | for (const std::pair<const unsigned int, CWalletTx *> &item : mapSorted) { | ||||
CWalletTx &wtx = *item.second; | CWalletTx &wtx = *item.second; | ||||
if (wtx.RelayWalletTransaction(connman)) { | if (wtx.RelayWalletTransaction(connman)) { | ||||
result.push_back(wtx.GetId()); | result.push_back(wtx.GetId()); | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins() const { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
std::map<CTxDestination, std::vector<COutput>> result; | std::map<CTxDestination, std::vector<COutput>> result; | ||||
std::vector<COutput> availableCoins; | std::vector<COutput> availableCoins; | ||||
AvailableCoins(availableCoins); | AvailableCoins(availableCoins); | ||||
for (auto &coin : availableCoins) { | for (const auto &coin : availableCoins) { | ||||
CTxDestination address; | CTxDestination address; | ||||
if (coin.fSpendable && | if (coin.fSpendable && | ||||
ExtractDestination( | ExtractDestination( | ||||
FindNonChangeParentOutput(*coin.tx->tx, coin.i).scriptPubKey, | FindNonChangeParentOutput(*coin.tx->tx, coin.i).scriptPubKey, | ||||
address)) { | address)) { | ||||
result[address].emplace_back(std::move(coin)); | result[address].emplace_back(std::move(coin)); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,006 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* Mark old keypool keys as used, and generate all new keys. | * Mark old keypool keys as used, and generate all new keys. | ||||
*/ | */ | ||||
bool CWallet::NewKeyPool() { | bool CWallet::NewKeyPool() { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
WalletBatch batch(*database); | WalletBatch batch(*database); | ||||
for (int64_t nIndex : setInternalKeyPool) { | for (const int64_t nIndex : setInternalKeyPool) { | ||||
batch.ErasePool(nIndex); | batch.ErasePool(nIndex); | ||||
} | } | ||||
setInternalKeyPool.clear(); | setInternalKeyPool.clear(); | ||||
for (int64_t nIndex : setExternalKeyPool) { | for (const int64_t nIndex : setExternalKeyPool) { | ||||
batch.ErasePool(nIndex); | batch.ErasePool(nIndex); | ||||
} | } | ||||
setExternalKeyPool.clear(); | setExternalKeyPool.clear(); | ||||
for (int64_t nIndex : set_pre_split_keypool) { | for (int64_t nIndex : set_pre_split_keypool) { | ||||
batch.ErasePool(nIndex); | batch.ErasePool(nIndex); | ||||
} | } | ||||
set_pre_split_keypool.clear(); | set_pre_split_keypool.clear(); | ||||
▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | std::set<std::set<CTxDestination>> CWallet::GetAddressGroupings() { | ||||
// A set of pointers to groups of addresses. | // A set of pointers to groups of addresses. | ||||
std::set<std::set<CTxDestination> *> uniqueGroupings; | std::set<std::set<CTxDestination> *> uniqueGroupings; | ||||
// Map addresses to the unique group containing it. | // Map addresses to the unique group containing it. | ||||
std::map<CTxDestination, std::set<CTxDestination> *> setmap; | std::map<CTxDestination, std::set<CTxDestination> *> setmap; | ||||
for (std::set<CTxDestination> _grouping : groupings) { | for (std::set<CTxDestination> _grouping : groupings) { | ||||
// Make a set of all the groups hit by this new group. | // Make a set of all the groups hit by this new group. | ||||
std::set<std::set<CTxDestination> *> hits; | std::set<std::set<CTxDestination> *> hits; | ||||
std::map<CTxDestination, std::set<CTxDestination> *>::iterator it; | std::map<CTxDestination, std::set<CTxDestination> *>::iterator it; | ||||
for (CTxDestination address : _grouping) { | for (const CTxDestination &address : _grouping) { | ||||
if ((it = setmap.find(address)) != setmap.end()) { | if ((it = setmap.find(address)) != setmap.end()) { | ||||
hits.insert((*it).second); | hits.insert((*it).second); | ||||
} | } | ||||
} | } | ||||
// Merge all hit groups into a new single group and delete old groups. | // Merge all hit groups into a new single group and delete old groups. | ||||
std::set<CTxDestination> *merged = | std::set<CTxDestination> *merged = | ||||
new std::set<CTxDestination>(_grouping); | new std::set<CTxDestination>(_grouping); | ||||
for (std::set<CTxDestination> *hit : hits) { | for (std::set<CTxDestination> *hit : hits) { | ||||
merged->insert(hit->begin(), hit->end()); | merged->insert(hit->begin(), hit->end()); | ||||
uniqueGroupings.erase(hit); | uniqueGroupings.erase(hit); | ||||
delete hit; | delete hit; | ||||
} | } | ||||
uniqueGroupings.insert(merged); | uniqueGroupings.insert(merged); | ||||
// Update setmap. | // Update setmap. | ||||
for (CTxDestination element : *merged) { | for (const CTxDestination &element : *merged) { | ||||
setmap[element] = merged; | setmap[element] = merged; | ||||
} | } | ||||
} | } | ||||
std::set<std::set<CTxDestination>> ret; | std::set<std::set<CTxDestination>> ret; | ||||
for (std::set<CTxDestination> *uniqueGrouping : uniqueGroupings) { | for (const std::set<CTxDestination> *uniqueGrouping : uniqueGroupings) { | ||||
ret.insert(*uniqueGrouping); | ret.insert(*uniqueGrouping); | ||||
delete uniqueGrouping; | delete uniqueGrouping; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
std::set<CTxDestination> | std::set<CTxDestination> | ||||
▲ Show 20 Lines • Show All 910 Lines • Show Last 20 Lines |