20 #include <ripple/basics/Log.h>
21 #include <ripple/basics/Slice.h>
22 #include <ripple/basics/contract.h>
23 #include <ripple/basics/safe_cast.h>
24 #include <ripple/beast/core/LexicalCast.h>
25 #include <ripple/protocol/HashPrefix.h>
26 #include <ripple/protocol/digest.h>
27 #include <ripple/shamap/SHAMapTreeNode.h>
30 #include <openssl/sha.h>
41 auto p = std::make_shared<SHAMapInnerNode>(seq);
47 for (
int i = 0; i < 16; ++i)
64 assert(item->peekData().size() >= 12);
75 assert(item->peekData().size() >= 12);
94 int type = rawNode[rawNode.
size() - 1];
97 if ((type < 0) || (type > 6))
102 auto item = std::make_shared<SHAMapItem const>(
107 return std::make_shared<SHAMapTreeNode>(
109 return std::make_shared<SHAMapTreeNode>(
116 Throw<std::runtime_error>(
"short AS node");
123 Throw<std::runtime_error>(
"invalid AS node");
125 auto item = std::make_shared<SHAMapItem const>(u, s.
peekData());
127 return std::make_shared<SHAMapTreeNode>(
135 Throw<std::runtime_error>(
"invalid FI node");
137 auto ret = std::make_shared<SHAMapInnerNode>(seq);
138 for (
int i = 0; i < 16; ++i)
142 if (ret->mHashes[i].isNonZero())
143 ret->mIsBranch |= (1 << i);
153 auto ret = std::make_shared<SHAMapInnerNode>(seq);
155 for (
int i = 0; i < (len / 33); ++i)
158 if (!s.
get8(pos, 32 + (i * 33)))
159 Throw<std::runtime_error>(
"short CI node");
160 if ((pos < 0) || (pos >= 16))
161 Throw<std::runtime_error>(
"invalid CI node");
163 if (ret->mHashes[pos].isNonZero())
164 ret->mIsBranch |= (1 << pos);
176 Throw<std::runtime_error>(
"short TM node");
183 Throw<std::runtime_error>(
"invalid TM node");
185 auto item = std::make_shared<SHAMapItem const>(u, s.
peekData());
187 return std::make_shared<SHAMapTreeNode>(
189 return std::make_shared<SHAMapTreeNode>(
196 if (rawNode.
size() < 4)
198 JLOG(j.
info()) <<
"size < 4";
199 Throw<std::runtime_error>(
"invalid P node");
204 prefix |= rawNode[1];
206 prefix |= rawNode[2];
208 prefix |= rawNode[3];
213 auto item = std::make_shared<SHAMapItem const>(
216 return std::make_shared<SHAMapTreeNode>(
218 return std::make_shared<SHAMapTreeNode>(
224 Throw<std::runtime_error>(
"short PLN node");
232 JLOG(j.
info()) <<
"invalid PLN node";
233 Throw<std::runtime_error>(
"invalid PLN node");
236 auto item = std::make_shared<SHAMapItem const>(u, s.
peekData());
238 return std::make_shared<SHAMapTreeNode>(
247 Throw<std::runtime_error>(
"invalid PIN node");
249 auto ret = std::make_shared<SHAMapInnerNode>(seq);
251 for (
int i = 0; i < 16; ++i)
255 if (ret->mHashes[i].isNonZero())
256 ret->mIsBranch |= (1 << i);
269 Throw<std::runtime_error>(
"short TXN node");
274 auto item = std::make_shared<SHAMapItem const>(txID, s.
peekData());
276 return std::make_shared<SHAMapTreeNode>(
278 return std::make_shared<SHAMapTreeNode>(
283 JLOG(j.
info()) <<
"Unknown node prefix " <<
std::hex << prefix
285 Throw<std::runtime_error>(
"invalid node prefix");
289 Throw<std::runtime_error>(
"Unknown format");
315 for (
auto pos = 0; pos < 16; ++pos)
358 Throw<std::runtime_error>(
"invalid I node type");
380 for (
int i = 0; i <
mHashes.size(); ++i)
408 Throw<std::runtime_error>(
"invalid I node type");
483 for (
int i = 0; i < 16; ++i)
494 ret += beast::lexicalCastThrow<std::string>(
id.getDepth());
505 for (
int i = 0; i <
mHashes.size(); ++i)
510 ret += beast::lexicalCastThrow<std::string>(i);
536 ret += beast::lexicalCast<std::string>(
mItem->size());
546 assert((m >= 0) && (m < 16));
549 assert(child.get() !=
this);
565 assert((m >= 0) && (m < 16));
569 assert(child.get() !=
this);
577 assert(branch >= 0 && branch < 16);
587 assert(branch >= 0 && branch < 16);
599 assert(branch >= 0 && branch < 16);
602 assert(node->getNodeHash() ==
mHashes[branch]);
621 Throw<std::logic_error>(
"SHAMapInnerNode::key() should never be called");
637 for (
int i = 0; i < 16; ++i)
664 assert(
mItem !=
nullptr);