mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
refactor: make CBlockTreeDB::Read*Index arguments const
With bonus code formatting. We cannot make the functions themselves const as the iterators are non-const.
This commit is contained in:
parent
625982e8d2
commit
9a6503d9e8
@ -9,8 +9,9 @@
|
||||
#include <uint256.h>
|
||||
#include <validation.h>
|
||||
|
||||
bool GetAddressIndex(uint160 addressHash, AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex, int32_t start, int32_t end)
|
||||
bool GetAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
const int32_t start, const int32_t end)
|
||||
{
|
||||
if (!fAddressIndex)
|
||||
return error("address index not enabled");
|
||||
@ -21,7 +22,7 @@ bool GetAddressIndex(uint160 addressHash, AddressType type,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetAddressUnspentIndex(uint160 addressHash, AddressType type,
|
||||
bool GetAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& unspentOutputs)
|
||||
{
|
||||
if (!fAddressIndex)
|
||||
@ -33,7 +34,7 @@ bool GetAddressUnspentIndex(uint160 addressHash, AddressType type,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetSpentIndex(const CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value)
|
||||
bool GetSpentIndex(const CTxMemPool& mempool, const CSpentIndexKey& key, CSpentIndexValue& value)
|
||||
{
|
||||
if (!fSpentIndex)
|
||||
return false;
|
||||
|
@ -22,12 +22,12 @@ struct CSpentIndexValue;
|
||||
|
||||
enum class AddressType : uint8_t;
|
||||
|
||||
bool GetAddressIndex(uint160 addressHash, AddressType type,
|
||||
bool GetAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
int32_t start = 0, int32_t end = 0);
|
||||
bool GetAddressUnspentIndex(uint160 addressHash, AddressType type,
|
||||
const int32_t start = 0, const int32_t end = 0);
|
||||
bool GetAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& unspentOutputs);
|
||||
bool GetSpentIndex(const CTxMemPool& mempool, CSpentIndexKey& key, CSpentIndexValue& value);
|
||||
bool GetSpentIndex(const CTxMemPool& mempool, const CSpentIndexKey& key, CSpentIndexValue& value);
|
||||
bool GetTimestampIndex(const uint32_t high, const uint32_t low, std::vector<uint256>& hashes);
|
||||
|
||||
#endif // BITCOIN_RPC_CLIENT_H
|
||||
|
37
src/txdb.cpp
37
src/txdb.cpp
@ -263,13 +263,13 @@ bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockF
|
||||
return WriteBatch(batch, true);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value) {
|
||||
bool CBlockTreeDB::ReadSpentIndex(const CSpentIndexKey key, CSpentIndexValue& value) {
|
||||
return Read(std::make_pair(DB_SPENTINDEX, key), value);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect) {
|
||||
bool CBlockTreeDB::UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue>>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CSpentIndexKey,CSpentIndexValue> >::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
for (std::vector<std::pair<CSpentIndexKey,CSpentIndexValue>>::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
if (it->second.IsNull()) {
|
||||
batch.Erase(std::make_pair(DB_SPENTINDEX, it->first));
|
||||
} else {
|
||||
@ -279,9 +279,9 @@ bool CBlockTreeDB::UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey,
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect) {
|
||||
bool CBlockTreeDB::UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> >::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
if (it->second.IsNull()) {
|
||||
batch.Erase(std::make_pair(DB_ADDRESSUNSPENTINDEX, it->first));
|
||||
} else {
|
||||
@ -291,9 +291,9 @@ bool CBlockTreeDB::UpdateAddressUnspentIndex(const std::vector<std::pair<CAddres
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadAddressUnspentIndex(uint160 addressHash, AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs) {
|
||||
|
||||
bool CBlockTreeDB::ReadAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& unspentOutputs)
|
||||
{
|
||||
std::unique_ptr<CDBIterator> pcursor(NewIterator());
|
||||
|
||||
pcursor->Seek(std::make_pair(DB_ADDRESSUNSPENTINDEX, CAddressIndexIteratorKey(type, addressHash)));
|
||||
@ -316,24 +316,24 @@ bool CBlockTreeDB::ReadAddressUnspentIndex(uint160 addressHash, AddressType type
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount > >&vect) {
|
||||
bool CBlockTreeDB::WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount>>::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
batch.Write(std::make_pair(DB_ADDRESSINDEX, it->first), it->second);
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount > >&vect) {
|
||||
bool CBlockTreeDB::EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount>>::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
batch.Erase(std::make_pair(DB_ADDRESSINDEX, it->first));
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
|
||||
int start, int end) {
|
||||
|
||||
bool CBlockTreeDB::ReadAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
const int32_t start, const int32_t end)
|
||||
{
|
||||
std::unique_ptr<CDBIterator> pcursor(NewIterator());
|
||||
|
||||
if (start > 0 && end > 0) {
|
||||
@ -363,7 +363,7 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, AddressType type,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) {
|
||||
bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey& timestampIndex) {
|
||||
CDBBatch batch(*this);
|
||||
batch.Write(std::make_pair(DB_TIMESTAMPINDEX, timestampIndex), 0);
|
||||
return WriteBatch(batch);
|
||||
@ -376,8 +376,7 @@ bool CBlockTreeDB::EraseTimestampIndex(const CTimestampIndexKey& timestampIndex)
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes) {
|
||||
|
||||
bool CBlockTreeDB::ReadTimestampIndex(const uint32_t high, const uint32_t low, std::vector<uint256>& hashes) {
|
||||
std::unique_ptr<CDBIterator> pcursor(NewIterator());
|
||||
|
||||
pcursor->Seek(std::make_pair(DB_TIMESTAMPINDEX, CTimestampIndexIteratorKey(low)));
|
||||
|
29
src/txdb.h
29
src/txdb.h
@ -84,19 +84,24 @@ public:
|
||||
bool ReadLastBlockFile(int &nFile);
|
||||
bool WriteReindexing(bool fReindexing);
|
||||
void ReadReindexing(bool &fReindexing);
|
||||
bool ReadSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
|
||||
bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> >&vect);
|
||||
bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue > >&vect);
|
||||
bool ReadAddressUnspentIndex(uint160 addressHash, AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &vect);
|
||||
bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
|
||||
bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount> > &vect);
|
||||
bool ReadAddressIndex(uint160 addressHash, AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
|
||||
int start = 0, int end = 0);
|
||||
bool WriteTimestampIndex(const CTimestampIndexKey ×tampIndex);
|
||||
|
||||
bool ReadSpentIndex(const CSpentIndexKey key, CSpentIndexValue& value);
|
||||
bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue>>& vect);
|
||||
|
||||
bool ReadAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& vect);
|
||||
bool UpdateAddressUnspentIndex(const std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& vect);
|
||||
|
||||
bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect);
|
||||
bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect);
|
||||
bool ReadAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
const int32_t start = 0, const int32_t end = 0);
|
||||
|
||||
bool WriteTimestampIndex(const CTimestampIndexKey& timestampIndex);
|
||||
bool EraseTimestampIndex(const CTimestampIndexKey& timestampIndex);
|
||||
bool ReadTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &vect);
|
||||
bool ReadTimestampIndex(const uint32_t high, const uint32_t low, std::vector<uint256>& hashes);
|
||||
|
||||
bool WriteFlag(const std::string &name, bool fValue);
|
||||
bool ReadFlag(const std::string &name, bool &fValue);
|
||||
bool LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex);
|
||||
|
Loading…
Reference in New Issue
Block a user