refactor: move timestamp index out of spentindex

This commit is contained in:
Kittywhiskers Van Gogh 2023-09-14 22:24:58 +05:30
parent ce3b5acae4
commit cc2efac4b4
4 changed files with 82 additions and 67 deletions

View File

@ -297,6 +297,7 @@ BITCOIN_CORE_H = \
support/events.h \
support/lockedpool.h \
sync.h \
timestampindex.h \
threadsafety.h \
threadinterrupt.h \
timedata.h \

View File

@ -99,73 +99,6 @@ struct CSpentIndexTxInfo
std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mSpentInfo;
};
struct CTimestampIndexIteratorKey {
public:
uint32_t m_time;
public:
CTimestampIndexIteratorKey() {
SetNull();
}
CTimestampIndexIteratorKey(uint32_t time) : m_time{time} {};
void SetNull() {
m_time = 0;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 4;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata32be(s, m_time);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_time = ser_readdata32be(s);
}
};
struct CTimestampIndexKey {
public:
uint32_t m_block_time;
uint256 m_block_hash;
public:
CTimestampIndexKey() {
SetNull();
}
CTimestampIndexKey(uint32_t block_time, uint256 block_hash) :
m_block_time{block_time}, m_block_hash{block_hash} {};
void SetNull() {
m_block_time = 0;
m_block_hash.SetNull();
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 36;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata32be(s, m_block_time);
m_block_hash.Serialize(s);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_block_time = ser_readdata32be(s);
m_block_hash.Unserialize(s);
}
};
struct CAddressUnspentKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};

80
src/timestampindex.h Normal file
View File

@ -0,0 +1,80 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2016 BitPay, Inc.
// Copyright (c) 2023 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_TIMESTAMPINDEX_H
#define BITCOIN_TIMESTAMPINDEX_H
#include <uint256.h>
struct CTimestampIndexIteratorKey {
public:
uint32_t m_time;
public:
CTimestampIndexIteratorKey() {
SetNull();
}
CTimestampIndexIteratorKey(uint32_t time) : m_time{time} {};
void SetNull() {
m_time = 0;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 4;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata32be(s, m_time);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_time = ser_readdata32be(s);
}
};
struct CTimestampIndexKey {
public:
uint32_t m_block_time;
uint256 m_block_hash;
public:
CTimestampIndexKey() {
SetNull();
}
CTimestampIndexKey(uint32_t block_time, uint256 block_hash) :
m_block_time{block_time}, m_block_hash{block_hash} {};
void SetNull() {
m_block_time = 0;
m_block_hash.SetNull();
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 36;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata32be(s, m_block_time);
m_block_hash.Serialize(s);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_block_time = ser_readdata32be(s);
m_block_hash.Unserialize(s);
}
};
#endif // BITCOIN_TIMESTAMPINDEX_H

View File

@ -11,6 +11,7 @@
#include <chain.h>
#include <primitives/block.h>
#include <spentindex.h>
#include <timestampindex.h>
#include <memory>
#include <string>