diff --git a/src/addressindex.h b/src/addressindex.h index a00b6e5b70..ed3225e3c1 100644 --- a/src/addressindex.h +++ b/src/addressindex.h @@ -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 + 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 + 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 + void Serialize(Stream& s) const { + ser_writedata8(s, m_address_type); + m_address_bytes.Serialize(s); + } + + template + 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 + void Serialize(Stream& s) const { + ser_writedata8(s, m_address_type); + m_address_bytes.Serialize(s); + ser_writedata32be(s, m_block_height); + } + + template + 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 diff --git a/src/spentindex.h b/src/spentindex.h index 3c03d66e95..7bf4e58b07 100644 --- a/src/spentindex.h +++ b/src/spentindex.h @@ -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 - 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 - 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 - void Serialize(Stream& s) const { - ser_writedata8(s, m_address_type); - m_address_bytes.Serialize(s); - } - - template - 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 - void Serialize(Stream& s) const { - ser_writedata8(s, m_address_type); - m_address_bytes.Serialize(s); - ser_writedata32be(s, m_block_height); - } - - template - 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