diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -482,7 +482,7 @@ for (const COutput &out : vOutputs) { // unselect already spent, very unlikely scenario, this could happen // when selected are spent elsewhere, like rpc or another computer - uint256 txhash = out.tx->GetId(); + TxHash txhash = out.tx->GetHash(); COutPoint outpt(txhash, out.i); if (model->isSpent(outpt)) { coinControl->UnSelect(outpt); @@ -795,7 +795,7 @@ QVariant((qlonglong)out.nDepth)); // transaction hash - uint256 txhash = out.tx->GetId(); + TxHash txhash = out.tx->GetHash(); itemOutput->setText(COLUMN_TXHASH, QString::fromStdString(txhash.GetHex())); diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -37,7 +37,7 @@ Amount nCredit = wtx.GetCredit(ISMINE_ALL); Amount nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nNet = (nCredit - nDebit).GetSatoshis(); - uint256 hash = wtx.GetId(); + TxHash hash = wtx.GetHash(); std::map mapValue = wtx.mapValue; if (nNet > 0 || wtx.IsCoinBase()) { diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -42,10 +42,10 @@ const TransactionRecord &b) const { return a.hash < b.hash; } - bool operator()(const TransactionRecord &a, const uint256 &b) const { + bool operator()(const TransactionRecord &a, const TxHash &b) const { return a.hash < b; } - bool operator()(const uint256 &a, const TransactionRecord &b) const { + bool operator()(const TxHash &a, const TransactionRecord &b) const { return a < b.hash; } }; @@ -72,7 +72,7 @@ cachedWallet.clear(); { LOCK2(cs_main, wallet->cs_wallet); - for (std::map::iterator it = + for (std::map::iterator it = wallet->mapWallet.begin(); it != wallet->mapWallet.end(); ++it) { if (TransactionRecord::showTransaction(it->second)) @@ -87,7 +87,7 @@ * the wallet with that of the core. * Call with transaction that was added, removed or changed. */ - void updateWallet(const uint256 &hash, int status, bool showTransaction) { + void updateWallet(const TxHash &hash, int status, bool showTransaction) { qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status); @@ -125,7 +125,7 @@ if (showTransaction) { LOCK2(cs_main, wallet->cs_wallet); // Find transaction in wallet - std::map::iterator mi = + std::map::iterator mi = wallet->mapWallet.find(hash); if (mi == wallet->mapWallet.end()) { qWarning() << "TransactionTablePriv::updateWallet: " @@ -189,7 +189,7 @@ if (lockMain) { TRY_LOCK(wallet->cs_wallet, lockWallet); if (lockWallet && rec->statusUpdateNeeded()) { - std::map::iterator mi = + std::map::iterator mi = wallet->mapWallet.find(rec->hash); if (mi != wallet->mapWallet.end()) { @@ -205,7 +205,7 @@ QString describe(TransactionRecord *rec, int unit) { { LOCK2(cs_main, wallet->cs_wallet); - std::map::iterator mi = + std::map::iterator mi = wallet->mapWallet.find(rec->hash); if (mi != wallet->mapWallet.end()) { return TransactionDesc::toHTML(wallet, mi->second, rec, unit); @@ -216,7 +216,7 @@ QString getTxHex(TransactionRecord *rec) { LOCK2(cs_main, wallet->cs_wallet); - std::map::iterator mi = + std::map::iterator mi = wallet->mapWallet.find(rec->hash); if (mi != wallet->mapWallet.end()) { std::string strHex = @@ -258,7 +258,7 @@ void TransactionTableModel::updateTransaction(const QString &hash, int status, bool showTransaction) { - uint256 updated; + TxHash updated; updated.SetHex(hash.toStdString()); priv->updateWallet(updated, status, showTransaction); @@ -706,7 +706,7 @@ struct TransactionNotification { public: TransactionNotification() {} - TransactionNotification(uint256 _hash, ChangeType _status, + TransactionNotification(TxHash _hash, ChangeType _status, bool _showTransaction) : hash(_hash), status(_status), showTransaction(_showTransaction) {} @@ -721,7 +721,7 @@ } private: - uint256 hash; + TxHash hash; ChangeType status; bool showTransaction; }; @@ -730,10 +730,10 @@ static std::vector vQueueNotifications; static void NotifyTransactionChanged(TransactionTableModel *ttm, - CWallet *wallet, const uint256 &hash, + CWallet *wallet, const TxHash &hash, ChangeType status) { // Find transaction in wallet - std::map::iterator mi = wallet->mapWallet.find(hash); + std::map::iterator mi = wallet->mapWallet.find(hash); // Determine whether to show transaction or not (determine this here so that // no relocking is needed in GUI thread) bool inWallet = mi != wallet->mapWallet.end(); diff --git a/src/validationinterface.h b/src/validationinterface.h --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -20,6 +20,7 @@ class CValidationInterface; class CValidationState; class uint256; +class TxHash; // These functions dispatch to one or all registered wallets @@ -38,7 +39,7 @@ virtual void SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, int posInBlock) {} virtual void SetBestChain(const CBlockLocator &locator) {} - virtual void UpdatedTransaction(const uint256 &hash) {} + virtual void UpdatedTransaction(const TxHash &hash) {} virtual void Inventory(const uint256 &hash) {} virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman) {} @@ -78,7 +79,7 @@ * Notifies listeners of an updated transaction without new data (for now: a * coinbase potentially becoming visible). */ - boost::signals2::signal UpdatedTransaction; + boost::signals2::signal UpdatedTransaction; /** Notifies listeners of a new active block chain. */ boost::signals2::signal SetBestChain; /** Notifies listeners about an inventory item being seen on the network. */ diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -364,11 +364,11 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - uint256 hash; + TxHash hash; hash.SetHex(request.params[0].get_str()); - std::vector vHash; + std::vector vHash; vHash.push_back(hash); - std::vector vHashOut; + std::vector vHashOut; if (pwalletMain->ZapSelectTx(vHash, vHashOut) != DB_LOAD_OK) { throw JSONRPCError(RPC_WALLET_ERROR, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -69,10 +69,10 @@ } else { entry.push_back(Pair("trusted", wtx.IsTrusted())); } - uint256 hash = wtx.GetId(); + TxHash hash = wtx.GetHash(); entry.push_back(Pair("txid", hash.GetHex())); UniValue conflicts(UniValue::VARR); - for (const uint256 &conflict : wtx.GetConflicts()) { + for (const TxHash &conflict : wtx.GetConflicts()) { conflicts.push_back(conflict.GetHex()); } entry.push_back(Pair("walletconflicts", conflicts)); @@ -508,7 +508,7 @@ SendMoney(dest, nAmount, fSubtractFeeFromAmount, wtx); - return wtx.GetId().GetHex(); + return wtx.GetHash().GetHex(); } static UniValue listaddressgroupings(const Config &config, @@ -698,7 +698,7 @@ // Tally Amount nAmount = 0; - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -771,7 +771,7 @@ // Tally Amount nAmount = 0; - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -876,7 +876,7 @@ // TxIns spending from the wallet. This also has fewer restrictions on // which unconfirmed transactions are considered trusted. Amount nBalance = 0; - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -1101,7 +1101,7 @@ SendMoney(dest, nAmount, false, wtx); - return wtx.GetId().GetHex(); + return wtx.GetHash().GetHex(); } static UniValue sendmany(const Config &config, const JSONRPCRequest &request) { @@ -1276,7 +1276,7 @@ throw JSONRPCError(RPC_WALLET_ERROR, strFailReason); } - return wtx.GetId().GetHex(); + return wtx.GetHash().GetHex(); } static UniValue addmultisigaddress(const Config &config, @@ -1373,7 +1373,7 @@ // Tally std::map mapTally; - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -1405,7 +1405,7 @@ tallyitem &item = mapTally[address]; item.nAmount += txout.nValue; item.nConf = std::min(item.nConf, nDepth); - item.txids.push_back(wtx.GetId()); + item.txids.push_back(wtx.GetHash()); if (mine & ISMINE_WATCH_ONLY) { item.fIsWatchonly = true; } @@ -1932,7 +1932,7 @@ } } - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; @@ -2102,7 +2102,7 @@ UniValue transactions(UniValue::VARR); - for (std::map::iterator it = + for (std::map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++) { CWalletTx tx = (*it).second; @@ -2215,7 +2215,7 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - uint256 hash; + TxHash hash; hash.SetHex(request.params[0].get_str()); isminefilter filter = ISMINE_SPENDABLE; @@ -2945,11 +2945,11 @@ LOCK2(cs_main, pwalletMain->cs_wallet); - std::vector txids = + std::vector txids = pwalletMain->ResendWalletTransactionsBefore(GetTime(), g_connman.get()); UniValue result(UniValue::VARR); - for (const uint256 &txid : txids) { - result.push_back(txid.ToString()); + for (const TxHash &txhash : txids) { + result.push_back(txhash.ToString()); } return result; @@ -3082,7 +3082,7 @@ continue; UniValue entry(UniValue::VOBJ); - entry.push_back(Pair("txid", out.tx->GetId().GetHex())); + entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("vout", out.i)); if (fValidAddress) { diff --git a/src/wallet/test/accounting_tests.cpp b/src/wallet/test/accounting_tests.cpp --- a/src/wallet/test/accounting_tests.cpp +++ b/src/wallet/test/accounting_tests.cpp @@ -42,7 +42,7 @@ wtx.mapValue["comment"] = "z"; pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx[0]->nTimeReceived = (unsigned int)1333333335; vpwtx[0]->nOrderPos = -1; @@ -83,7 +83,7 @@ wtx.SetTx(MakeTransactionRef(std::move(tx))); } pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx[1]->nTimeReceived = (unsigned int)1333333336; wtx.mapValue["comment"] = "x"; @@ -94,7 +94,7 @@ wtx.SetTx(MakeTransactionRef(std::move(tx))); } pwalletMain->AddToWallet(wtx); - vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetId()]); + vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx[2]->nTimeReceived = (unsigned int)1333333329; vpwtx[2]->nOrderPos = -1; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -244,7 +244,7 @@ bool isAbandoned() const { return (hashBlock == ABANDON_HASH); } void setAbandoned() { hashBlock = ABANDON_HASH; } - const uint256 &GetId() const { return tx->GetHash(); } + const TxHash &GetHash() const { return tx->GetHash(); } bool IsCoinBase() const { return tx->IsCoinBase(); } }; @@ -425,7 +425,7 @@ bool RelayWalletTransaction(CConnman *connman); - std::set GetConflicts() const; + std::set GetConflicts() const; }; class COutput { @@ -585,14 +585,14 @@ * Used to keep track of spent outpoints, and detect and report conflicts * (double-spends or mutated transactions where the mutant gets mined). */ - typedef std::multimap TxSpends; + typedef std::multimap TxSpends; TxSpends mapTxSpends; - void AddToSpends(const COutPoint &outpoint, const uint256 &wtxid); - void AddToSpends(const uint256 &wtxid); + void AddToSpends(const COutPoint &outpoint, const TxHash &wtxid); + void AddToSpends(const TxHash &wtxid); /* Mark a transaction (and its in-wallet descendants) as conflicting with a * particular block. */ - void MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx); + void MarkConflicted(const uint256 &hashBlock, const TxHash &hashTx); void SyncMetaData(std::pair); @@ -673,7 +673,7 @@ fBroadcastTransactions = false; } - std::map mapWallet; + std::map mapWallet; std::list laccentries; typedef std::pair TxPair; @@ -681,7 +681,7 @@ TxItems wtxOrdered; int64_t nOrderPosNext; - std::map mapRequestCount; + std::map mapRequestCount; std::map mapAddressBook; @@ -689,7 +689,7 @@ std::set setLockedCoins; - const CWalletTx *GetWalletTx(const uint256 &hash) const; + const CWalletTx *GetWalletTx(const TxHash &hash) const; //! check whether we are allowed to upgrade (or already support) to the //! named feature @@ -718,9 +718,9 @@ std::set> &setCoinsRet, Amount &nValueRet) const; - bool IsSpent(const uint256 &hash, unsigned int n) const; + bool IsSpent(const TxHash &hash, unsigned int n) const; - bool IsLockedCoin(uint256 hash, unsigned int n) const; + bool IsLockedCoin(TxHash hash, unsigned int n) const; void LockCoin(const COutPoint &output); void UnlockCoin(const COutPoint &output); void UnlockAllCoins(); @@ -812,8 +812,8 @@ void ReacceptWalletTransactions(); void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman) override; - std::vector ResendWalletTransactionsBefore(int64_t nTime, - CConnman *connman); + std::vector ResendWalletTransactionsBefore(int64_t nTime, + CConnman *connman); Amount GetBalance() const; Amount GetUnconfirmedBalance() const; Amount GetImmatureBalance() const; @@ -919,19 +919,19 @@ DBErrors LoadWallet(bool &fFirstRunRet); DBErrors ZapWalletTx(std::vector &vWtx); - DBErrors ZapSelectTx(std::vector &vHashIn, - std::vector &vHashOut); + DBErrors ZapSelectTx(std::vector &vHashIn, + std::vector &vHashOut); bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose); bool DelAddressBook(const CTxDestination &address); - void UpdatedTransaction(const uint256 &hashTx) override; + void UpdatedTransaction(const TxHash &hashTx) override; void Inventory(const uint256 &hash) override { LOCK(cs_wallet); - std::map::iterator mi = mapRequestCount.find(hash); + std::map::iterator mi = mapRequestCount.find(hash); if (mi != mapRequestCount.end()) { (*mi).second++; } @@ -940,7 +940,7 @@ void GetScriptForMining(std::shared_ptr &script) override; void ResetRequestCount(const uint256 &hash) override { LOCK(cs_wallet); - mapRequestCount[hash] = 0; + mapRequestCount[TxHash(hash)] = 0; }; unsigned int GetKeyPoolSize() { @@ -969,11 +969,11 @@ //! Get wallet transactions that conflict with given transaction (spend same //! outputs) - std::set GetConflicts(const uint256 &txid) const; + std::set GetConflicts(const TxHash &txid) const; //! Check if a given transaction has any of its outputs spent by another //! transaction in the wallet - bool HasWalletSpend(const uint256 &txid) const; + bool HasWalletSpend(const TxHash &txid) const; //! Flush wallet (bitdb flush) void Flush(bool shutdown = false); @@ -994,7 +994,7 @@ * Wallet transaction added, removed or updated. * @note called with lock cs_wallet held. */ - boost::signals2::signal NotifyTransactionChanged; @@ -1016,12 +1016,12 @@ * Mark a transaction (and it in-wallet descendants) as abandoned so its * inputs may be respent. */ - bool AbandonTransaction(const uint256 &hashTx); + bool AbandonTransaction(const TxHash &hashTx); /** * Mark a transaction as replaced by another transaction (e.g., BIP 125). */ - bool MarkReplaced(const uint256 &originalHash, const uint256 &newHash); + bool MarkReplaced(const TxHash &originalHash, const TxHash &newHash); /* Returns the wallets help message */ static std::string GetWalletHelpString(bool showDebug); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -77,13 +77,13 @@ }; std::string COutput::ToString() const { - return strprintf("COutput(%s, %d, %d) [%s]", tx->GetId().ToString(), i, + return strprintf("COutput(%s, %d, %d) [%s]", tx->GetHash().ToString(), i, nDepth, FormatMoney(tx->tx->vout[i].nValue)); } -const CWalletTx *CWallet::GetWalletTx(const uint256 &hash) const { +const CWalletTx *CWallet::GetWalletTx(const TxHash &hash) const { LOCK(cs_wallet); - std::map::const_iterator it = mapWallet.find(hash); + std::map::const_iterator it = mapWallet.find(hash); if (it == mapWallet.end()) { return nullptr; } @@ -486,11 +486,11 @@ return true; } -std::set CWallet::GetConflicts(const uint256 &txid) const { - std::set result; +std::set CWallet::GetConflicts(const TxHash &txid) const { + std::set result; AssertLockHeld(cs_wallet); - std::map::const_iterator it = mapWallet.find(txid); + std::map::const_iterator it = mapWallet.find(txid); if (it == mapWallet.end()) { return result; } @@ -515,7 +515,7 @@ return result; } -bool CWallet::HasWalletSpend(const uint256 &txid) const { +bool CWallet::HasWalletSpend(const TxHash &txid) const { AssertLockHeld(cs_wallet); auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0)); return (iter != mapTxSpends.end() && iter->first.hash == txid); @@ -603,7 +603,7 @@ int nMinOrderPos = std::numeric_limits::max(); const CWalletTx *copyFrom = nullptr; for (TxSpends::iterator it = range.first; it != range.second; ++it) { - const uint256 &hash = it->second; + const TxHash &hash = it->second; int n = mapWallet[hash].nOrderPos; if (n < nMinOrderPos) { nMinOrderPos = n; @@ -613,7 +613,7 @@ // Now copy data from copyFrom to rest: for (TxSpends::iterator it = range.first; it != range.second; ++it) { - const uint256 &hash = it->second; + const TxHash &hash = it->second; CWalletTx *copyTo = &mapWallet[hash]; if (copyFrom == copyTo) { continue; @@ -637,15 +637,15 @@ /** * Outpoint is spent if any non-conflicted transaction, spends it: */ -bool CWallet::IsSpent(const uint256 &hash, unsigned int n) const { +bool CWallet::IsSpent(const TxHash &hash, unsigned int n) const { const COutPoint outpoint(hash, n); std::pair range; range = mapTxSpends.equal_range(outpoint); for (TxSpends::const_iterator it = range.first; it != range.second; ++it) { - const uint256 &wtxid = it->second; - std::map::const_iterator mit = - mapWallet.find(wtxid); + const TxHash &wtxhash = it->second; + std::map::const_iterator mit = + mapWallet.find(wtxhash); if (mit != mapWallet.end()) { int depth = mit->second.GetDepthInMainChain(); if (depth > 0 || (depth == 0 && !mit->second.isAbandoned())) { @@ -658,24 +658,24 @@ return false; } -void CWallet::AddToSpends(const COutPoint &outpoint, const uint256 &wtxid) { - mapTxSpends.insert(std::make_pair(outpoint, wtxid)); +void CWallet::AddToSpends(const COutPoint &outpoint, const TxHash &wtxhash) { + mapTxSpends.insert(std::make_pair(outpoint, wtxhash)); std::pair range; range = mapTxSpends.equal_range(outpoint); SyncMetaData(range); } -void CWallet::AddToSpends(const uint256 &wtxid) { - assert(mapWallet.count(wtxid)); - CWalletTx &thisTx = mapWallet[wtxid]; +void CWallet::AddToSpends(const TxHash &wtxhash) { + assert(mapWallet.count(wtxhash)); + CWalletTx &thisTx = mapWallet[wtxhash]; // Coinbases don't spend anything! if (thisTx.IsCoinBase()) { return; } for (const CTxIn &txin : thisTx.tx->vin) { - AddToSpends(txin.prevout, wtxid); + AddToSpends(txin.prevout, wtxhash); } } @@ -808,7 +808,7 @@ typedef std::multimap TxItems; TxItems txByTime; - for (std::map::iterator it = mapWallet.begin(); + for (std::map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { CWalletTx *wtx = &((*it).second); txByTime.insert( @@ -936,7 +936,7 @@ // Check if the current key has been used. CScript scriptPubKey = GetScriptForDestination(account.vchPubKey.GetID()); - for (std::map::iterator it = mapWallet.begin(); + for (std::map::iterator it = mapWallet.begin(); it != mapWallet.end() && account.vchPubKey.IsValid(); ++it) { for (const CTxOut &txout : (*it).second.tx->vout) { if (txout.scriptPubKey == scriptPubKey) { @@ -965,13 +965,12 @@ void CWallet::MarkDirty() { LOCK(cs_wallet); - for (std::pair &item : mapWallet) { + for (std::pair &item : mapWallet) { item.second.MarkDirty(); } } -bool CWallet::MarkReplaced(const uint256 &originalHash, - const uint256 &newHash) { +bool CWallet::MarkReplaced(const TxHash &originalHash, const TxHash &newHash) { LOCK(cs_wallet); auto mi = mapWallet.find(originalHash); @@ -992,7 +991,7 @@ bool success = true; if (!walletdb.WriteTx(wtx)) { LogPrintf("%s: Updating walletdb tx %s failed", __func__, - wtx.GetId().ToString()); + wtx.GetHash().ToString()); success = false; } @@ -1006,10 +1005,10 @@ CWalletDB walletdb(strWalletFile, "r+", fFlushOnClose); - uint256 hash = wtxIn.GetId(); + TxHash hash = wtxIn.GetHash(); // Inserts only if not already there, returns tx inserted or tx found. - std::pair::iterator, bool> ret = + std::pair::iterator, bool> ret = mapWallet.insert(std::make_pair(hash, wtxIn)); CWalletTx &wtx = (*ret.first).second; wtx.BindWallet(this); @@ -1065,7 +1064,8 @@ std::max(latestEntry, std::min(blocktime, latestNow)); } else { LogPrintf("AddToWallet(): found %s in block %s not in index\n", - wtxIn.GetId().ToString(), wtxIn.hashBlock.ToString()); + wtxIn.GetHash().ToString(), + wtxIn.hashBlock.ToString()); } } @@ -1098,7 +1098,7 @@ } //// debug print - LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetId().ToString(), + LogPrintf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : "")); // Write to disk @@ -1117,7 +1117,7 @@ std::string strCmd = GetArg("-walletnotify", ""); if (!strCmd.empty()) { - boost::replace_all(strCmd, "%s", wtxIn.GetId().GetHex()); + boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex()); // Thread runs free. boost::thread t(runCommand, strCmd); } @@ -1126,18 +1126,18 @@ } bool CWallet::LoadToWallet(const CWalletTx &wtxIn) { - uint256 txid = wtxIn.GetId(); + TxHash txhash = wtxIn.GetHash(); - mapWallet[txid] = wtxIn; - CWalletTx &wtx = mapWallet[txid]; + mapWallet[txhash] = wtxIn; + CWalletTx &wtx = mapWallet[txhash]; wtx.BindWallet(this); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr))); - AddToSpends(txid); + AddToSpends(txhash); for (const CTxIn &txin : wtx.tx->vin) { if (mapWallet.count(txin.prevout.hash)) { CWalletTx &prevtx = mapWallet[txin.prevout.hash]; if (prevtx.nIndex == -1 && !prevtx.hashUnset()) { - MarkConflicted(prevtx.hashBlock, wtx.GetId()); + MarkConflicted(prevtx.hashBlock, wtx.GetHash()); } } } @@ -1202,13 +1202,13 @@ return false; } -bool CWallet::AbandonTransaction(const uint256 &hashTx) { +bool CWallet::AbandonTransaction(const TxHash &hashTx) { LOCK2(cs_main, cs_wallet); CWalletDB walletdb(strWalletFile, "r+"); - std::set todo; - std::set done; + std::set todo; + std::set done; // Can't mark abandoned if confirmed or in mempool. assert(mapWallet.count(hashTx)); @@ -1220,7 +1220,7 @@ todo.insert(hashTx); while (!todo.empty()) { - uint256 now = *todo.begin(); + TxHash now = *todo.begin(); todo.erase(now); done.insert(now); assert(mapWallet.count(now)); @@ -1238,7 +1238,7 @@ wtx.setAbandoned(); wtx.MarkDirty(); walletdb.WriteTx(wtx); - NotifyTransactionChanged(this, wtx.GetId(), CT_UPDATED); + NotifyTransactionChanged(this, wtx.GetHash(), CT_UPDATED); // Iterate over all its outputs, and mark transactions in the wallet // that spend them abandoned too. TxSpends::const_iterator iter = @@ -1263,7 +1263,7 @@ return true; } -void CWallet::MarkConflicted(const uint256 &hashBlock, const uint256 &hashTx) { +void CWallet::MarkConflicted(const uint256 &hashBlock, const TxHash &hashTx) { LOCK2(cs_main, cs_wallet); int conflictconfirms = 0; @@ -1284,13 +1284,13 @@ // Do not flush the wallet here for performance reasons CWalletDB walletdb(strWalletFile, "r+", false); - std::set todo; - std::set done; + std::set todo; + std::set done; todo.insert(hashTx); while (!todo.empty()) { - uint256 now = *todo.begin(); + TxHash now = *todo.begin(); todo.erase(now); done.insert(now); assert(mapWallet.count(now)); @@ -1346,7 +1346,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const { LOCK(cs_wallet); - std::map::const_iterator mi = + std::map::const_iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx &prev = (*mi).second; @@ -1362,7 +1362,7 @@ // not-"is mine" (according to the filter) input. Amount CWallet::GetDebit(const CTxIn &txin, const isminefilter &filter) const { LOCK(cs_wallet); - std::map::const_iterator mi = + std::map::const_iterator mi = mapWallet.find(txin.prevout.hash); if (mi != mapWallet.end()) { const CWalletTx &prev = (*mi).second; @@ -1577,7 +1577,7 @@ if (IsCoinBase()) { // Generated block. if (!hashUnset()) { - std::map::const_iterator mi = + std::map::const_iterator mi = pwallet->mapRequestCount.find(hashBlock); if (mi != pwallet->mapRequestCount.end()) { nRequests = (*mi).second; @@ -1585,14 +1585,14 @@ } } else { // Did anyone request this transaction? - std::map::const_iterator mi = - pwallet->mapRequestCount.find(GetId()); + std::map::const_iterator mi = + pwallet->mapRequestCount.find(GetHash()); if (mi != pwallet->mapRequestCount.end()) { nRequests = (*mi).second; // How about the block it's in? if (nRequests == 0 && !hashUnset()) { - std::map::const_iterator _mi = + std::map::const_iterator _mi = pwallet->mapRequestCount.find(hashBlock); if (_mi != pwallet->mapRequestCount.end()) { nRequests = (*_mi).second; @@ -1647,7 +1647,7 @@ !txout.scriptPubKey.IsUnspendable()) { LogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, " "txid %s\n", - this->GetId().ToString()); + this->GetHash().ToString()); address = CNoDestination(); } @@ -1786,10 +1786,10 @@ // Sort pending wallet transactions based on their initial wallet insertion // order. - for (std::pair &item : mapWallet) { - const uint256 &wtxid = item.first; + for (std::pair &item : mapWallet) { + const TxHash &wtxhash = item.first; CWalletTx &wtx = item.second; - assert(wtx.GetId() == wtxid); + assert(wtx.GetHash() == wtxhash); int nDepth = wtx.GetDepthInMainChain(); @@ -1817,9 +1817,9 @@ CValidationState state; // GetDepthInMainChain already catches known conflicts. if (InMempool() || AcceptToMemoryPool(maxTxFee, state)) { - LogPrintf("Relaying wtx %s\n", GetId().ToString()); + LogPrintf("Relaying wtx %s\n", GetHash().ToString()); if (connman) { - CInv inv(MSG_TX, GetId()); + CInv inv(MSG_TX, GetHash()); connman->ForEachNode( [&inv](CNode *pnode) { pnode->PushInventory(inv); }); return true; @@ -1829,10 +1829,10 @@ return false; } -std::set CWalletTx::GetConflicts() const { - std::set result; +std::set CWalletTx::GetConflicts() const { + std::set result; if (pwallet != nullptr) { - uint256 myHash = GetId(); + TxHash myHash = GetHash(); result = pwallet->GetConflicts(myHash); result.erase(myHash); } @@ -1926,7 +1926,7 @@ } Amount nCredit = 0; - uint256 hashTx = GetId(); + TxHash hashTx = GetHash(); for (unsigned int i = 0; i < tx->vout.size(); i++) { if (!pwallet->IsSpent(hashTx, i)) { const CTxOut &txout = tx->vout[i]; @@ -1975,7 +1975,7 @@ Amount nCredit = 0; for (unsigned int i = 0; i < tx->vout.size(); i++) { - if (!pwallet->IsSpent(GetId(), i)) { + if (!pwallet->IsSpent(GetHash(), i)) { const CTxOut &txout = tx->vout[i]; nCredit += pwallet->GetCredit(txout, ISMINE_WATCH_ONLY); if (!MoneyRange(nCredit)) { @@ -2002,7 +2002,7 @@ bool CWalletTx::InMempool() const { LOCK(mempool.cs); - if (mempool.exists(GetId())) { + if (mempool.exists(GetHash())) { return true; } @@ -2066,14 +2066,14 @@ return CTransaction(tx1) == CTransaction(tx2); } -std::vector -CWallet::ResendWalletTransactionsBefore(int64_t nTime, CConnman *connman) { - std::vector result; +std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime, + CConnman *connman) { + std::vector result; LOCK(cs_wallet); // Sort them in chronological order std::multimap mapSorted; - for (std::pair &item : mapWallet) { + for (std::pair &item : mapWallet) { CWalletTx &wtx = item.second; // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) { @@ -2086,7 +2086,7 @@ for (std::pair &item : mapSorted) { CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction(connman)) { - result.push_back(wtx.GetId()); + result.push_back(wtx.GetHash()); } } @@ -2116,7 +2116,7 @@ // Rebroadcast unconfirmed txes older than 5 minutes before the last block // was found: - std::vector relayed = + std::vector relayed = ResendWalletTransactionsBefore(nBestBlockTime - 5 * 60, connman); if (!relayed.empty()) { LogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, @@ -2135,7 +2135,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; if (pcoin->IsTrusted()) { @@ -2150,7 +2150,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && @@ -2166,7 +2166,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; nTotal += pcoin->GetImmatureCredit(); @@ -2179,7 +2179,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; if (pcoin->IsTrusted()) { @@ -2194,7 +2194,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; if (!pcoin->IsTrusted() && pcoin->GetDepthInMainChain() == 0 && @@ -2210,7 +2210,7 @@ LOCK2(cs_main, cs_wallet); Amount nTotal = 0; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx *pcoin = &(*it).second; nTotal += pcoin->GetImmatureWatchOnlyCredit(); @@ -2225,9 +2225,9 @@ vCoins.clear(); LOCK2(cs_main, cs_wallet); - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { - const uint256 &wtxid = it->first; + const TxHash &wtxhash = it->first; const CWalletTx *pcoin = &(*it).second; if (!CheckFinalTx(*pcoin)) { @@ -2277,7 +2277,7 @@ for (unsigned int i = 0; i < pcoin->tx->vout.size(); i++) { isminetype mine = IsMine(pcoin->tx->vout[i]); - if (!(IsSpent(wtxid, i)) && mine != ISMINE_NO && + if (!(IsSpent(wtxhash, i)) && mine != ISMINE_NO && !IsLockedCoin((*it).first, i) && (pcoin->tx->vout[i].nValue > 0 || fIncludeZeroValue) && (!coinControl || !coinControl->HasSelected() || @@ -2368,7 +2368,7 @@ continue; } - if (!mempool.TransactionWithinChainLimit(pcoin->GetId(), + if (!mempool.TransactionWithinChainLimit(pcoin->GetHash(), nMaxAncestors)) { continue; } @@ -2483,7 +2483,7 @@ } for (const COutPoint &outpoint : vPresetInputs) { - std::map::const_iterator it = + std::map::const_iterator it = mapWallet.find(outpoint.hash); if (it == mapWallet.end()) { // TODO: Allow non-wallet inputs @@ -2859,7 +2859,7 @@ // nLockTime set above actually works. for (const auto &coin : setCoins) { txNew.vin.push_back( - CTxIn(coin.first->GetId(), coin.second, CScript(), + CTxIn(coin.first->GetHash(), coin.second, CScript(), std::numeric_limits::max() - 1)); } @@ -3044,11 +3044,11 @@ for (const CTxIn &txin : wtxNew.tx->vin) { CWalletTx &coin = mapWallet[txin.prevout.hash]; coin.BindWallet(this); - NotifyTransactionChanged(this, coin.GetId(), CT_UPDATED); + NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED); } // Track how many getdata requests our transaction gets. - mapRequestCount[wtxNew.GetId()] = 0; + mapRequestCount[wtxNew.GetHash()] = 0; if (fBroadcastTransactions) { // Broadcast @@ -3159,8 +3159,8 @@ return DB_LOAD_OK; } -DBErrors CWallet::ZapSelectTx(std::vector &vHashIn, - std::vector &vHashOut) { +DBErrors CWallet::ZapSelectTx(std::vector &vHashIn, + std::vector &vHashOut) { if (!fFileBacked) { return DB_LOAD_OK; } @@ -3443,7 +3443,7 @@ std::map balances; LOCK(cs_wallet); - for (std::pair walletEntry : mapWallet) { + for (std::pair walletEntry : mapWallet) { CWalletTx *pcoin = &walletEntry.second; if (!pcoin->IsTrusted()) { @@ -3486,7 +3486,7 @@ std::set> groupings; std::set grouping; - for (std::pair walletEntry : mapWallet) { + for (std::pair walletEntry : mapWallet) { CWalletTx *pcoin = &walletEntry.second; if (pcoin->tx->vin.size() > 0) { @@ -3596,7 +3596,7 @@ Amount nBalance = 0; // Tally wallet transactions. - for (std::map::iterator it = mapWallet.begin(); + for (std::map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx &wtx = (*it).second; if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || @@ -3693,10 +3693,10 @@ } } -void CWallet::UpdatedTransaction(const uint256 &hashTx) { +void CWallet::UpdatedTransaction(const TxHash &hashTx) { LOCK(cs_wallet); // Only notify UI if this transaction is in this wallet. - std::map::const_iterator mi = mapWallet.find(hashTx); + std::map::const_iterator mi = mapWallet.find(hashTx); if (mi != mapWallet.end()) { NotifyTransactionChanged(this, hashTx, CT_UPDATED); } @@ -3731,7 +3731,7 @@ setLockedCoins.clear(); } -bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const { +bool CWallet::IsLockedCoin(TxHash hash, unsigned int n) const { // setLockedCoins AssertLockHeld(cs_wallet); COutPoint outpt(hash, n); @@ -3822,7 +3822,7 @@ // Find first block that affects those keys, if there are any left. std::vector vAffected; - for (std::map::const_iterator it = mapWallet.begin(); + for (std::map::const_iterator it = mapWallet.begin(); it != mapWallet.end(); it++) { // Iterate over all wallet transactions... const CWalletTx &wtx = (*it).second; @@ -4177,9 +4177,9 @@ CWalletDB walletdb(walletFile); for (const CWalletTx &wtxOld : vWtx) { - uint256 txid = wtxOld.GetId(); - std::map::iterator mi = - walletInstance->mapWallet.find(txid); + TxHash txhash = wtxOld.GetHash(); + std::map::iterator mi = + walletInstance->mapWallet.find(txhash); if (mi != walletInstance->mapWallet.end()) { const CWalletTx *copyFrom = &wtxOld; CWalletTx *copyTo = &mi->second; diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -120,7 +120,7 @@ bool ErasePurpose(const std::string &strAddress); bool WriteTx(const CWalletTx &wtx); - bool EraseTx(uint256 hash); + bool EraseTx(TxHash hash); bool WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, const CKeyMetadata &keyMeta); @@ -167,11 +167,11 @@ std::list &acentries); DBErrors LoadWallet(CWallet *pwallet); - DBErrors FindWalletTx(CWallet *pwallet, std::vector &vTxHash, + DBErrors FindWalletTx(CWallet *pwallet, std::vector &vTxHash, std::vector &vWtx); DBErrors ZapWalletTx(CWallet *pwallet, std::vector &vWtx); - DBErrors ZapSelectTx(CWallet *pwallet, std::vector &vHashIn, - std::vector &vHashOut); + DBErrors ZapSelectTx(CWallet *pwallet, std::vector &vHashIn, + std::vector &vHashOut); static bool Recover(CDBEnv &dbenv, const std::string &filename, bool fOnlyKeys); static bool Recover(CDBEnv &dbenv, const std::string &filename); diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -57,10 +57,10 @@ bool CWalletDB::WriteTx(const CWalletTx &wtx) { nWalletDBUpdateCounter++; - return Write(std::make_pair(std::string("tx"), wtx.GetId()), wtx); + return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx); } -bool CWalletDB::EraseTx(uint256 hash) { +bool CWalletDB::EraseTx(TxHash hash) { nWalletDBUpdateCounter++; return Erase(std::make_pair(std::string("tx"), hash)); } @@ -301,7 +301,7 @@ bool isValid = wtx.IsCoinBase() ? CheckCoinbase(wtx, state) : CheckRegularTransaction(wtx, state); - if (wtx.GetId() != hash || !isValid) return false; + if (wtx.GetHash() != hash || !isValid) return false; // Undo serialize changes in 31600 if (31404 <= wtx.fTimeReceivedIsTxTime && @@ -601,8 +601,7 @@ return result; } -DBErrors CWalletDB::FindWalletTx(CWallet *pwallet, - std::vector &vTxHash, +DBErrors CWalletDB::FindWalletTx(CWallet *pwallet, std::vector &vTxHash, std::vector &vWtx) { pwallet->vchDefaultKey = CPubKey(); bool fNoncriticalErrors = false; @@ -662,10 +661,10 @@ } DBErrors CWalletDB::ZapSelectTx(CWallet *pwallet, - std::vector &vTxHashIn, - std::vector &vTxHashOut) { + std::vector &vTxHashIn, + std::vector &vTxHashOut) { // Build list of wallet TXs and hashes. - std::vector vTxHash; + std::vector vTxHash; std::vector vWtx; DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); if (err != DB_LOAD_OK) { @@ -677,8 +676,8 @@ // Erase each matching wallet TX. bool delerror = false; - std::vector::iterator it = vTxHashIn.begin(); - for (uint256 hash : vTxHash) { + std::vector::iterator it = vTxHashIn.begin(); + for (TxHash hash : vTxHash) { while (it < vTxHashIn.end() && (*it) < hash) { it++; } @@ -705,12 +704,12 @@ DBErrors CWalletDB::ZapWalletTx(CWallet *pwallet, std::vector &vWtx) { // Build list of wallet TXs. - std::vector vTxHash; + std::vector vTxHash; DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); if (err != DB_LOAD_OK) return err; // Erase each wallet TX. - for (uint256 &hash : vTxHash) { + for (TxHash &hash : vTxHash) { if (!EraseTx(hash)) return DB_CORRUPT; }