mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +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>
|
||||
|
||||
struct CSpentIndexKey {
|
||||
public:
|
||||
uint256 txid;
|
||||
unsigned int outputIndex;
|
||||
|
||||
SERIALIZE_METHODS(CSpentIndexKey, obj)
|
||||
{
|
||||
READWRITE(obj.txid, obj.outputIndex);
|
||||
}
|
||||
|
||||
public:
|
||||
CSpentIndexKey(uint256 t, unsigned int i) {
|
||||
txid = t;
|
||||
outputIndex = i;
|
||||
@ -37,9 +34,15 @@ struct CSpentIndexKey {
|
||||
outputIndex = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
SERIALIZE_METHODS(CSpentIndexKey, obj)
|
||||
{
|
||||
READWRITE(obj.txid, obj.outputIndex);
|
||||
}
|
||||
};
|
||||
|
||||
struct CSpentIndexValue {
|
||||
public:
|
||||
uint256 txid;
|
||||
unsigned int inputIndex;
|
||||
int blockHeight;
|
||||
@ -47,11 +50,7 @@ struct CSpentIndexValue {
|
||||
int addressType;
|
||||
uint160 addressHash;
|
||||
|
||||
SERIALIZE_METHODS(CSpentIndexValue, obj)
|
||||
{
|
||||
READWRITE(obj.txid, obj.inputIndex, obj.blockHeight, obj.satoshis, obj.addressType, obj.addressHash);
|
||||
}
|
||||
|
||||
public:
|
||||
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
|
||||
txid = t;
|
||||
inputIndex = i;
|
||||
@ -77,6 +76,12 @@ struct CSpentIndexValue {
|
||||
bool IsNull() const {
|
||||
return txid.IsNull();
|
||||
}
|
||||
|
||||
public:
|
||||
SERIALIZE_METHODS(CSpentIndexValue, obj)
|
||||
{
|
||||
READWRITE(obj.txid, obj.inputIndex, obj.blockHeight, obj.satoshis, obj.addressType, obj.addressHash);
|
||||
}
|
||||
};
|
||||
|
||||
struct CSpentIndexKeyCompare
|
||||
@ -95,20 +100,10 @@ struct CSpentIndexTxInfo
|
||||
};
|
||||
|
||||
struct CTimestampIndexIteratorKey {
|
||||
public:
|
||||
unsigned int timestamp;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
CTimestampIndexIteratorKey(unsigned int time) {
|
||||
timestamp = time;
|
||||
}
|
||||
@ -120,26 +115,29 @@ struct CTimestampIndexIteratorKey {
|
||||
void SetNull() {
|
||||
timestamp = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CTimestampIndexKey {
|
||||
unsigned int timestamp;
|
||||
uint256 blockHash;
|
||||
|
||||
public:
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 36;
|
||||
return 4;
|
||||
}
|
||||
|
||||
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 CTimestampIndexKey {
|
||||
public:
|
||||
unsigned int timestamp;
|
||||
uint256 blockHash;
|
||||
|
||||
public:
|
||||
CTimestampIndexKey(unsigned int time, uint256 hash) {
|
||||
timestamp = time;
|
||||
blockHash = hash;
|
||||
@ -153,32 +151,33 @@ struct CTimestampIndexKey {
|
||||
timestamp = 0;
|
||||
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 {
|
||||
public:
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
uint256 txhash;
|
||||
size_t index;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public:
|
||||
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
@ -196,18 +195,36 @@ struct CAddressUnspentKey {
|
||||
txhash.SetNull();
|
||||
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 {
|
||||
public:
|
||||
CAmount satoshis;
|
||||
CScript script;
|
||||
int blockHeight;
|
||||
|
||||
SERIALIZE_METHODS(CAddressUnspentValue, obj)
|
||||
{
|
||||
READWRITE(obj.satoshis, obj.script, obj.blockHeight);
|
||||
}
|
||||
|
||||
public:
|
||||
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
|
||||
satoshis = sats;
|
||||
script = scriptPubKey;
|
||||
@ -227,9 +244,16 @@ struct CAddressUnspentValue {
|
||||
bool IsNull() const {
|
||||
return (satoshis == -1);
|
||||
}
|
||||
|
||||
public:
|
||||
SERIALIZE_METHODS(CAddressUnspentValue, obj)
|
||||
{
|
||||
READWRITE(obj.satoshis, obj.script, obj.blockHeight);
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexKey {
|
||||
public:
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
@ -238,33 +262,7 @@ struct CAddressIndexKey {
|
||||
size_t index;
|
||||
bool is_spent;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
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;
|
||||
}
|
||||
|
||||
public:
|
||||
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
|
||||
uint256 txid, size_t indexValue, bool isSpending) {
|
||||
type = addressType;
|
||||
@ -290,26 +288,43 @@ struct CAddressIndexKey {
|
||||
is_spent = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
|
||||
public:
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 21;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorKey {
|
||||
public:
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
|
||||
public:
|
||||
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
@ -323,29 +338,32 @@ struct CAddressIndexIteratorKey {
|
||||
type = AddressType::UNKNOWN;
|
||||
hashBytes.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorHeightKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
|
||||
public:
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 25;
|
||||
return 21;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorHeightKey {
|
||||
public:
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
|
||||
public:
|
||||
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
@ -361,7 +379,25 @@ struct CAddressIndexIteratorHeightKey {
|
||||
hashBytes.SetNull();
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user