34 BlockHeader::BlockHeader()
41 m_hash = _hashWith ? _hashWith :
sha3(header.
data());
45 void BlockHeader::clear()
47 m_parentHash =
h256();
77 void BlockHeader::streamRLPFields(
RLPStream& _s)
const 79 _s << m_parentHash << m_sha3Uncles << m_author << m_stateRoot << m_transactionsRoot << m_receiptsRoot << m_logBloom
80 << m_difficulty << m_number << m_gasLimit << m_gasUsed << m_timestamp << m_extraData;
88 BlockHeader::streamRLPFields(_s);
91 for (
unsigned i = 0; i < m_seal.size(); ++i)
105 RLP header = root[0];
108 if (!root[1].isList())
110 if (!root[2].isList())
115 void BlockHeader::populate(
RLP const& _header)
120 m_parentHash = _header[field = 0].
toHash<
h256>(RLP::VeryStrict);
121 m_sha3Uncles = _header[field = 1].
toHash<
h256>(RLP::VeryStrict);
122 m_author = _header[field = 2].
toHash<
Address>(RLP::VeryStrict);
123 m_stateRoot = _header[field = 3].
toHash<
h256>(RLP::VeryStrict);
124 m_transactionsRoot = _header[field = 4].
toHash<
h256>(RLP::VeryStrict);
125 m_receiptsRoot = _header[field = 5].
toHash<
h256>(RLP::VeryStrict);
126 m_logBloom = _header[field = 6].
toHash<
LogBloom>(RLP::VeryStrict);
127 m_difficulty = _header[field = 7].
toInt<
u256>();
128 m_number = _header[field = 8].
toInt<
u256>();
129 m_gasLimit = _header[field = 9].
toInt<
u256>();
130 m_gasUsed = _header[field = 10].
toInt<
u256>();
131 m_timestamp = _header[field = 11].
toInt<
u256>();
132 m_extraData = _header[field = 12].
toBytes();
134 for (
unsigned i = 13; i < _header.
itemCount(); ++i)
150 m_parentHash = _parent.
m_hash;
158 if (m_number > ~(
unsigned)0)
159 BOOST_THROW_EXCEPTION(InvalidNumber());
166 if (m_parentHash && _parent.
hash() != m_parentHash)
167 BOOST_THROW_EXCEPTION(InvalidParentHash());
170 BOOST_THROW_EXCEPTION(InvalidTimestamp());
172 if (m_number != _parent.
m_number + 1)
173 BOOST_THROW_EXCEPTION(InvalidNumber());
180 auto txList = root[1];
181 auto expectedRoot =
trieRootOver(txList.itemCount(), [&](
unsigned i){
return rlp(i); }, [&](
unsigned i){
return txList[i].data().toBytes(); });
184 if (m_transactionsRoot != expectedRoot)
188 transactionsTrie.
init();
190 vector<bytesConstRef> txs;
192 for (
unsigned i = 0; i < txList.itemCount(); ++i)
197 transactionsTrie.
insert(&k.
out(), txList[i].data());
199 txs.push_back(txList[i].
data());
202 cdebug <<
"trieRootOver" << expectedRoot;
204 cdebug <<
"TrieDB" << transactionsTrie.
root();
206 for (
auto const& t: txs)
212 if (m_sha3Uncles !=
sha3(root[2].
data()))
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
boost::tuple< errinfo_required_h256, errinfo_got_h256 > Hash256RequirementError
boost::error_info< struct tag_field, std::string > errinfo_name
bool isList() const
List value.
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
bytesConstRef data() const
The bare data of the RLP.
Merkle Patricia Tree "Trie": a modifed base-16 Radix tree.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
bytes const & out() const
Read the byte stream.
bool verify(Public const &_k, Signature const &_s, h256 const &_hash)
Verify signature.
h160 Address
An Ethereum address: 20 bytes.
std::hash for asio::adress
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
_N toHash(int _flags=Strict) const
Base class for all exceptions.
h256 const & root() const
std::vector< unsigned char > toBytes() const
RLPStream & appendList(size_t _items)
Appends a list.
ANONYMOUS_NAMESPACE_BEGIN const CryptoPP::GF2_32 field
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
boost::tuple< errinfo_field, errinfo_data > BadFieldError
boost::error_info< struct tag_comment, std::string > errinfo_comment
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
h256 trieRootOver(unsigned _itemCount, T const &_getKey, U const &_getValue)
The default logging channels.
h2048 LogBloom
The log bloom's size (2048-bit).
h256 orderedTrieRoot(std::vector< bytes > const &_data)
void insert(bytes const &_key, bytes const &_value)
boost::tuple< errinfo_required, errinfo_got > RequirementError
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Class for writing to an RLP bytestream.
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
Class for interpreting Recursive Linear-Prefix Data.
std::string toString() const
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.