2016-05-16 20:23:01 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_SPENTINDEX_H
|
|
|
|
#define BITCOIN_SPENTINDEX_H
|
|
|
|
|
|
|
|
#include "uint256.h"
|
|
|
|
#include "amount.h"
|
2017-09-15 18:34:04 +02:00
|
|
|
#include "script/script.h"
|
2019-06-19 07:24:14 +02:00
|
|
|
#include "serialize.h"
|
2016-05-16 20:23:01 +02:00
|
|
|
|
|
|
|
struct CSpentIndexKey {
|
|
|
|
uint256 txid;
|
|
|
|
unsigned int outputIndex;
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2016-05-16 20:23:01 +02:00
|
|
|
READWRITE(txid);
|
|
|
|
READWRITE(outputIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSpentIndexKey(uint256 t, unsigned int i) {
|
|
|
|
txid = t;
|
|
|
|
outputIndex = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSpentIndexKey() {
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull() {
|
|
|
|
txid.SetNull();
|
|
|
|
outputIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CSpentIndexValue {
|
|
|
|
uint256 txid;
|
|
|
|
unsigned int inputIndex;
|
|
|
|
int blockHeight;
|
|
|
|
CAmount satoshis;
|
|
|
|
int addressType;
|
|
|
|
uint160 addressHash;
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2016-05-16 20:23:01 +02:00
|
|
|
READWRITE(txid);
|
|
|
|
READWRITE(inputIndex);
|
|
|
|
READWRITE(blockHeight);
|
|
|
|
READWRITE(satoshis);
|
|
|
|
READWRITE(addressType);
|
|
|
|
READWRITE(addressHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
|
|
|
|
txid = t;
|
|
|
|
inputIndex = i;
|
|
|
|
blockHeight = h;
|
|
|
|
satoshis = s;
|
|
|
|
addressType = type;
|
|
|
|
addressHash = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSpentIndexValue() {
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull() {
|
|
|
|
txid.SetNull();
|
|
|
|
inputIndex = 0;
|
|
|
|
blockHeight = 0;
|
|
|
|
satoshis = 0;
|
|
|
|
addressType = 0;
|
|
|
|
addressHash.SetNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNull() const {
|
|
|
|
return txid.IsNull();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CSpentIndexKeyCompare
|
|
|
|
{
|
|
|
|
bool operator()(const CSpentIndexKey& a, const CSpentIndexKey& b) const {
|
|
|
|
if (a.txid == b.txid) {
|
|
|
|
return a.outputIndex < b.outputIndex;
|
|
|
|
} else {
|
|
|
|
return a.txid < b.txid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-11 13:42:17 +02:00
|
|
|
struct CSpentIndexTxInfo
|
|
|
|
{
|
|
|
|
std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mSpentInfo;
|
|
|
|
};
|
|
|
|
|
2017-09-15 18:34:04 +02:00
|
|
|
struct CTimestampIndexIteratorKey {
|
|
|
|
unsigned int timestamp;
|
|
|
|
|
|
|
|
size_t GetSerializeSize(int nType, int nVersion) const {
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata32be(s, timestamp);
|
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata32be(s, timestamp);
|
2017-09-19 21:36:55 +02:00
|
|
|
blockHash.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
timestamp = ser_readdata32be(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
blockHash.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata8(s, type);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Serialize(s);
|
|
|
|
txhash.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata32(s, index);
|
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
type = ser_readdata8(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Unserialize(s);
|
|
|
|
txhash.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2017-09-15 18:34:04 +02:00
|
|
|
READWRITE(satoshis);
|
2019-07-09 07:59:57 +02:00
|
|
|
READWRITE(script);
|
2017-09-15 18:34:04 +02:00
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata8(s, type);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
// Heights are stored big-endian for key sorting in LevelDB
|
|
|
|
ser_writedata32be(s, blockHeight);
|
|
|
|
ser_writedata32be(s, txindex);
|
2017-09-19 21:36:55 +02:00
|
|
|
txhash.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata32(s, index);
|
|
|
|
char f = spending;
|
|
|
|
ser_writedata8(s, f);
|
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
type = ser_readdata8(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
blockHeight = ser_readdata32be(s);
|
|
|
|
txindex = ser_readdata32be(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
txhash.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata8(s, type);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
type = ser_readdata8(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Serialize(Stream& s) const {
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata8(s, type);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Serialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
ser_writedata32be(s, blockHeight);
|
|
|
|
}
|
|
|
|
template<typename Stream>
|
2017-09-19 21:36:55 +02:00
|
|
|
void Unserialize(Stream& s) {
|
2017-09-15 18:34:04 +02:00
|
|
|
type = ser_readdata8(s);
|
2017-09-19 21:36:55 +02:00
|
|
|
hashBytes.Unserialize(s);
|
2017-09-15 18:34:04 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-16 20:23:01 +02:00
|
|
|
#endif // BITCOIN_SPENTINDEX_H
|