Raven Core  3.0.0
P2P Digital Currency
addressindex.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 RAVEN_ADDRESSINDEX_H
7 #define RAVEN_ADDRESSINDEX_H
8 
9 #include "uint256.h"
10 #include "amount.h"
11 #include "script/script.h"
12 
13 static const std::string RVN = "RVN";
14 
16  unsigned int type;
18  std::string asset;
20  size_t index;
21 
22  size_t GetSerializeSize() const {
23  return 57 + asset.size();
24  }
25  template<typename Stream>
26  void Serialize(Stream& s) const {
27  ser_writedata8(s, type);
28  hashBytes.Serialize(s);
29  ::Serialize(s, asset);
30  txhash.Serialize(s);
31  ser_writedata32(s, index);
32  }
33  template<typename Stream>
34  void Unserialize(Stream& s) {
35  type = ser_readdata8(s);
36  hashBytes.Unserialize(s);
37  ::Unserialize(s, asset);
38  txhash.Unserialize(s);
39  index = ser_readdata32(s);
40  }
41 
42  CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue) {
43  type = addressType;
44  hashBytes = addressHash;
45  asset = RVN;
46  txhash = txid;
47  index = indexValue;
48  }
49 
50  CAddressUnspentKey(unsigned int addressType, uint160 addressHash, std::string assetName, uint256 txid, size_t indexValue) {
51  type = addressType;
52  hashBytes = addressHash;
53  asset = assetName;
54  txhash = txid;
55  index = indexValue;
56  }
57 
59  SetNull();
60  }
61 
62  void SetNull() {
63  type = 0;
64  hashBytes.SetNull();
65  asset.clear();
66  txhash.SetNull();
67  index = 0;
68  }
69 };
70 
75 
77 
78  template <typename Stream, typename Operation>
79  inline void SerializationOp(Stream& s, Operation ser_action) {
80  READWRITE(satoshis);
81  READWRITE(*(CScriptBase*)(&script));
82  READWRITE(blockHeight);
83  }
84 
85  CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height) {
86  satoshis = sats;
87  script = scriptPubKey;
88  blockHeight = height;
89  }
90 
92  SetNull();
93  }
94 
95  void SetNull() {
96  satoshis = -1;
97  script.clear();
98  blockHeight = 0;
99  }
100 
101  bool IsNull() const {
102  return (satoshis == -1);
103  }
104 };
105 
107  unsigned int type;
109  std::string asset;
111  unsigned int txindex;
113  size_t index;
114  bool spending;
115 
116  size_t GetSerializeSize() const {
117  return 34 + asset.size();
118  }
119  template<typename Stream>
120  void Serialize(Stream& s) const {
121  ser_writedata8(s, type);
122  hashBytes.Serialize(s);
123  ::Serialize(s, asset);
124  // Heights are stored big-endian for key sorting in LevelDB
125  ser_writedata32be(s, blockHeight);
126  ser_writedata32be(s, txindex);
127  txhash.Serialize(s);
128  ser_writedata32(s, index);
129  char f = spending;
130  ser_writedata8(s, f);
131  }
132  template<typename Stream>
133  void Unserialize(Stream& s) {
134  type = ser_readdata8(s);
135  hashBytes.Unserialize(s);
136  ::Unserialize(s, asset);
137  blockHeight = ser_readdata32be(s);
138  txindex = ser_readdata32be(s);
139  txhash.Unserialize(s);
140  index = ser_readdata32(s);
141  char f = ser_readdata8(s);
142  spending = f;
143  }
144 
145  CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex,
146  uint256 txid, size_t indexValue, bool isSpending) {
147  type = addressType;
148  hashBytes = addressHash;
149  asset = RVN;
150  blockHeight = height;
151  txindex = blockindex;
152  txhash = txid;
153  index = indexValue;
154  spending = isSpending;
155  }
156 
157  CAddressIndexKey(unsigned int addressType, uint160 addressHash, std::string assetName, int height, int blockindex,
158  uint256 txid, size_t indexValue, bool isSpending) {
159  type = addressType;
160  hashBytes = addressHash;
161  asset = assetName;
162  blockHeight = height;
163  txindex = blockindex;
164  txhash = txid;
165  index = indexValue;
166  spending = isSpending;
167  }
168 
170  SetNull();
171  }
172 
173  void SetNull() {
174  type = 0;
175  hashBytes.SetNull();
176  asset.clear();
177  blockHeight = 0;
178  txindex = 0;
179  txhash.SetNull();
180  index = 0;
181  spending = false;
182  }
183 
184 };
185 
187  unsigned int type;
189 
190  size_t GetSerializeSize() const {
191  return 21;
192  }
193  template<typename Stream>
194  void Serialize(Stream& s) const {
195  ser_writedata8(s, type);
196  hashBytes.Serialize(s);
197  }
198  template<typename Stream>
199  void Unserialize(Stream& s) {
200  type = ser_readdata8(s);
201  hashBytes.Unserialize(s);
202  }
203 
204  CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash) {
205  type = addressType;
206  hashBytes = addressHash;
207  }
208 
210  SetNull();
211  }
212 
213  void SetNull() {
214  type = 0;
215  hashBytes.SetNull();
216  }
217 };
218 
220  unsigned int type;
222  std::string asset;
223 
224  size_t GetSerializeSize() const {
225  return 21 + asset.size();
226  }
227  template<typename Stream>
228  void Serialize(Stream& s) const {
229  ser_writedata8(s, type);
230  hashBytes.Serialize(s);
231  ::Serialize(s, asset);
232  }
233  template<typename Stream>
234  void Unserialize(Stream& s) {
235  type = ser_readdata8(s);
236  hashBytes.Unserialize(s);
237  ::Unserialize(s, asset);
238  }
239 
240  CAddressIndexIteratorAssetKey(unsigned int addressType, uint160 addressHash) {
241  type = addressType;
242  hashBytes = addressHash;
243  asset = RVN;
244  }
245 
246  CAddressIndexIteratorAssetKey(unsigned int addressType, uint160 addressHash, std::string assetName) {
247  type = addressType;
248  hashBytes = addressHash;
249  asset = assetName;
250  }
251 
253  SetNull();
254  }
255 
256  void SetNull() {
257  type = 0;
258  hashBytes.SetNull();
259  asset.clear();
260  }
261 };
262 
264  unsigned int type;
266  std::string asset;
268 
269  size_t GetSerializeSize() const {
270  return 25 + asset.size();
271  }
272  template<typename Stream>
273  void Serialize(Stream& s) const {
274  ser_writedata8(s, type);
275  hashBytes.Serialize(s);
276  ::Serialize(s, asset);
277  ser_writedata32be(s, blockHeight);
278  }
279  template<typename Stream>
280  void Unserialize(Stream& s) {
281  type = ser_readdata8(s);
282  hashBytes.Unserialize(s);
283  ::Unserialize(s, asset);
284  blockHeight = ser_readdata32be(s);
285  }
286 
287  CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height) {
288  type = addressType;
289  hashBytes = addressHash;
290  asset = RVN;
291  blockHeight = height;
292  }
293 
294  CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, std::string assetName, int height) {
295  type = addressType;
296  hashBytes = addressHash;
297  asset = assetName;
298  blockHeight = height;
299  }
300 
302  SetNull();
303  }
304 
305  void SetNull() {
306  type = 0;
307  hashBytes.SetNull();
308  asset.clear();
309  blockHeight = 0;
310  }
311 };
312 
314 {
315  int64_t time;
318  unsigned int prevout;
319 
320  CMempoolAddressDelta(int64_t t, CAmount a, uint256 hash, unsigned int out) {
321  time = t;
322  amount = a;
323  prevhash = hash;
324  prevout = out;
325  }
326 
328  time = t;
329  amount = a;
330  prevhash.SetNull();
331  prevout = 0;
332  }
333 };
334 
336 {
337  int type;
339  std::string asset;
341  unsigned int index;
342  int spending;
343 
344  CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string assetName,
345  uint256 hash, unsigned int i, int s) {
346  type = addressType;
347  addressBytes = addressHash;
348  asset = assetName;
349  txhash = hash;
350  index = i;
351  spending = s;
352  }
353 
354  CMempoolAddressDeltaKey(int addressType, uint160 addressHash, uint256 hash, unsigned int i, int s) {
355  type = addressType;
356  addressBytes = addressHash;
357  asset = "";
358  txhash = hash;
359  index = i;
360  spending = s;
361  }
362 
363  CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string assetName) {
364  type = addressType;
365  addressBytes = addressHash;
366  asset = assetName;
367  txhash.SetNull();
368  index = 0;
369  spending = 0;
370  }
371 
372  CMempoolAddressDeltaKey(int addressType, uint160 addressHash) {
373  type = addressType;
374  addressBytes = addressHash;
375  asset = "";
376  txhash.SetNull();
377  index = 0;
378  spending = 0;
379  }
380 };
381 
383 {
385  if (a.type == b.type) {
386  if (a.addressBytes == b.addressBytes) {
387  if (a.asset == b.asset) {
388  if (a.txhash == b.txhash) {
389  if (a.index == b.index) {
390  return a.spending < b.spending;
391  } else {
392  return a.index < b.index;
393  }
394  } else {
395  return a.txhash < b.txhash;
396  }
397  } else {
398  return a.asset < b.asset;
399  }
400  } else {
401  return a.addressBytes < b.addressBytes;
402  }
403  } else {
404  return a.type < b.type;
405  }
406  }
407 };
408 
409 #endif // RAVEN_ADDRESSINDEX_H
void Unserialize(Stream &s)
Definition: addressindex.h:133
void Unserialize(Stream &s)
Definition: addressindex.h:34
void SetNull()
Definition: uint256.h:41
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:91
#define READWRITE(obj)
Definition: serialize.h:163
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, uint256 txid, size_t indexValue)
Definition: addressindex.h:42
unsigned int type
Definition: addressindex.h:107
void SerializationOp(Stream &s, Operation ser_action)
Definition: addressindex.h:79
void ser_writedata32(Stream &s, uint32_t obj)
Definition: serialize.h:76
void Serialize(Stream &s) const
Definition: uint256.h:96
CMempoolAddressDeltaKey(int addressType, uint160 addressHash, uint256 hash, unsigned int i, int s)
Definition: addressindex.h:354
void Serialize(Stream &s) const
Definition: addressindex.h:273
void Serialize(Stream &s) const
Definition: addressindex.h:228
bool IsNull() const
Definition: addressindex.h:101
CAddressIndexKey(unsigned int addressType, uint160 addressHash, std::string assetName, int height, int blockindex, uint256 txid, size_t indexValue, bool isSpending)
Definition: addressindex.h:157
CMempoolAddressDelta(int64_t t, CAmount a)
Definition: addressindex.h:327
CMempoolAddressDelta(int64_t t, CAmount a, uint256 hash, unsigned int out)
Definition: addressindex.h:320
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
CAddressIndexIteratorAssetKey(unsigned int addressType, uint160 addressHash, std::string assetName)
Definition: addressindex.h:246
void Unserialize(Stream &s)
Definition: uint256.h:102
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, int height)
Definition: addressindex.h:287
uint32_t ser_readdata32(Stream &s)
Definition: serialize.h:103
unsigned int type
Definition: addressindex.h:16
CAddressUnspentValue(CAmount sats, CScript scriptPubKey, int height)
Definition: addressindex.h:85
CMempoolAddressDeltaKey(int addressType, uint160 addressHash)
Definition: addressindex.h:372
void Serialize(Stream &s) const
Definition: addressindex.h:26
CAddressIndexIteratorKey(unsigned int addressType, uint160 addressHash)
Definition: addressindex.h:204
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:81
void Serialize(Stream &s) const
Definition: addressindex.h:120
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:37
void Unserialize(Stream &s)
Definition: addressindex.h:199
256-bit opaque blob.
Definition: uint256.h:123
size_t GetSerializeSize() const
Definition: addressindex.h:22
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:109
160-bit opaque blob.
Definition: uint256.h:112
unsigned int txindex
Definition: addressindex.h:111
CAddressIndexIteratorHeightKey(unsigned int addressType, uint160 addressHash, std::string assetName, int height)
Definition: addressindex.h:294
size_t GetSerializeSize() const
Definition: addressindex.h:116
CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string assetName, uint256 hash, unsigned int i, int s)
Definition: addressindex.h:344
std::string asset
Definition: addressindex.h:109
unsigned int prevout
Definition: addressindex.h:318
CMempoolAddressDeltaKey(int addressType, uint160 addressHash, std::string assetName)
Definition: addressindex.h:363
std::string asset
Definition: addressindex.h:18
CAddressIndexKey(unsigned int addressType, uint160 addressHash, int height, int blockindex, uint256 txid, size_t indexValue, bool isSpending)
Definition: addressindex.h:145
size_t GetSerializeSize() const
Definition: addressindex.h:190
void clear()
Definition: script.h:689
CAddressIndexIteratorAssetKey(unsigned int addressType, uint160 addressHash)
Definition: addressindex.h:240
CAddressUnspentKey(unsigned int addressType, uint160 addressHash, std::string assetName, uint256 txid, size_t indexValue)
Definition: addressindex.h:50
bool operator()(const CMempoolAddressDeltaKey &a, const CMempoolAddressDeltaKey &b) const
Definition: addressindex.h:384
void ser_writedata8(Stream &s, uint8_t obj)
Definition: serialize.h:67
void Serialize(Stream &s) const
Definition: addressindex.h:194