xrpld
Loading...
Searching...
No Matches
InnerNode.h
1#pragma once
2
3#include <xrpl/basics/SHAMapHash.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/protocol/Serializer.h>
8#include <xrpl/shamap/SHAMapInnerNode.h>
9#include <xrpl/shamap/SHAMapTreeNode.h>
10
11#include <array>
12#include <cstdint>
13#include <stdexcept>
14#include <vector>
15
16namespace xrpl::tests {
17
22{
23 unsigned int branch{};
25};
26
41[[nodiscard]] inline SHAMapTreeNodePtr
43{
44 // The full form carries a slot for every branch, so a child's position comes from the slot it
45 // is written to.
47
48 // A duplicate branch is refused here, and one past the last to match the compressed parser.
49 std::uint32_t seen = 0;
50 for (auto const& child : children)
51 {
52 if (child.branch >= SHAMapInnerNode::kBranchFactor)
53 Throw<std::logic_error>("makeFullInnerNode: branch is past the last one");
54
55 auto const bit = 1u << child.branch;
56 if ((seen & bit) != 0)
57 Throw<std::logic_error>("makeFullInnerNode: branch named twice");
58 seen |= bit;
59
60 hashes.at(child.branch) = child.hash.asUInt256();
61 }
62
63 Serializer s;
64 for (auto const& hash : hashes)
65 s.addBitString(hash);
67
69}
70
86[[nodiscard]] inline SHAMapTreeNodePtr
88{
89 Serializer s;
90 for (auto const& child : children)
91 {
92 s.addBitString(child.hash.asUInt256());
93 s.add8(static_cast<unsigned char>(child.branch));
94 }
96
98}
99
100} // namespace xrpl::tests
T at(T... args)
static constexpr unsigned int kBranchFactor
Each inner node has 16 children (the 'radix tree' part of the map).
static SHAMapTreeNodePtr makeFromWire(Slice rawNode)
Blob const & peekData() const
Definition Serializer.h:273
int addBitString(BaseUInt< Bits, Tag > const &v)
Definition Serializer.h:202
int add8(unsigned char byteValue)
SHAMapTreeNodePtr makeCompressedInnerNode(std::vector< InnerChild > const &children)
Assemble an inner node in the wire format's compressed form.
Definition InnerNode.h:87
SHAMapTreeNodePtr makeFullInnerNode(std::vector< InnerChild > const &children)
Assemble an inner node in the wire format's full form.
Definition InnerNode.h:42
intr_ptr::SharedPtr< SHAMapTreeNode > SHAMapTreeNodePtr
static constexpr unsigned char const kWireTypeCompressedInner
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
static constexpr unsigned char const kWireTypeInner
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
One child of an inner node a test assembles by hand.
Definition InnerNode.h:22
unsigned int branch
Definition InnerNode.h:23