mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
refactor: add separators between members, functions and serialization
This commit is contained in:
parent
53977827ff
commit
98e61857fe
230
src/spentindex.h
230
src/spentindex.h
@ -15,14 +15,11 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
struct CSpentIndexKey {
|
struct CSpentIndexKey {
|
||||||
|
public:
|
||||||
uint256 txid;
|
uint256 txid;
|
||||||
unsigned int outputIndex;
|
unsigned int outputIndex;
|
||||||
|
|
||||||
SERIALIZE_METHODS(CSpentIndexKey, obj)
|
public:
|
||||||
{
|
|
||||||
READWRITE(obj.txid, obj.outputIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSpentIndexKey(uint256 t, unsigned int i) {
|
CSpentIndexKey(uint256 t, unsigned int i) {
|
||||||
txid = t;
|
txid = t;
|
||||||
outputIndex = i;
|
outputIndex = i;
|
||||||
@ -37,9 +34,15 @@ struct CSpentIndexKey {
|
|||||||
outputIndex = 0;
|
outputIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SERIALIZE_METHODS(CSpentIndexKey, obj)
|
||||||
|
{
|
||||||
|
READWRITE(obj.txid, obj.outputIndex);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CSpentIndexValue {
|
struct CSpentIndexValue {
|
||||||
|
public:
|
||||||
uint256 txid;
|
uint256 txid;
|
||||||
unsigned int inputIndex;
|
unsigned int inputIndex;
|
||||||
int blockHeight;
|
int blockHeight;
|
||||||
@ -47,11 +50,7 @@ struct CSpentIndexValue {
|
|||||||
int addressType;
|
int addressType;
|
||||||
uint160 addressHash;
|
uint160 addressHash;
|
||||||
|
|
||||||
SERIALIZE_METHODS(CSpentIndexValue, obj)
|
public:
|
||||||
{
|
|
||||||
READWRITE(obj.txid, obj.inputIndex, obj.blockHeight, obj.satoshis, obj.addressType, obj.addressHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
|
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
|
||||||
txid = t;
|
txid = t;
|
||||||
inputIndex = i;
|
inputIndex = i;
|
||||||
@ -77,6 +76,12 @@ struct CSpentIndexValue {
|
|||||||
bool IsNull() const {
|
bool IsNull() const {
|
||||||
return txid.IsNull();
|
return txid.IsNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SERIALIZE_METHODS(CSpentIndexValue, obj)
|
||||||
|
{
|
||||||
|
READWRITE(obj.txid, obj.inputIndex, obj.blockHeight, obj.satoshis, obj.addressType, obj.addressHash);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CSpentIndexKeyCompare
|
struct CSpentIndexKeyCompare
|
||||||
@ -95,20 +100,10 @@ struct CSpentIndexTxInfo
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct CTimestampIndexIteratorKey {
|
struct CTimestampIndexIteratorKey {
|
||||||
|
public:
|
||||||
unsigned int timestamp;
|
unsigned int timestamp;
|
||||||
|
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
public:
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Serialize(Stream& s) const {
|
|
||||||
ser_writedata32be(s, timestamp);
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Unserialize(Stream& s) {
|
|
||||||
timestamp = ser_readdata32be(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
CTimestampIndexIteratorKey(unsigned int time) {
|
CTimestampIndexIteratorKey(unsigned int time) {
|
||||||
timestamp = time;
|
timestamp = time;
|
||||||
}
|
}
|
||||||
@ -120,26 +115,29 @@ struct CTimestampIndexIteratorKey {
|
|||||||
void SetNull() {
|
void SetNull() {
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
struct CTimestampIndexKey {
|
|
||||||
unsigned int timestamp;
|
|
||||||
uint256 blockHash;
|
|
||||||
|
|
||||||
|
public:
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
return 36;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Serialize(Stream& s) const {
|
void Serialize(Stream& s) const {
|
||||||
ser_writedata32be(s, timestamp);
|
ser_writedata32be(s, timestamp);
|
||||||
blockHash.Serialize(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Unserialize(Stream& s) {
|
void Unserialize(Stream& s) {
|
||||||
timestamp = ser_readdata32be(s);
|
timestamp = ser_readdata32be(s);
|
||||||
blockHash.Unserialize(s);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CTimestampIndexKey {
|
||||||
|
public:
|
||||||
|
unsigned int timestamp;
|
||||||
|
uint256 blockHash;
|
||||||
|
|
||||||
|
public:
|
||||||
CTimestampIndexKey(unsigned int time, uint256 hash) {
|
CTimestampIndexKey(unsigned int time, uint256 hash) {
|
||||||
timestamp = time;
|
timestamp = time;
|
||||||
blockHash = hash;
|
blockHash = hash;
|
||||||
@ -153,32 +151,33 @@ struct CTimestampIndexKey {
|
|||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
blockHash.SetNull();
|
blockHash.SetNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
|
return 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Serialize(Stream& s) const {
|
||||||
|
ser_writedata32be(s, timestamp);
|
||||||
|
blockHash.Serialize(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s) {
|
||||||
|
timestamp = ser_readdata32be(s);
|
||||||
|
blockHash.Unserialize(s);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CAddressUnspentKey {
|
struct CAddressUnspentKey {
|
||||||
|
public:
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
uint160 hashBytes;
|
uint160 hashBytes;
|
||||||
uint256 txhash;
|
uint256 txhash;
|
||||||
size_t index;
|
size_t index;
|
||||||
|
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
public:
|
||||||
return 57;
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Serialize(Stream& s) const {
|
|
||||||
ser_writedata8(s, type);
|
|
||||||
hashBytes.Serialize(s);
|
|
||||||
txhash.Serialize(s);
|
|
||||||
ser_writedata32(s, index);
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Unserialize(Stream& s) {
|
|
||||||
type = ser_readdata8(s);
|
|
||||||
hashBytes.Unserialize(s);
|
|
||||||
txhash.Unserialize(s);
|
|
||||||
index = ser_readdata32(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
|
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
|
||||||
type = addressType;
|
type = addressType;
|
||||||
hashBytes = addressHash;
|
hashBytes = addressHash;
|
||||||
@ -196,18 +195,36 @@ struct CAddressUnspentKey {
|
|||||||
txhash.SetNull();
|
txhash.SetNull();
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
|
return 57;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Serialize(Stream& s) const {
|
||||||
|
ser_writedata8(s, type);
|
||||||
|
hashBytes.Serialize(s);
|
||||||
|
txhash.Serialize(s);
|
||||||
|
ser_writedata32(s, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s) {
|
||||||
|
type = ser_readdata8(s);
|
||||||
|
hashBytes.Unserialize(s);
|
||||||
|
txhash.Unserialize(s);
|
||||||
|
index = ser_readdata32(s);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CAddressUnspentValue {
|
struct CAddressUnspentValue {
|
||||||
|
public:
|
||||||
CAmount satoshis;
|
CAmount satoshis;
|
||||||
CScript script;
|
CScript script;
|
||||||
int blockHeight;
|
int blockHeight;
|
||||||
|
|
||||||
SERIALIZE_METHODS(CAddressUnspentValue, obj)
|
public:
|
||||||
{
|
|
||||||
READWRITE(obj.satoshis, obj.script, obj.blockHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
|
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
|
||||||
satoshis = sats;
|
satoshis = sats;
|
||||||
script = scriptPubKey;
|
script = scriptPubKey;
|
||||||
@ -227,9 +244,16 @@ struct CAddressUnspentValue {
|
|||||||
bool IsNull() const {
|
bool IsNull() const {
|
||||||
return (satoshis == -1);
|
return (satoshis == -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SERIALIZE_METHODS(CAddressUnspentValue, obj)
|
||||||
|
{
|
||||||
|
READWRITE(obj.satoshis, obj.script, obj.blockHeight);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CAddressIndexKey {
|
struct CAddressIndexKey {
|
||||||
|
public:
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
uint160 hashBytes;
|
uint160 hashBytes;
|
||||||
int blockHeight;
|
int blockHeight;
|
||||||
@ -238,33 +262,7 @@ struct CAddressIndexKey {
|
|||||||
size_t index;
|
size_t index;
|
||||||
bool is_spent;
|
bool is_spent;
|
||||||
|
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
public:
|
||||||
return 66;
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Serialize(Stream& s) const {
|
|
||||||
ser_writedata8(s, type);
|
|
||||||
hashBytes.Serialize(s);
|
|
||||||
// Heights are stored big-endian for key sorting in LevelDB
|
|
||||||
ser_writedata32be(s, blockHeight);
|
|
||||||
ser_writedata32be(s, txindex);
|
|
||||||
txhash.Serialize(s);
|
|
||||||
ser_writedata32(s, index);
|
|
||||||
char f = is_spent;
|
|
||||||
ser_writedata8(s, f);
|
|
||||||
}
|
|
||||||
template<typename Stream>
|
|
||||||
void Unserialize(Stream& s) {
|
|
||||||
type = ser_readdata8(s);
|
|
||||||
hashBytes.Unserialize(s);
|
|
||||||
blockHeight = ser_readdata32be(s);
|
|
||||||
txindex = ser_readdata32be(s);
|
|
||||||
txhash.Unserialize(s);
|
|
||||||
index = ser_readdata32(s);
|
|
||||||
char f = ser_readdata8(s);
|
|
||||||
is_spent = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
|
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
|
||||||
uint256 txid, size_t indexValue, bool isSpending) {
|
uint256 txid, size_t indexValue, bool isSpending) {
|
||||||
type = addressType;
|
type = addressType;
|
||||||
@ -290,26 +288,43 @@ struct CAddressIndexKey {
|
|||||||
is_spent = false;
|
is_spent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
public:
|
||||||
|
|
||||||
struct CAddressIndexIteratorKey {
|
|
||||||
unsigned int type;
|
|
||||||
uint160 hashBytes;
|
|
||||||
|
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
return 21;
|
return 66;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Serialize(Stream& s) const {
|
void Serialize(Stream& s) const {
|
||||||
ser_writedata8(s, type);
|
ser_writedata8(s, type);
|
||||||
hashBytes.Serialize(s);
|
hashBytes.Serialize(s);
|
||||||
|
// Heights are stored big-endian for key sorting in LevelDB
|
||||||
|
ser_writedata32be(s, blockHeight);
|
||||||
|
ser_writedata32be(s, txindex);
|
||||||
|
txhash.Serialize(s);
|
||||||
|
ser_writedata32(s, index);
|
||||||
|
char f = is_spent;
|
||||||
|
ser_writedata8(s, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Unserialize(Stream& s) {
|
void Unserialize(Stream& s) {
|
||||||
type = ser_readdata8(s);
|
type = ser_readdata8(s);
|
||||||
hashBytes.Unserialize(s);
|
hashBytes.Unserialize(s);
|
||||||
|
blockHeight = ser_readdata32be(s);
|
||||||
|
txindex = ser_readdata32be(s);
|
||||||
|
txhash.Unserialize(s);
|
||||||
|
index = ser_readdata32(s);
|
||||||
|
char f = ser_readdata8(s);
|
||||||
|
is_spent = f;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CAddressIndexIteratorKey {
|
||||||
|
public:
|
||||||
|
unsigned int type;
|
||||||
|
uint160 hashBytes;
|
||||||
|
|
||||||
|
public:
|
||||||
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
|
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
|
||||||
type = addressType;
|
type = addressType;
|
||||||
hashBytes = addressHash;
|
hashBytes = addressHash;
|
||||||
@ -323,29 +338,32 @@ struct CAddressIndexIteratorKey {
|
|||||||
type = AddressType::UNKNOWN;
|
type = AddressType::UNKNOWN;
|
||||||
hashBytes.SetNull();
|
hashBytes.SetNull();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
struct CAddressIndexIteratorHeightKey {
|
|
||||||
unsigned int type;
|
|
||||||
uint160 hashBytes;
|
|
||||||
int blockHeight;
|
|
||||||
|
|
||||||
|
public:
|
||||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
return 25;
|
return 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Serialize(Stream& s) const {
|
void Serialize(Stream& s) const {
|
||||||
ser_writedata8(s, type);
|
ser_writedata8(s, type);
|
||||||
hashBytes.Serialize(s);
|
hashBytes.Serialize(s);
|
||||||
ser_writedata32be(s, blockHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Unserialize(Stream& s) {
|
void Unserialize(Stream& s) {
|
||||||
type = ser_readdata8(s);
|
type = ser_readdata8(s);
|
||||||
hashBytes.Unserialize(s);
|
hashBytes.Unserialize(s);
|
||||||
blockHeight = ser_readdata32be(s);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CAddressIndexIteratorHeightKey {
|
||||||
|
public:
|
||||||
|
unsigned int type;
|
||||||
|
uint160 hashBytes;
|
||||||
|
int blockHeight;
|
||||||
|
|
||||||
|
public:
|
||||||
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
|
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
|
||||||
type = addressType;
|
type = addressType;
|
||||||
hashBytes = addressHash;
|
hashBytes = addressHash;
|
||||||
@ -361,7 +379,25 @@ struct CAddressIndexIteratorHeightKey {
|
|||||||
hashBytes.SetNull();
|
hashBytes.SetNull();
|
||||||
blockHeight = 0;
|
blockHeight = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Serialize(Stream& s) const {
|
||||||
|
ser_writedata8(s, type);
|
||||||
|
hashBytes.Serialize(s);
|
||||||
|
ser_writedata32be(s, blockHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
void Unserialize(Stream& s) {
|
||||||
|
type = ser_readdata8(s);
|
||||||
|
hashBytes.Unserialize(s);
|
||||||
|
blockHeight = ser_readdata32be(s);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // BITCOIN_SPENTINDEX_H
|
#endif // BITCOIN_SPENTINDEX_H
|
||||||
|
Loading…
Reference in New Issue
Block a user