Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

spentindex.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_SPENTINDEX_H
7 #define BITCOIN_SPENTINDEX_H
8 
9 #include <uint256.h>
10 #include <amount.h>
11 #include <script/script.h>
12 #include <serialize.h>
13 
16  unsigned int outputIndex;
17 
19 
20  template <typename Stream, typename Operation>
21  inline void SerializationOp(Stream& s, Operation ser_action) {
22  READWRITE(txid);
24  }
25 
26  CSpentIndexKey(uint256 t, unsigned int i) {
27  txid = t;
28  outputIndex = i;
29  }
30 
32  SetNull();
33  }
34 
35  void SetNull() {
36  txid.SetNull();
37  outputIndex = 0;
38  }
39 
40 };
41 
44  unsigned int inputIndex;
49 
51 
52  template <typename Stream, typename Operation>
53  inline void SerializationOp(Stream& s, Operation ser_action) {
54  READWRITE(txid);
60  }
61 
62  CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a) {
63  txid = t;
64  inputIndex = i;
65  blockHeight = h;
66  satoshis = s;
67  addressType = type;
68  addressHash = a;
69  }
70 
72  SetNull();
73  }
74 
75  void SetNull() {
76  txid.SetNull();
77  inputIndex = 0;
78  blockHeight = 0;
79  satoshis = 0;
80  addressType = 0;
82  }
83 
84  bool IsNull() const {
85  return txid.IsNull();
86  }
87 };
88 
90 {
91  bool operator()(const CSpentIndexKey& a, const CSpentIndexKey& b) const {
92  if (a.txid == b.txid) {
93  return a.outputIndex < b.outputIndex;
94  } else {
95  return a.txid < b.txid;
96  }
97  }
98 };
99 
101 {
102  std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mSpentInfo;
103 };
104 
106  unsigned int timestamp;
107 
108  size_t GetSerializeSize(int nType, int nVersion) const {
109  return 4;
110  }
111  template<typename Stream>
112  void Serialize(Stream& s) const {
114  }
115  template<typename Stream>
116  void Unserialize(Stream& s) {
118  }
119 
120  CTimestampIndexIteratorKey(unsigned int time) {
121  timestamp = time;
122  }
123 
125  SetNull();
126  }
127 
128  void SetNull() {
129  timestamp = 0;
130  }
131 };
132 
134  unsigned int timestamp;
136 
137  size_t GetSerializeSize(int nType, int nVersion) const {
138  return 36;
139  }
140  template<typename Stream>
141  void Serialize(Stream& s) const {
143  blockHash.Serialize(s);
144  }
145  template<typename Stream>
146  void Unserialize(Stream& s) {
149  }
150 
151  CTimestampIndexKey(unsigned int time, uint256 hash) {
152  timestamp = time;
153  blockHash = hash;
154  }
155 
157  SetNull();
158  }
159 
160  void SetNull() {
161  timestamp = 0;
162  blockHash.SetNull();
163  }
164 };
165 
167  unsigned int type;
170  size_t index;
171 
172  size_t GetSerializeSize(int nType, int nVersion) const {
173  return 57;
174  }
175  template<typename Stream>
176  void Serialize(Stream& s) const {
177  ser_writedata8(s, type);
178  hashBytes.Serialize(s);
179  txhash.Serialize(s);
181  }
182  template<typename Stream>
183  void Unserialize(Stream& s) {
184  type = ser_readdata8(s);
186  txhash.Unserialize(s);
187  index = ser_readdata32(s);
188  }
189 
190  CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
191  type = addressType;
192  hashBytes = addressHash;
193  txhash = txid;
194  index = indexValue;
195  }
196 
198  SetNull();
199  }
200 
201  void SetNull() {
202  type = 0;
203  hashBytes.SetNull();
204  txhash.SetNull();
205  index = 0;
206  }
207 };
208 
213 
215 
216  template <typename Stream, typename Operation>
217  inline void SerializationOp(Stream& s, Operation ser_action) {
219  READWRITE(script);
221  }
222 
223  CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
224  satoshis = sats;
225  script = scriptPubKey;
226  blockHeight = height;
227  }
228 
230  SetNull();
231  }
232 
233  void SetNull() {
234  satoshis = -1;
235  script.clear();
236  blockHeight = 0;
237  }
238 
239  bool IsNull() const {
240  return (satoshis == -1);
241  }
242 };
243 
245  unsigned int type;
248  unsigned int txindex;
250  size_t index;
251  bool spending;
252 
253  size_t GetSerializeSize(int nType, int nVersion) const {
254  return 66;
255  }
256  template<typename Stream>
257  void Serialize(Stream& s) const {
258  ser_writedata8(s, type);
259  hashBytes.Serialize(s);
260  // Heights are stored big-endian for key sorting in LevelDB
263  txhash.Serialize(s);
265  char f = spending;
266  ser_writedata8(s, f);
267  }
268  template<typename Stream>
269  void Unserialize(Stream& s) {
270  type = ser_readdata8(s);
274  txhash.Unserialize(s);
275  index = ser_readdata32(s);
276  char f = ser_readdata8(s);
277  spending = f;
278  }
279 
280  CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
281  uint256 txid, size_t indexValue, bool isSpending) {
282  type = addressType;
283  hashBytes = addressHash;
284  blockHeight = height;
285  txindex = blockindex;
286  txhash = txid;
287  index = indexValue;
288  spending = isSpending;
289  }
290 
292  SetNull();
293  }
294 
295  void SetNull() {
296  type = 0;
297  hashBytes.SetNull();
298  blockHeight = 0;
299  txindex = 0;
300  txhash.SetNull();
301  index = 0;
302  spending = false;
303  }
304 
305 };
306 
308  unsigned int type;
310 
311  size_t GetSerializeSize(int nType, int nVersion) const {
312  return 21;
313  }
314  template<typename Stream>
315  void Serialize(Stream& s) const {
316  ser_writedata8(s, type);
317  hashBytes.Serialize(s);
318  }
319  template<typename Stream>
320  void Unserialize(Stream& s) {
321  type = ser_readdata8(s);
323  }
324 
325  CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
326  type = addressType;
327  hashBytes = addressHash;
328  }
329 
331  SetNull();
332  }
333 
334  void SetNull() {
335  type = 0;
336  hashBytes.SetNull();
337  }
338 };
339 
341  unsigned int type;
344 
345  size_t GetSerializeSize(int nType, int nVersion) const {
346  return 25;
347  }
348  template<typename Stream>
349  void Serialize(Stream& s) const {
350  ser_writedata8(s, type);
351  hashBytes.Serialize(s);
353  }
354  template<typename Stream>
355  void Unserialize(Stream& s) {
356  type = ser_readdata8(s);
359  }
360 
361  CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
362  type = addressType;
363  hashBytes = addressHash;
364  blockHeight = height;
365  }
366 
368  SetNull();
369  }
370 
371  void SetNull() {
372  type = 0;
373  hashBytes.SetNull();
374  blockHeight = 0;
375  }
376 };
377 
378 
379 #endif // BITCOIN_SPENTINDEX_H
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:137
void Serialize(Stream &s) const
Definition: spentindex.h:141
void Unserialize(Stream &s)
Definition: spentindex.h:269
void SetNull()
Definition: spentindex.h:35
void Unserialize(Stream &s)
Definition: spentindex.h:146
void Unserialize(Stream &s)
Definition: spentindex.h:183
void SetNull()
Definition: uint256.h:41
CTimestampIndexKey(unsigned int time, uint256 hash)
Definition: spentindex.h:151
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:93
#define READWRITE(obj)
Definition: serialize.h:165
CSpentIndexValue(uint256 t, unsigned int i, int h, CAmount s, int type, uint160 a)
Definition: spentindex.h:62
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue)
Definition: spentindex.h:190
unsigned int outputIndex
Definition: spentindex.h:16
unsigned int inputIndex
Definition: spentindex.h:44
unsigned int type
Definition: spentindex.h:245
void SerializationOp(Stream &s, Operation ser_action)
Definition: spentindex.h:217
void ser_writedata32(Stream &s, uint32_t obj)
Definition: serialize.h:78
void Serialize(Stream &s) const
Definition: uint256.h:96
uint160 hashBytes
Definition: spentindex.h:246
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:108
void Serialize(Stream &s) const
Definition: spentindex.h:349
bool IsNull() const
Definition: uint256.h:33
unsigned int timestamp
Definition: spentindex.h:134
bool IsNull() const
Definition: spentindex.h:239
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void Unserialize(Stream &s)
Definition: uint256.h:102
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height)
Definition: spentindex.h:361
std::map< CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare > mSpentInfo
Definition: spentindex.h:102
CTimestampIndexIteratorKey(unsigned int time)
Definition: spentindex.h:120
uint32_t ser_readdata32(Stream &s)
Definition: serialize.h:105
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:253
unsigned int type
Definition: spentindex.h:167
CSpentIndexKey(uint256 t, unsigned int i)
Definition: spentindex.h:26
bool operator()(const CSpentIndexKey &a, const CSpentIndexKey &b) const
Definition: spentindex.h:91
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height)
Definition: spentindex.h:223
void Serialize(Stream &s) const
Definition: spentindex.h:176
void Serialize(Stream &s) const
Definition: spentindex.h:112
uint256 txid
Definition: spentindex.h:15
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:311
void SerializationOp(Stream &s, Operation ser_action)
Definition: spentindex.h:21
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash)
Definition: spentindex.h:325
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:83
void Serialize(Stream &s) const
Definition: spentindex.h:257
void Unserialize(Stream &s)
Definition: spentindex.h:320
256-bit opaque blob.
Definition: uint256.h:123
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:345
void Unserialize(Stream &s)
Definition: spentindex.h:116
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
uint160 addressHash
Definition: spentindex.h:48
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:111
void SerializationOp(Stream &s, Operation ser_action)
Definition: spentindex.h:53
160-bit opaque blob.
Definition: uint256.h:112
bool IsNull() const
Definition: spentindex.h:84
unsigned int txindex
Definition: spentindex.h:248
CAmount satoshis
Definition: spentindex.h:46
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex, uint256 txid, size_t indexValue, bool isSpending)
Definition: spentindex.h:280
void clear()
Definition: script.h:664
void ser_writedata8(Stream &s, uint8_t obj)
Definition: serialize.h:69
void Serialize(Stream &s) const
Definition: spentindex.h:315
size_t GetSerializeSize(int nType, int nVersion) const
Definition: spentindex.h:172
Released under the MIT license