Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,641 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, | int64_t CalculateMaximumSignedTxSize(const CTransaction &tx, | ||||
const CWallet *wallet) { | const CWallet *wallet) { | ||||
std::vector<CTxOut> txouts; | std::vector<CTxOut> txouts; | ||||
// Look up the inputs. We should have already checked that this transaction | // Look up the inputs. We should have already checked that this transaction | ||||
// IsAllFromMe(ISMINE_SPENDABLE), so every input should already be in our | // IsAllFromMe(ISMINE_SPENDABLE), so every input should already be in our | ||||
// wallet, with a valid index into the vout array, and the ability to sign. | // wallet, with a valid index into the vout array, and the ability to sign. | ||||
for (auto &input : tx.vin) { | for (const auto &input : tx.vin) { | ||||
const auto mi = wallet->mapWallet.find(input.prevout.GetTxId()); | const auto mi = wallet->mapWallet.find(input.prevout.GetTxId()); | ||||
if (mi == wallet->mapWallet.end()) { | if (mi == wallet->mapWallet.end()) { | ||||
return -1; | return -1; | ||||
} | } | ||||
assert(input.prevout.GetN() < mi->second.tx->vout.size()); | assert(input.prevout.GetN() < mi->second.tx->vout.size()); | ||||
txouts.emplace_back(mi->second.tx->vout[input.prevout.GetN()]); | txouts.emplace_back(mi->second.tx->vout[input.prevout.GetN()]); | ||||
} | } | ||||
return CalculateMaximumSignedTxSize(tx, wallet, txouts); | return CalculateMaximumSignedTxSize(tx, wallet, txouts); | ||||
▲ Show 20 Lines • Show All 260 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 auto &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 auto &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,351 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 841 Lines • Show Last 20 Lines |