Simplify SHAMapNodeID:

The existing SHAMapNodeID object has both a valid and an invalid state
and requirs callers to verify the state of an instance prior to using
it. A simple set of changes removes that restriction and ensures that
all instances are valid, making the code more robust.

This change also:

1. Introduces a new function to construct a SHAMapNodeID from a
   serialized blob; and
2. Reduces the amount of constructors the class exposes.
This commit is contained in:
Nik Bougalis
2020-09-21 21:33:27 -07:00
parent 57ffc58613
commit ab77444fa3
12 changed files with 245 additions and 266 deletions

View File

@@ -491,12 +491,7 @@ SHAMapInnerNode::getBranchCount() const
std::string
SHAMapAbstractNode::getString(const SHAMapNodeID& id) const
{
std::string ret = "NodeID(";
ret += beast::lexicalCastThrow<std::string>(id.getDepth());
ret += ",";
ret += to_string(id.getNodeID());
ret += ")";
return ret;
return to_string(id);
}
std::string
@@ -507,8 +502,8 @@ SHAMapInnerNode::getString(const SHAMapNodeID& id) const
{
if (!isEmptyBranch(i))
{
ret += "\nb";
ret += beast::lexicalCastThrow<std::string>(i);
ret += "\n";
ret += std::to_string(i);
ret += " = ";
ret += to_string(mHashes[i]);
}