mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
refactor: define all key/value pairings as *Entry and use them instead
This commit is contained in:
parent
488f0474a8
commit
808842b1a3
@ -17,6 +17,9 @@
|
||||
#include <tuple>
|
||||
|
||||
class CScript;
|
||||
struct CAddressIndexKey;
|
||||
struct CMempoolAddressDelta;
|
||||
struct CMempoolAddressDeltaKey;
|
||||
|
||||
enum class AddressType : uint8_t {
|
||||
P2PK_OR_P2PKH = 1,
|
||||
@ -26,6 +29,9 @@ enum class AddressType : uint8_t {
|
||||
};
|
||||
template<> struct is_serializable_enum<AddressType> : std::true_type {};
|
||||
|
||||
using CAddressIndexEntry = std::pair<CAddressIndexKey, CAmount>;
|
||||
using CMempoolAddressDeltaEntry = std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta>;
|
||||
|
||||
struct CMempoolAddressDelta
|
||||
{
|
||||
public:
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <validation.h>
|
||||
|
||||
bool GetAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
std::vector<CAddressIndexEntry>& addressIndex,
|
||||
const int32_t start, const int32_t end)
|
||||
{
|
||||
if (!fAddressIndex)
|
||||
@ -23,7 +23,7 @@ bool GetAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
}
|
||||
|
||||
bool GetAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& unspentOutputs)
|
||||
std::vector<CAddressUnspentIndexEntry>& unspentOutputs)
|
||||
{
|
||||
if (!fAddressIndex)
|
||||
return error("Address index not enabled");
|
||||
|
@ -10,23 +10,20 @@
|
||||
#include <vector>
|
||||
|
||||
#include <amount.h>
|
||||
#include <addressindex.h>
|
||||
#include <spentindex.h>
|
||||
|
||||
class CTxMemPool;
|
||||
class uint160;
|
||||
class uint256;
|
||||
struct CAddressIndexKey;
|
||||
struct CAddressUnspentKey;
|
||||
struct CAddressUnspentValue;
|
||||
struct CSpentIndexKey;
|
||||
struct CSpentIndexValue;
|
||||
|
||||
enum class AddressType : uint8_t;
|
||||
|
||||
bool GetAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
std::vector<CAddressIndexEntry>& addressIndex,
|
||||
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);
|
||||
std::vector<CAddressUnspentIndexEntry>& unspentOutputs);
|
||||
bool GetSpentIndex(const CTxMemPool& mempool, const CSpentIndexKey& key, CSpentIndexValue& value);
|
||||
bool GetTimestampIndex(const uint32_t high, const uint32_t low, std::vector<uint256>& hashes);
|
||||
|
||||
|
@ -701,13 +701,11 @@ static bool getAddressesFromParams(const UniValue& params, std::vector<std::pair
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool heightSort(std::pair<CAddressUnspentKey, CAddressUnspentValue> a,
|
||||
std::pair<CAddressUnspentKey, CAddressUnspentValue> b) {
|
||||
static bool heightSort(CAddressUnspentIndexEntry a, CAddressUnspentIndexEntry b) {
|
||||
return a.second.m_block_height < b.second.m_block_height;
|
||||
}
|
||||
|
||||
static bool timestampSort(std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> a,
|
||||
std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> b) {
|
||||
static bool timestampSort(CMempoolAddressDeltaEntry a, CMempoolAddressDeltaEntry b) {
|
||||
return a.second.m_time < b.second.m_time;
|
||||
}
|
||||
|
||||
@ -749,7 +747,7 @@ static RPCHelpMan getaddressmempool()
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > indexes;
|
||||
std::vector<CMempoolAddressDeltaEntry> indexes;
|
||||
|
||||
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||
if (!mempool.getAddressIndex(addresses, indexes)) {
|
||||
@ -821,7 +819,7 @@ static RPCHelpMan getaddressutxos()
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
std::vector<CAddressUnspentIndexEntry> unspentOutputs;
|
||||
|
||||
for (const auto& address : addresses) {
|
||||
if (!GetAddressUnspentIndex(address.first, address.second, unspentOutputs)) {
|
||||
@ -906,7 +904,7 @@ static RPCHelpMan getaddressdeltas()
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
|
||||
for (const auto& address : addresses) {
|
||||
if (start > 0 && end > 0) {
|
||||
@ -975,7 +973,7 @@ static RPCHelpMan getaddressbalance()
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
|
||||
for (const auto& address : addresses) {
|
||||
if (!GetAddressIndex(address.first, address.second, addressIndex)) {
|
||||
@ -1054,7 +1052,7 @@ static RPCHelpMan getaddresstxids()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
|
||||
for (const auto& address : addresses) {
|
||||
if (start > 0 && end > 0) {
|
||||
|
@ -16,6 +16,14 @@
|
||||
|
||||
#include <tuple>
|
||||
|
||||
struct CAddressUnspentKey;
|
||||
struct CAddressUnspentValue;
|
||||
struct CSpentIndexKey;
|
||||
struct CSpentIndexValue;
|
||||
|
||||
using CAddressUnspentIndexEntry = std::pair<CAddressUnspentKey, CAddressUnspentValue>;
|
||||
using CSpentIndexEntry = std::pair<CSpentIndexKey, CSpentIndexValue>;
|
||||
|
||||
struct CSpentIndexKey {
|
||||
public:
|
||||
uint256 m_tx_hash;
|
||||
|
18
src/txdb.cpp
18
src/txdb.cpp
@ -267,7 +267,7 @@ bool CBlockTreeDB::ReadSpentIndex(const CSpentIndexKey key, CSpentIndexValue& va
|
||||
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<CSpentIndexEntry>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CSpentIndexKey,CSpentIndexValue>>::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
if (it->second.IsNull()) {
|
||||
@ -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<CAddressUnspentIndexEntry>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
for (std::vector<CAddressUnspentIndexEntry>::const_iterator it=vect.begin(); it!=vect.end(); it++) {
|
||||
if (it->second.IsNull()) {
|
||||
batch.Erase(std::make_pair(DB_ADDRESSUNSPENTINDEX, it->first));
|
||||
} else {
|
||||
@ -292,7 +292,7 @@ bool CBlockTreeDB::UpdateAddressUnspentIndex(const std::vector<std::pair<CAddres
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadAddressUnspentIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>>& unspentOutputs)
|
||||
std::vector<CAddressUnspentIndexEntry>& unspentOutputs)
|
||||
{
|
||||
std::unique_ptr<CDBIterator> pcursor(NewIterator());
|
||||
|
||||
@ -316,22 +316,22 @@ bool CBlockTreeDB::ReadAddressUnspentIndex(const uint160& addressHash, const Add
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect) {
|
||||
bool CBlockTreeDB::WriteAddressIndex(const std::vector<CAddressIndexEntry>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount>>::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
for (std::vector<CAddressIndexEntry>::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<CAddressIndexEntry>& vect) {
|
||||
CDBBatch batch(*this);
|
||||
for (std::vector<std::pair<CAddressIndexKey, CAmount>>::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
for (std::vector<CAddressIndexEntry>::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||
batch.Erase(std::make_pair(DB_ADDRESSINDEX, it->first));
|
||||
return WriteBatch(batch);
|
||||
}
|
||||
|
||||
bool CBlockTreeDB::ReadAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
std::vector<CAddressIndexEntry>& addressIndex,
|
||||
const int32_t start, const int32_t end)
|
||||
{
|
||||
std::unique_ptr<CDBIterator> pcursor(NewIterator());
|
||||
|
12
src/txdb.h
12
src/txdb.h
@ -86,16 +86,16 @@ public:
|
||||
void ReadReindexing(bool &fReindexing);
|
||||
|
||||
bool ReadSpentIndex(const CSpentIndexKey key, CSpentIndexValue& value);
|
||||
bool UpdateSpentIndex(const std::vector<std::pair<CSpentIndexKey, CSpentIndexValue>>& vect);
|
||||
bool UpdateSpentIndex(const std::vector<CSpentIndexEntry>& 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);
|
||||
std::vector<CAddressUnspentIndexEntry>& vect);
|
||||
bool UpdateAddressUnspentIndex(const std::vector<CAddressUnspentIndexEntry>& vect);
|
||||
|
||||
bool WriteAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect);
|
||||
bool EraseAddressIndex(const std::vector<std::pair<CAddressIndexKey, CAmount>>& vect);
|
||||
bool WriteAddressIndex(const std::vector<CAddressIndexEntry>& vect);
|
||||
bool EraseAddressIndex(const std::vector<CAddressIndexEntry>& vect);
|
||||
bool ReadAddressIndex(const uint160& addressHash, const AddressType type,
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount>>& addressIndex,
|
||||
std::vector<CAddressIndexEntry>& addressIndex,
|
||||
const int32_t start = 0, const int32_t end = 0);
|
||||
|
||||
bool WriteTimestampIndex(const CTimestampIndexKey& timestampIndex);
|
||||
|
@ -471,7 +471,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry& entry, const CCoinsViewC
|
||||
}
|
||||
|
||||
bool CTxMemPool::getAddressIndex(const std::vector<std::pair<uint160, AddressType>>& addresses,
|
||||
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta>>& results) const
|
||||
std::vector<CMempoolAddressDeltaEntry>& results) const
|
||||
{
|
||||
LOCK(cs);
|
||||
for (const auto& address : addresses) {
|
||||
|
@ -637,7 +637,7 @@ public:
|
||||
|
||||
void addAddressIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view);
|
||||
bool getAddressIndex(const std::vector<std::pair<uint160, AddressType>>& addresses,
|
||||
std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta>>& results) const;
|
||||
std::vector<CMempoolAddressDeltaEntry>& results) const;
|
||||
bool removeAddressIndex(const uint256 txhash);
|
||||
|
||||
void addSpentIndex(const CTxMemPoolEntry& entry, const CCoinsViewCache& view);
|
||||
|
@ -1685,9 +1685,9 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
||||
return DISCONNECT_FAILED;
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > addressUnspentIndex;
|
||||
std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> > spentIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
std::vector<CAddressUnspentIndexEntry> addressUnspentIndex;
|
||||
std::vector<CSpentIndexEntry> spentIndex;
|
||||
|
||||
std::optional<MNListUpdates> mnlist_updates_opt{std::nullopt};
|
||||
if (!m_chain_helper->special_tx->UndoSpecialTxsInBlock(block, pindex, mnlist_updates_opt)) {
|
||||
@ -2152,9 +2152,9 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
|
||||
int nInputs = 0;
|
||||
unsigned int nSigOps = 0;
|
||||
blockundo.vtxundo.reserve(block.vtx.size() - 1);
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > addressUnspentIndex;
|
||||
std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> > spentIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
std::vector<CAddressUnspentIndexEntry> addressUnspentIndex;
|
||||
std::vector<CSpentIndexEntry> spentIndex;
|
||||
|
||||
bool fDIP0001Active_context = pindex->nHeight >= Params().GetConsensus().DIP0001Height;
|
||||
|
||||
@ -4782,9 +4782,9 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
|
||||
pindex->GetBlockHash().ToString(), state.ToString());
|
||||
}
|
||||
|
||||
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
|
||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > addressUnspentIndex;
|
||||
std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> > spentIndex;
|
||||
std::vector<CAddressIndexEntry> addressIndex;
|
||||
std::vector<CAddressUnspentIndexEntry> addressUnspentIndex;
|
||||
std::vector<CSpentIndexEntry> spentIndex;
|
||||
|
||||
for (size_t i = 0; i < block.vtx.size(); i++) {
|
||||
const CTransactionRef& tx = block.vtx[i];
|
||||
|
Loading…
Reference in New Issue
Block a user