1#include <xrpld/app/ledger/LedgerNodeHelpers.h>
3#include <xrpl/basics/Slice.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/shamap/SHAMap.h>
6#include <xrpl/shamap/SHAMapLeafNode.h>
7#include <xrpl/shamap/SHAMapNodeID.h>
8#include <xrpl/shamap/SHAMapTreeNode.h>
35 if (ledgerNode.has_id() || ledgerNode.has_depth())
38 if (ledgerNode.has_nodeid())
43 if (!ledgerNode.has_id())
46 REACHABLE(
"xrpl::getSHAMapNodeID : inner node ID from id field");
54 "xrpl::getSHAMapNodeID : leaf depth exceeds max");
58 auto const key =
leafKey(treeNode);
59 REACHABLE(
"xrpl::getSHAMapNodeID : leaf node ID reconstructed from depth");
63 UNREACHABLE(
"xrpl::getSHAMapNodeID : tree node is neither inner nor leaf");
68 if (!ledgerNode.has_nodeid())
72 if (!nodeID.has_value())
77 auto const key =
leafKey(treeNode);
80 nodeID->getNodeID() != expectedID.getNodeID(),
81 "xrpl::getSHAMapNodeID : legacy leaf ID inconsistent with key");
82 if (nodeID->getNodeID() != expectedID.getNodeID())
static SHAMapNodeID createID(int depth, uint256 const &key)
Create a SHAMapNodeID of a node with the depth of the node and the key of a leaf.
static SHAMapTreeNodePtr makeFromWire(Slice rawNode)
virtual bool isLeaf() const =0
Determines if this is a leaf node.
virtual bool isInner() const =0
Determines if this is an inner node.
static constexpr unsigned int kLeafDepth
The depth of the hash map: data is only present in the leaves.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
intr_ptr::SharedPtr< SHAMapTreeNode > SHAMapTreeNodePtr
uint256 const & leafKey(SHAMapTreeNode const &node)
Return the key of the item held by a SHAMap leaf node.
std::optional< SHAMapNodeID > getSHAMapNodeID(protocol::TMLedgerNode const &ledgerNode, SHAMapTreeNode const &treeNode)
Extracts or reconstructs the SHAMapNodeID from a ledger node proto message.
SHAMapTreeNodePtr getTreeNode(std::string_view data)
Deserializes a SHAMapTreeNode from wire format data.
Slice makeSlice(std::array< T, N > const &a)
std::optional< SHAMapNodeID > deserializeSHAMapNodeID(void const *data, std::size_t size)
Return an object representing a serialized SHAMap Node ID.