MCPcopy Create free account
hub / github.com/LUX-Core/lux / hash256rlp

Function hash256rlp

src/cpp-ethereum/libdevcore/TrieHash.cpp:48–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46void hash256aux(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp);
47
48void hash256rlp(HexMap const& _s, HexMap::const_iterator _begin, HexMap::const_iterator _end, unsigned _preLen, RLPStream& _rlp)
49{
50#if ENABLE_DEBUG_PRINT
51 static std::string s_indent;
52 if (_preLen)
53 s_indent += " ";
54#endif
55
56 if (_begin == _end)
57 _rlp << ""; // NULL
58 else if (std::next(_begin) == _end)
59 {
60 // only one left - terminate with the pair.
61 _rlp.appendList(2) << hexPrefixEncode(_begin->first, true, _preLen) << _begin->second;
62#if ENABLE_DEBUG_PRINT
63 if (g_hashDebug)
64 std::cerr << s_indent << toHex(bytesConstRef(_begin->first.data() + _preLen, _begin->first.size() - _preLen), 1) << ": " << _begin->second << " = " << sha3(_rlp.out()) << std::endl;
65#endif
66 }
67 else
68 {
69 // find the number of common prefix nibbles shared
70 // i.e. the minimum number of nibbles shared at the beginning between the first hex string and each successive.
71 unsigned sharedPre = (unsigned)-1;
72 unsigned c = 0;
73 for (auto i = std::next(_begin); i != _end && sharedPre; ++i, ++c)
74 {
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);
79 }
80 if (sharedPre > _preLen)
81 {
82 // if they all have the same next nibble, we also want a pair.
83#if ENABLE_DEBUG_PRINT
84 if (g_hashDebug)
85 std::cerr << s_indent << toHex(bytesConstRef(_begin->first.data() + _preLen, sharedPre), 1) << ": " << std::endl;
86#endif
87 _rlp.appendList(2) << hexPrefixEncode(_begin->first, false, _preLen, (int)sharedPre);
88 hash256aux(_s, _begin, _end, (unsigned)sharedPre, _rlp);
89#if ENABLE_DEBUG_PRINT
90 if (g_hashDebug)
91 std::cerr << s_indent << "= " << hex << sha3(_rlp.out()) << dec << std::endl;
92#endif
93 }
94 else
95 {
96 // otherwise enumerate all 16+1 entries.
97 _rlp.appendList(17);
98 auto b = _begin;
99 if (_preLen == b->first.size())
100 {
101#if ENABLE_DEBUG_PRINT
102 if (g_hashDebug)
103 std::cerr << s_indent << "@: " << b->second << std::endl;
104#endif
105 ++b;

Callers 2

hash256auxFunction · 0.85
rlp256Function · 0.85

Calls 7

toHexFunction · 0.85
hash256auxFunction · 0.85
hexPrefixEncodeFunction · 0.70
sha3Function · 0.70
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected