refactor: make CTxMemPool::get*Index functions and arguments const

This commit is contained in:
Kittywhiskers Van Gogh 2024-06-26 17:51:48 +00:00
parent 5ad49ad668
commit 625982e8d2
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
4 changed files with 14 additions and 15 deletions

View File

@ -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;

View File

@ -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<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& 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<uint256>& hashes);
#endif // BITCOIN_RPC_CLIENT_H

View File

@ -470,12 +470,12 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC
mapAddressInserted.insert(std::make_pair(txhash, inserted));
}
bool CTxMemPool::getAddressIndex(std::vector<std::pair<uint160, AddressType> > &addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results)
bool CTxMemPool::getAddressIndex(const std::vector<std::pair<uint160, AddressType>>& addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta>>& 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++;
@ -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;

View File

@ -636,12 +636,12 @@ public:
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<std::pair<uint160, AddressType> > &addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
bool getAddressIndex(const std::vector<std::pair<uint160, AddressType>>& addresses,
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta>>& results) const;
bool removeAddressIndex(const uint256 txhash);
void addSpentIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view);
bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
bool getSpentIndex(const CSpentIndexKey& key, CSpentIndexValue& value) const;
bool removeSpentIndex(const uint256 txhash);
void removeRecursive(const CTransaction& tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);