mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add 'SHAMap::getPath' function to get a verifiable path through a SHAMap.
This commit is contained in:
@@ -814,6 +814,38 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& nodeID)
|
||||
return node;
|
||||
}
|
||||
|
||||
bool SHAMap::getPath(const uint256& index, std::vector< std::vector<unsigned char> >& nodes, SHANodeFormat format)
|
||||
{
|
||||
// Return the path of nodes to the specified index in the specified format
|
||||
// Return value: true = node present, false = node not present
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode* inNode = root.get();
|
||||
|
||||
while (!inNode->isLeaf())
|
||||
{
|
||||
Serializer s;
|
||||
inNode->addRaw(s, format);
|
||||
nodes.push_back(s.peekData());
|
||||
|
||||
int branch = inNode->selectBranch(index);
|
||||
if (inNode->isEmptyBranch(branch)) // paths leads to empty branch
|
||||
return false;
|
||||
inNode = getNodePointer(inNode->getChildNodeID(branch), inNode->getChildHash(branch));
|
||||
if (!inNode)
|
||||
throw SHAMapMissingNode(mType, inNode->getChildNodeID(branch), inNode->getChildHash(branch), index);
|
||||
}
|
||||
|
||||
if (inNode->getTag() != index) // path leads to different leaf
|
||||
return false;
|
||||
|
||||
// path lead to the requested leaf
|
||||
Serializer s;
|
||||
inNode->addRaw(s, format);
|
||||
nodes.push_back(s.peekData());
|
||||
return true;
|
||||
}
|
||||
|
||||
void SHAMap::dump(bool hash)
|
||||
{
|
||||
#if 0
|
||||
|
||||
Reference in New Issue
Block a user