Add 'SHAMap::getPath' function to get a verifiable path through a SHAMap.

This commit is contained in:
JoelKatz
2012-10-18 09:18:46 -07:00
parent b09318f8d3
commit 92409dd3fc
3 changed files with 57 additions and 3 deletions

View File

@@ -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