Move index structures into spentindex.h
txdb.h does not include validation.h anymore, so we need these structs somewhere else
This commit is contained in:
parent
abaf524f0c
commit
02a6cef94d
275
src/spentindex.h
275
src/spentindex.h
@ -8,6 +8,7 @@
|
||||
|
||||
#include "uint256.h"
|
||||
#include "amount.h"
|
||||
#include "script/script.h"
|
||||
|
||||
struct CSpentIndexKey {
|
||||
uint256 txid;
|
||||
@ -95,4 +96,278 @@ struct CSpentIndexKeyCompare
|
||||
}
|
||||
};
|
||||
|
||||
struct CTimestampIndexIteratorKey {
|
||||
unsigned int timestamp;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 4;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata32be(s, timestamp);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
timestamp = ser_readdata32be(s);
|
||||
}
|
||||
|
||||
CTimestampIndexIteratorKey(unsigned int time) {
|
||||
timestamp = time;
|
||||
}
|
||||
|
||||
CTimestampIndexIteratorKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
timestamp = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CTimestampIndexKey {
|
||||
unsigned int timestamp;
|
||||
uint256 blockHash;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 36;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata32be(s, timestamp);
|
||||
blockHash.Serialize(s, nType, nVersion);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
timestamp = ser_readdata32be(s);
|
||||
blockHash.Unserialize(s, nType, nVersion);
|
||||
}
|
||||
|
||||
CTimestampIndexKey(unsigned int time, uint256 hash) {
|
||||
timestamp = time;
|
||||
blockHash = hash;
|
||||
}
|
||||
|
||||
CTimestampIndexKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
timestamp = 0;
|
||||
blockHash.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressUnspentKey {
|
||||
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, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
txhash.Serialize(s, nType, nVersion);
|
||||
ser_writedata32(s, index);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
txhash.Unserialize(s, nType, nVersion);
|
||||
index = ser_readdata32(s);
|
||||
}
|
||||
|
||||
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
txhash = txid;
|
||||
index = indexValue;
|
||||
}
|
||||
|
||||
CAddressUnspentKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
txhash.SetNull();
|
||||
index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressUnspentValue {
|
||||
CAmount satoshis;
|
||||
CScript script;
|
||||
int blockHeight;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(satoshis);
|
||||
READWRITE(*(CScriptBase*)(&script));
|
||||
READWRITE(blockHeight);
|
||||
}
|
||||
|
||||
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
|
||||
satoshis = sats;
|
||||
script = scriptPubKey;
|
||||
blockHeight = height;
|
||||
}
|
||||
|
||||
CAddressUnspentValue() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
satoshis = -1;
|
||||
script.clear();
|
||||
blockHeight = 0;
|
||||
}
|
||||
|
||||
bool IsNull() const {
|
||||
return (satoshis == -1);
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
unsigned int txindex;
|
||||
uint256 txhash;
|
||||
size_t index;
|
||||
bool spending;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 66;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
// Heights are stored big-endian for key sorting in LevelDB
|
||||
ser_writedata32be(s, blockHeight);
|
||||
ser_writedata32be(s, txindex);
|
||||
txhash.Serialize(s, nType, nVersion);
|
||||
ser_writedata32(s, index);
|
||||
char f = spending;
|
||||
ser_writedata8(s, f);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
blockHeight = ser_readdata32be(s);
|
||||
txindex = ser_readdata32be(s);
|
||||
txhash.Unserialize(s, nType, nVersion);
|
||||
index = ser_readdata32(s);
|
||||
char f = ser_readdata8(s);
|
||||
spending = f;
|
||||
}
|
||||
|
||||
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
|
||||
uint256 txid, size_t indexValue, bool isSpending) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
blockHeight = height;
|
||||
txindex = blockindex;
|
||||
txhash = txid;
|
||||
index = indexValue;
|
||||
spending = isSpending;
|
||||
}
|
||||
|
||||
CAddressIndexKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
blockHeight = 0;
|
||||
txindex = 0;
|
||||
txhash.SetNull();
|
||||
index = 0;
|
||||
spending = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 21;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
}
|
||||
|
||||
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
}
|
||||
|
||||
CAddressIndexIteratorKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorHeightKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 25;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
ser_writedata32be(s, blockHeight);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
blockHeight = ser_readdata32be(s);
|
||||
}
|
||||
|
||||
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
blockHeight = height;
|
||||
}
|
||||
|
||||
CAddressIndexIteratorHeightKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
blockHeight = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // BITCOIN_SPENTINDEX_H
|
||||
|
11
src/txdb.h
11
src/txdb.h
@ -9,6 +9,7 @@
|
||||
#include "coins.h"
|
||||
#include "dbwrapper.h"
|
||||
#include "chain.h"
|
||||
#include "spentindex.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@ -21,16 +22,6 @@ class CBlockIndex;
|
||||
class CCoinsViewDBCursor;
|
||||
class uint256;
|
||||
|
||||
struct CAddressUnspentKey;
|
||||
struct CAddressUnspentValue;
|
||||
struct CAddressIndexKey;
|
||||
struct CAddressIndexIteratorKey;
|
||||
struct CAddressIndexIteratorHeightKey;
|
||||
struct CTimestampIndexKey;
|
||||
struct CTimestampIndexIteratorKey;
|
||||
struct CSpentIndexKey;
|
||||
struct CSpentIndexValue;
|
||||
|
||||
//! -dbcache default (MiB)
|
||||
static const int64_t nDefaultDbCache = 100;
|
||||
//! max. -dbcache in (MiB)
|
||||
|
277
src/validation.h
277
src/validation.h
@ -310,282 +310,7 @@ std::string FormatStateMessage(const CValidationState &state);
|
||||
/** Get the BIP9 state for a given deployment at the current tip. */
|
||||
ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);
|
||||
|
||||
struct CTimestampIndexIteratorKey {
|
||||
unsigned int timestamp;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 4;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata32be(s, timestamp);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
timestamp = ser_readdata32be(s);
|
||||
}
|
||||
|
||||
CTimestampIndexIteratorKey(unsigned int time) {
|
||||
timestamp = time;
|
||||
}
|
||||
|
||||
CTimestampIndexIteratorKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
timestamp = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CTimestampIndexKey {
|
||||
unsigned int timestamp;
|
||||
uint256 blockHash;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 36;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata32be(s, timestamp);
|
||||
blockHash.Serialize(s, nType, nVersion);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
timestamp = ser_readdata32be(s);
|
||||
blockHash.Unserialize(s, nType, nVersion);
|
||||
}
|
||||
|
||||
CTimestampIndexKey(unsigned int time, uint256 hash) {
|
||||
timestamp = time;
|
||||
blockHash = hash;
|
||||
}
|
||||
|
||||
CTimestampIndexKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
timestamp = 0;
|
||||
blockHash.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressUnspentKey {
|
||||
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, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
txhash.Serialize(s, nType, nVersion);
|
||||
ser_writedata32(s, index);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
txhash.Unserialize(s, nType, nVersion);
|
||||
index = ser_readdata32(s);
|
||||
}
|
||||
|
||||
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
txhash = txid;
|
||||
index = indexValue;
|
||||
}
|
||||
|
||||
CAddressUnspentKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
txhash.SetNull();
|
||||
index = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressUnspentValue {
|
||||
CAmount satoshis;
|
||||
CScript script;
|
||||
int blockHeight;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
READWRITE(satoshis);
|
||||
READWRITE(*(CScriptBase*)(&script));
|
||||
READWRITE(blockHeight);
|
||||
}
|
||||
|
||||
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
|
||||
satoshis = sats;
|
||||
script = scriptPubKey;
|
||||
blockHeight = height;
|
||||
}
|
||||
|
||||
CAddressUnspentValue() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
satoshis = -1;
|
||||
script.clear();
|
||||
blockHeight = 0;
|
||||
}
|
||||
|
||||
bool IsNull() const {
|
||||
return (satoshis == -1);
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
unsigned int txindex;
|
||||
uint256 txhash;
|
||||
size_t index;
|
||||
bool spending;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 66;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
// Heights are stored big-endian for key sorting in LevelDB
|
||||
ser_writedata32be(s, blockHeight);
|
||||
ser_writedata32be(s, txindex);
|
||||
txhash.Serialize(s, nType, nVersion);
|
||||
ser_writedata32(s, index);
|
||||
char f = spending;
|
||||
ser_writedata8(s, f);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
blockHeight = ser_readdata32be(s);
|
||||
txindex = ser_readdata32be(s);
|
||||
txhash.Unserialize(s, nType, nVersion);
|
||||
index = ser_readdata32(s);
|
||||
char f = ser_readdata8(s);
|
||||
spending = f;
|
||||
}
|
||||
|
||||
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
|
||||
uint256 txid, size_t indexValue, bool isSpending) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
blockHeight = height;
|
||||
txindex = blockindex;
|
||||
txhash = txid;
|
||||
index = indexValue;
|
||||
spending = isSpending;
|
||||
}
|
||||
|
||||
CAddressIndexKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
blockHeight = 0;
|
||||
txindex = 0;
|
||||
txhash.SetNull();
|
||||
index = 0;
|
||||
spending = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 21;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
}
|
||||
|
||||
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
}
|
||||
|
||||
CAddressIndexIteratorKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
}
|
||||
};
|
||||
|
||||
struct CAddressIndexIteratorHeightKey {
|
||||
unsigned int type;
|
||||
uint160 hashBytes;
|
||||
int blockHeight;
|
||||
|
||||
size_t GetSerializeSize(int nType, int nVersion) const {
|
||||
return 25;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s, int nType, int nVersion) const {
|
||||
ser_writedata8(s, type);
|
||||
hashBytes.Serialize(s, nType, nVersion);
|
||||
ser_writedata32be(s, blockHeight);
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s, int nType, int nVersion) {
|
||||
type = ser_readdata8(s);
|
||||
hashBytes.Unserialize(s, nType, nVersion);
|
||||
blockHeight = ser_readdata32be(s);
|
||||
}
|
||||
|
||||
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
|
||||
type = addressType;
|
||||
hashBytes = addressHash;
|
||||
blockHeight = height;
|
||||
}
|
||||
|
||||
CAddressIndexIteratorHeightKey() {
|
||||
SetNull();
|
||||
}
|
||||
|
||||
void SetNull() {
|
||||
type = 0;
|
||||
hashBytes.SetNull();
|
||||
blockHeight = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Count ECDSA signature operations the old-fashioned (pre-0.6) way
|
||||
* @return number of sigops this transaction's outputs will produce when spent
|
||||
* @see CTransaction::FetchInputs
|
||||
|
Loading…
Reference in New Issue
Block a user