Ejemplo n.º 1
0
void MemTrie::insert(std::string const& _key, std::string const& _value)
{
	if (_value.empty())
		remove(_key);
	auto h = asNibbles(_key);
	m_root = m_root ? m_root->insert(&h, _value) : new TrieLeafNode(bytesConstRef(&h), _value);
}
Ejemplo n.º 2
0
std::string const& MemTrie::at(std::string const& _key) const
{
	if (!m_root)
		return c_nullString;
	auto h = asNibbles(_key);
	return m_root->at(bytesConstRef(&h));
}
Ejemplo n.º 3
0
void MemTrie::remove(std::string const& _key)
{
	if (m_root)
	{
		auto h = asNibbles(_key);
		m_root = m_root->remove(&h);
	}
}
Ejemplo n.º 4
0
h256 hash256(u256Map const& _s)
{
	// build patricia tree.
	if (_s.empty())
		return h256();
	HexMap hexMap;
	for (auto i = _s.rbegin(); i != _s.rend(); ++i)
		hexMap[asNibbles(toBigEndianString(i->first))] = asString(rlp(i->second));
	RLPStream s;
	hash256rlp(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
	return sha3(s.out());
}
Ejemplo n.º 5
0
bytes rlp256(StringMap const& _s)
{
	// build patricia tree.
	if (_s.empty())
		return bytes();
	HexMap hexMap;
	for (auto i = _s.rbegin(); i != _s.rend(); ++i)
		hexMap[asNibbles(i->first)] = i->second;
	RLPStream s;
	hash256aux(hexMap, hexMap.cbegin(), hexMap.cend(), 0, s);
	return s.out();
}