refactor: move CAddressIndex* out of spentindex

This commit is contained in:
Kittywhiskers Van Gogh 2023-09-25 20:25:34 +05:30
parent cc2efac4b4
commit 0cc321cd8c
2 changed files with 142 additions and 142 deletions

View File

@ -72,4 +72,146 @@ struct CMempoolAddressDeltaKeyCompare
}
};
struct CAddressIndexKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
int32_t m_block_height{0};
uint32_t m_block_tx_pos{0};
uint256 m_tx_hash;
uint32_t m_tx_index{0};
bool m_tx_spent{false};
public:
CAddressIndexKey() {
SetNull();
}
CAddressIndexKey(uint8_t address_type, uint160 address_bytes, int32_t block_height, uint32_t block_tx_pos, uint256 tx_hash,
uint32_t tx_index, bool tx_spent) :
m_address_type{address_type},
m_address_bytes{address_bytes},
m_block_height{block_height},
m_block_tx_pos{block_tx_pos},
m_tx_hash{tx_hash},
m_tx_index{tx_index},
m_tx_spent{tx_spent} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
m_block_height = 0;
m_block_tx_pos = 0;
m_tx_hash.SetNull();
m_tx_index = 0;
m_tx_spent = false;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 66;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
// Heights are stored big-endian for key sorting in LevelDB
ser_writedata32be(s, m_block_height);
ser_writedata32be(s, m_block_tx_pos);
m_tx_hash.Serialize(s);
ser_writedata32(s, m_tx_index);
char f = m_tx_spent;
ser_writedata8(s, f);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s);
m_block_tx_pos = ser_readdata32be(s);
m_tx_hash.Unserialize(s);
m_tx_index = ser_readdata32(s);
char f = ser_readdata8(s);
m_tx_spent = f;
}
};
struct CAddressIndexIteratorKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
public:
CAddressIndexIteratorKey() {
SetNull();
}
CAddressIndexIteratorKey(uint8_t address_type, uint160 address_bytes) :
m_address_type{address_type}, m_address_bytes{address_bytes} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 21;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
}
};
struct CAddressIndexIteratorHeightKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
int32_t m_block_height{0};
public:
CAddressIndexIteratorHeightKey() {
SetNull();
}
CAddressIndexIteratorHeightKey(uint8_t address_type, uint160 address_bytes, int32_t block_height) :
m_address_type{address_type}, m_address_bytes{address_bytes}, m_block_height{block_height} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
m_block_height = 0;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 25;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
ser_writedata32be(s, m_block_height);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s);
}
};
#endif // BITCOIN_ADDRESSINDEX_H

View File

@ -174,146 +174,4 @@ public:
}
};
struct CAddressIndexKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
int32_t m_block_height{0};
uint32_t m_block_tx_pos{0};
uint256 m_tx_hash;
uint32_t m_tx_index{0};
bool m_tx_spent{false};
public:
CAddressIndexKey() {
SetNull();
}
CAddressIndexKey(uint8_t address_type, uint160 address_bytes, int32_t block_height, uint32_t block_tx_pos, uint256 tx_hash,
uint32_t tx_index, bool tx_spent) :
m_address_type{address_type},
m_address_bytes{address_bytes},
m_block_height{block_height},
m_block_tx_pos{block_tx_pos},
m_tx_hash{tx_hash},
m_tx_index{tx_index},
m_tx_spent{tx_spent} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
m_block_height = 0;
m_block_tx_pos = 0;
m_tx_hash.SetNull();
m_tx_index = 0;
m_tx_spent = false;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 66;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
// Heights are stored big-endian for key sorting in LevelDB
ser_writedata32be(s, m_block_height);
ser_writedata32be(s, m_block_tx_pos);
m_tx_hash.Serialize(s);
ser_writedata32(s, m_tx_index);
char f = m_tx_spent;
ser_writedata8(s, f);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s);
m_block_tx_pos = ser_readdata32be(s);
m_tx_hash.Unserialize(s);
m_tx_index = ser_readdata32(s);
char f = ser_readdata8(s);
m_tx_spent = f;
}
};
struct CAddressIndexIteratorKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
public:
CAddressIndexIteratorKey() {
SetNull();
}
CAddressIndexIteratorKey(uint8_t address_type, uint160 address_bytes) :
m_address_type{address_type}, m_address_bytes{address_bytes} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 21;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
}
};
struct CAddressIndexIteratorHeightKey {
public:
uint8_t m_address_type{AddressType::UNKNOWN};
uint160 m_address_bytes;
int32_t m_block_height{0};
public:
CAddressIndexIteratorHeightKey() {
SetNull();
}
CAddressIndexIteratorHeightKey(uint8_t address_type, uint160 address_bytes, int32_t block_height) :
m_address_type{address_type}, m_address_bytes{address_bytes}, m_block_height{block_height} {};
void SetNull() {
m_address_type = AddressType::UNKNOWN;
m_address_bytes.SetNull();
m_block_height = 0;
}
public:
size_t GetSerializeSize(int nType, int nVersion) const {
return 25;
}
template<typename Stream>
void Serialize(Stream& s) const {
ser_writedata8(s, m_address_type);
m_address_bytes.Serialize(s);
ser_writedata32be(s, m_block_height);
}
template<typename Stream>
void Unserialize(Stream& s) {
m_address_type = ser_readdata8(s);
m_address_bytes.Unserialize(s);
m_block_height = ser_readdata32be(s);
}
};
#endif // BITCOIN_SPENTINDEX_H