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(
mItem->peekData().size() >= 12);
75 assert(
mItem->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>(
129 return std::make_shared<SHAMapTreeNode>(
136 Throw<std::runtime_error>(
"invalid FI node");
138 auto ret = std::make_shared<SHAMapInnerNode>(seq);
139 for (
int i = 0; i < 16; ++i)
143 if (ret->mHashes[i].isNonZero())
144 ret->mIsBranch |= (1 << i);
154 auto ret = std::make_shared<SHAMapInnerNode>(seq);
156 for (
int i = 0; i < (len / 33); ++i)
159 if (!s.
get8(pos, 32 + (i * 33)))
160 Throw<std::runtime_error>(
"short CI node");
161 if ((pos < 0) || (pos >= 16))
162 Throw<std::runtime_error>(
"invalid CI node");
164 if (ret->mHashes[pos].isNonZero())
165 ret->mIsBranch |= (1 << pos);
177 Throw<std::runtime_error>(
"short TM node");
184 Throw<std::runtime_error>(
"invalid TM node");
186 auto item = std::make_shared<SHAMapItem const>(u, s.
peekData());
188 return std::make_shared<SHAMapTreeNode>(
190 return std::make_shared<SHAMapTreeNode>(
197 if (rawNode.
size() < 4)
199 JLOG(j.
info()) <<
"size < 4";
200 Throw<std::runtime_error>(
"invalid P node");
205 prefix |= rawNode[1];
207 prefix |= rawNode[2];
209 prefix |= rawNode[3];
214 auto item = std::make_shared<SHAMapItem const>(
217 return std::make_shared<SHAMapTreeNode>(
219 return std::make_shared<SHAMapTreeNode>(
225 Throw<std::runtime_error>(
"short PLN node");
233 JLOG(j.
info()) <<
"invalid PLN node";
234 Throw<std::runtime_error>(
"invalid PLN node");
237 auto item = std::make_shared<SHAMapItem const>(u, s.
peekData());
239 return std::make_shared<SHAMapTreeNode>(
241 return std::make_shared<SHAMapTreeNode>(
249 Throw<std::runtime_error>(
"invalid PIN node");
251 auto ret = std::make_shared<SHAMapInnerNode>(seq);
253 for (
int i = 0; i < 16; ++i)
257 if (ret->mHashes[i].isNonZero())
258 ret->mIsBranch |= (1 << i);
271 Throw<std::runtime_error>(
"short TXN node");
276 auto item = std::make_shared<SHAMapItem const>(txID, s.
peekData());
278 return std::make_shared<SHAMapTreeNode>(
280 return std::make_shared<SHAMapTreeNode>(
285 JLOG(j.
info()) <<
"Unknown node prefix " <<
std::hex << prefix
287 Throw<std::runtime_error>(
"invalid node prefix");
291 Throw<std::runtime_error>(
"Unknown format");
317 for (
auto pos = 0; pos < 16; ++pos)
360 Throw<std::runtime_error>(
"invalid I node type");
382 for (
int i = 0; i <
mHashes.size(); ++i)
410 Throw<std::runtime_error>(
"invalid I node type");
467 mItem = std::move(i);
485 for (
int i = 0; i < 16; ++i)
496 ret += beast::lexicalCastThrow<std::string>(
id.getDepth());
507 for (
int i = 0; i <
mHashes.size(); ++i)
512 ret += beast::lexicalCastThrow<std::string>(i);
538 ret += beast::lexicalCast<std::string>(
mItem->size());
548 assert((m >= 0) && (m < 16));
551 assert(child.get() !=
this);
567 assert((m >= 0) && (m < 16));
571 assert(child.get() !=
this);
579 assert(branch >= 0 && branch < 16);
589 assert(branch >= 0 && branch < 16);
601 assert(branch >= 0 && branch < 16);
604 assert(node->getNodeHash() ==
mHashes[branch]);
623 Throw<std::logic_error>(
"SHAMapInnerNode::key() should never be called");
639 for (
int i = 0; i < 16; ++i)
666 assert(
mItem !=
nullptr);