22 #if !defined(ETH_EMSCRIPTEN) 40 #define ENABLE_DEBUG_PRINT 0 42 #if ENABLE_DEBUG_PRINT 43 bool g_hashDebug =
false;
46 void hash256aux(
HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end,
unsigned _preLen,
RLPStream& _rlp);
50 #if ENABLE_DEBUG_PRINT 51 static std::string s_indent;
58 else if (std::next(_begin) == _end)
62 #if ENABLE_DEBUG_PRINT 64 std::cerr << s_indent <<
toHex(
bytesConstRef(_begin->first.data() + _preLen, _begin->first.size() - _preLen), 1) <<
": " << _begin->second <<
" = " <<
sha3(_rlp.
out()) << std::endl;
71 unsigned sharedPre = (unsigned)-1;
73 for (
auto i = std::next(_begin); i != _end && sharedPre; ++i, ++
c)
75 unsigned x =
std::min(sharedPre,
std::min((
unsigned)_begin->first.size(), (unsigned)i->first.size()));
76 unsigned shared = _preLen;
77 for (; shared < x && _begin->first[shared] == i->first[shared]; ++shared) {}
78 sharedPre =
std::min(shared, sharedPre);
80 if (sharedPre > _preLen)
83 #if ENABLE_DEBUG_PRINT 85 std::cerr << s_indent <<
toHex(
bytesConstRef(_begin->first.data() + _preLen, sharedPre), 1) <<
": " << std::endl;
88 hash256aux(_s, _begin, _end, (
unsigned)sharedPre, _rlp);
89 #if ENABLE_DEBUG_PRINT 91 std::cerr << s_indent <<
"= " << hex <<
sha3(_rlp.
out()) << dec << std::endl;
99 if (_preLen ==
b->first.size())
101 #if ENABLE_DEBUG_PRINT 103 std::cerr << s_indent <<
"@: " <<
b->second << std::endl;
107 for (
auto i = 0; i < 16; ++i)
110 for (; n != _end && n->first[_preLen] == i; ++n) {}
115 #if ENABLE_DEBUG_PRINT 117 std::cerr << s_indent << std::hex << i <<
": " << std::dec << std::endl;
123 if (_preLen == _begin->first.size())
124 _rlp << _begin->second;
130 std::cerr << s_indent <<
"= " << hex <<
sha3(_rlp.
out()) << dec << std::endl;
134 #if ENABLE_DEBUG_PRINT 136 s_indent.resize(s_indent.size() - 2);
144 if (rlp.
out().size() < 32)
147 #if ENABLE_DEBUG_PRINT 148 cerr <<
"[INLINE: " << dec << rlp.
out().size() <<
" < 32]" << endl;
150 _rlp.APPEND_CHILD(rlp.
out());
154 #if ENABLE_DEBUG_PRINT 155 cerr <<
"[HASH: " << dec << rlp.
out().size() <<
" >= 32]" << endl;
167 for (
auto i = _s.rbegin(); i != _s.rend(); ++i)
170 hash256rlp(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
193 m[
rlp(j++)] = i.toBytes();
199 #endif // ETH_EMSCRIPTEN 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)
std::map< bytes, bytes > BytesMap
h256 orderedTrieRoot(std::vector< bytesConstRef > const &_data)
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
std::string hexPrefixEncode(bytes const &_hexVector, bool _leaf, int _begin, int _end)
bytes const & out() const
Read the byte stream.
std::hash for asio::adress
if(a.IndicesBefore(b, len, lenIndices))
#define ENABLE_DEBUG_PRINT
void hash256rlp(HexMap const &_s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream &_rlp)
h256 hash256(BytesMap const &_s)
std::vector< byte > bytes
vector_ref< byte const > bytesConstRef
RLPStream & appendList(size_t _items)
Appends a list.
bytes asNibbles(bytesConstRef const &_s)
std::map< bytes, bytes > HexMap
bytes rlp256(BytesMap const &_s)
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Class for writing to an RLP bytestream.
void hash256aux(HexMap const &_s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream &_rlp)