Fabcoin Core  0.16.2
P2P Digital Currency
BlockDetails.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <unordered_map>
25 #include <libdevcore/Log.h>
26 #include <libdevcore/RLP.h>
27 #include "TransactionReceipt.h"
28 
29 namespace dev
30 {
31 namespace eth
32 {
33 
34 // TODO: OPTIMISE: constructors take bytes, RLP used only in necessary classes.
35 
36 static const unsigned c_bloomIndexSize = 16;
37 static const unsigned c_bloomIndexLevels = 2;
38 
39 static const unsigned InvalidNumber = (unsigned)-1;
40 
42 {
44  BlockDetails(unsigned _n, u256 _tD, h256 _p, h256s _c): number(_n), totalDifficulty(_tD), parent(_p), children(_c) {}
45  BlockDetails(RLP const& _r);
46  bytes rlp() const;
47 
48  bool isNull() const { return number == InvalidNumber; }
49  explicit operator bool() const { return !isNull(); }
50 
51  unsigned number = InvalidNumber;
55 
56  mutable unsigned size;
57 };
58 
60 {
62  BlockLogBlooms(RLP const& _r) { blooms = _r.toVector<LogBloom>(); size = _r.data().size(); }
63  bytes rlp() const { bytes r = dev::rlp(blooms); size = r.size(); return r; }
64 
66  mutable unsigned size;
67 };
68 
70 {
72  BlocksBlooms(RLP const& _r) { blooms = _r.toArray<LogBloom, c_bloomIndexSize>(); size = _r.data().size(); }
73  bytes rlp() const { bytes r = dev::rlp(blooms); size = r.size(); return r; }
74 
75  std::array<LogBloom, c_bloomIndexSize> blooms;
76  mutable unsigned size;
77 };
78 
80 {
82  BlockReceipts(RLP const& _r) { for (auto const& i: _r) receipts.emplace_back(i.data()); size = _r.data().size(); }
83  bytes rlp() const { RLPStream s(receipts.size()); for (TransactionReceipt const& i: receipts) i.streamRLP(s); size = s.out().size(); return s.out(); }
84 
86  mutable unsigned size = 0;
87 };
88 
89 struct BlockHash
90 {
91  BlockHash() {}
92  BlockHash(h256 const& _h): value(_h) {}
93  BlockHash(RLP const& _r) { value = _r.toHash<h256>(); }
94  bytes rlp() const { return dev::rlp(value); }
95 
97  static const unsigned size = 65;
98 };
99 
101 {
103  TransactionAddress(RLP const& _rlp) { blockHash = _rlp[0].toHash<h256>(); index = _rlp[1].toInt<unsigned>(); }
104  bytes rlp() const { RLPStream s(2); s << blockHash << index; return s.out(); }
105 
106  explicit operator bool() const { return !!blockHash; }
107 
109  unsigned index = 0;
110 
111  static const unsigned size = 67;
112 };
113 
114 using BlockDetailsHash = std::unordered_map<h256, BlockDetails>;
115 using BlockLogBloomsHash = std::unordered_map<h256, BlockLogBlooms>;
116 using BlockReceiptsHash = std::unordered_map<h256, BlockReceipts>;
117 using TransactionAddressHash = std::unordered_map<h256, TransactionAddress>;
118 using BlockHashHash = std::unordered_map<uint64_t, BlockHash>;
119 using BlocksBloomsHash = std::unordered_map<h256, BlocksBlooms>;
120 
121 static const BlockDetails NullBlockDetails;
122 static const BlockLogBlooms NullBlockLogBlooms;
123 static const BlockReceipts NullBlockReceipts;
124 static const TransactionAddress NullTransactionAddress;
125 static const BlockHash NullBlockHash;
126 static const BlocksBlooms NullBlocksBlooms;
127 
128 }
129 }
bytes rlp() const
Definition: BlockDetails.h:83
std::unordered_map< h256, BlocksBlooms > BlocksBloomsHash
Definition: BlockDetails.h:119
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::array< T, N > toArray(int _flags=LaissezFaire) const
Definition: RLP.h:259
std::array< LogBloom, c_bloomIndexSize > blooms
Definition: BlockDetails.h:75
bytes rlp() const
Definition: BlockDetails.h:73
BlocksBlooms(RLP const &_r)
Definition: BlockDetails.h:72
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
Definition: RLP.h:467
bytesConstRef data() const
The bare data of the RLP.
Definition: RLP.h:97
std::vector< T > toVector(int _flags=LaissezFaire) const
Definition: RLP.h:204
std::unordered_map< h256, BlockDetails > BlockDetailsHash
Definition: BlockDetails.h:114
bytes const & out() const
Read the byte stream.
Definition: RLP.h:433
TransactionAddress(RLP const &_rlp)
Definition: BlockDetails.h:103
TransactionReceipts receipts
Definition: BlockDetails.h:85
BlockDetails(unsigned _n, u256 _tD, h256 _p, h256s _c)
Definition: BlockDetails.h:44
BlockReceipts(RLP const &_r)
Definition: BlockDetails.h:82
BlockLogBlooms(RLP const &_r)
Definition: BlockDetails.h:62
std::vector< TransactionReceipt > TransactionReceipts
_N toHash(int _flags=Strict) const
Definition: RLP.h:298
std::vector< byte > bytes
Definition: Common.h:75
const u256 Invalid256
Definition: Common.cpp:38
std::unordered_map< uint64_t, BlockHash > BlockHashHash
Definition: BlockDetails.h:118
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
size_t size() const
Definition: vector_ref.h:55
std::unordered_map< h256, BlockLogBlooms > BlockLogBloomsHash
Definition: BlockDetails.h:115
bool isNull() const
Definition: BlockDetails.h:48
std::unordered_map< h256, TransactionAddress > TransactionAddressHash
Definition: BlockDetails.h:117
BlockHash(RLP const &_r)
Definition: BlockDetails.h:93
std::unordered_map< h256, BlockReceipts > BlockReceiptsHash
Definition: BlockDetails.h:116
h2048 LogBloom
The log bloom&#39;s size (2048-bit).
Definition: Common.h:58
std::vector< h256 > h256s
Definition: FixedHash.h:345
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Definition: RLP.h:275
Class for writing to an RLP bytestream.
Definition: RLP.h:383
bytes rlp() const
Definition: BlockDetails.h:94
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64
std::vector< LogBloom > LogBlooms
Many log blooms.
Definition: Common.h:61
BlockHash(h256 const &_h)
Definition: BlockDetails.h:92