diff --git a/src/rpc/index_util.cpp b/src/rpc/index_util.cpp index 65ddf3e49b..4b8bf64a61 100644 --- a/src/rpc/index_util.cpp +++ b/src/rpc/index_util.cpp @@ -33,7 +33,7 @@ bool GetAddressUnspentIndex(uint160 addressHash, AddressType type, return true; } -bool GetSpentIndex(CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value) +bool GetSpentIndex(const CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value) { if (!fSpentIndex) return false; diff --git a/src/rpc/index_util.h b/src/rpc/index_util.h index af01cadf9c..15b82eb2a5 100644 --- a/src/rpc/index_util.h +++ b/src/rpc/index_util.h @@ -27,7 +27,7 @@ bool GetAddressIndex(uint160 addressHash, AddressType type, int32_t start = 0, int32_t end = 0); bool GetAddressUnspentIndex(uint160 addressHash, AddressType type, std::vector>& unspentOutputs); -bool GetSpentIndex(CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value); +bool GetSpentIndex(const CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value); bool GetTimestampIndex(const uint32_t high, const uint32_t low, std::vector& hashes); #endif // BITCOIN_RPC_CLIENT_H diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a9b9a09360..a2eaf621ff 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -427,7 +427,7 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces } } -void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view) +void CTxMemPool::addAddressIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view) { LOCK(cs); const CTransaction& tx = entry.GetTx(); @@ -470,12 +470,12 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC mapAddressInserted.insert(std::make_pair(txhash, inserted)); } -bool CTxMemPool::getAddressIndex(std::vector > &addresses, - std::vector > &results) +bool CTxMemPool::getAddressIndex(const std::vector>& addresses, + std::vector>& results) const { LOCK(cs); for (const auto& address : addresses) { - addressDeltaMap::iterator ait = mapAddress.lower_bound(CMempoolAddressDeltaKey(address.second, address.first)); + addressDeltaMap::const_iterator ait = mapAddress.lower_bound(CMempoolAddressDeltaKey(address.second, address.first)); while (ait != mapAddress.end() && (*ait).first.m_address_bytes == address.first && (*ait).first.m_address_type == address.second) { results.push_back(*ait); ait++; @@ -500,7 +500,7 @@ bool CTxMemPool::removeAddressIndex(const uint256 txhash) return true; } -void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view) +void CTxMemPool::addSpentIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view) { LOCK(cs); @@ -530,12 +530,11 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac mapSpentInserted.insert(make_pair(txhash, inserted)); } -bool CTxMemPool::getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value) +bool CTxMemPool::getSpentIndex(const CSpentIndexKey& key, CSpentIndexValue& value) const { LOCK(cs); - mapSpentIndex::iterator it; + mapSpentIndex::const_iterator it = mapSpent.find(key); - it = mapSpent.find(key); if (it != mapSpent.end()) { value = it->second; return true; diff --git a/src/txmempool.h b/src/txmempool.h index a4717b7e88..823b45e892 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -635,13 +635,13 @@ public: void addUnchecked(const CTxMemPoolEntry& entry, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main); void addUnchecked(const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main); - void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view); - bool getAddressIndex(std::vector > &addresses, - std::vector > &results); + void addAddressIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view); + bool getAddressIndex(const std::vector>& addresses, + std::vector>& results) const; bool removeAddressIndex(const uint256 txhash); - void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view); - bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value); + void addSpentIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view); + bool getSpentIndex(const CSpentIndexKey& key, CSpentIndexValue& value) const; bool removeSpentIndex(const uint256 txhash); void removeRecursive(const CTransaction& tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);