rippled
Loading...
Searching...
No Matches
SHAMapTreeNode.h
1#ifndef XRPL_SHAMAP_SHAMAPTREENODE_H_INCLUDED
2#define XRPL_SHAMAP_SHAMAPTREENODE_H_INCLUDED
3
4#include <xrpl/basics/IntrusivePointer.h>
5#include <xrpl/basics/IntrusiveRefCounts.h>
6#include <xrpl/basics/SHAMapHash.h>
7#include <xrpl/protocol/Serializer.h>
8#include <xrpl/shamap/SHAMapItem.h>
9#include <xrpl/shamap/SHAMapNodeID.h>
10
11#include <cstdint>
12#include <string>
13
14namespace ripple {
15
16// These are wire-protocol identifiers used during serialization to encode the
17// type of a node. They should not be arbitrarily be changed.
18static constexpr unsigned char const wireTypeTransaction = 0;
19static constexpr unsigned char const wireTypeAccountState = 1;
20static constexpr unsigned char const wireTypeInner = 2;
21static constexpr unsigned char const wireTypeCompressedInner = 3;
22static constexpr unsigned char const wireTypeTransactionWithMeta = 4;
23
24enum class SHAMapNodeType {
25 tnINNER = 1,
26 tnTRANSACTION_NM = 2, // transaction, no metadata
27 tnTRANSACTION_MD = 3, // transaction, with metadata
29};
30
32{
33protected:
35
43
44protected:
47 operator=(SHAMapTreeNode const&) = delete;
48
56 {
57 }
58
61 SHAMapHash const& hash) noexcept
62 : hash_(hash), cowid_(cowid)
63 {
64 }
67public:
68 virtual ~SHAMapTreeNode() noexcept = default;
69
70 // Needed to support weak intrusive pointers
71 virtual void
73
98 cowid() const
99 {
100 return cowid_;
101 }
102
108 void
110 {
111 cowid_ = 0;
112 }
113
120 virtual void
122
124 SHAMapHash const&
125 getHash() const
126 {
127 return hash_;
128 }
129
131 virtual SHAMapNodeType
132 getType() const = 0;
133
135 virtual bool
136 isLeaf() const = 0;
137
139 virtual bool
140 isInner() const = 0;
141
143 virtual void
145
147 virtual void
149
150 virtual std::string
151 getString(SHAMapNodeID const&) const;
152
153 virtual void
154 invariants(bool is_root = false) const = 0;
155
157 makeFromPrefix(Slice rawNode, SHAMapHash const& hash);
158
160 makeFromWire(Slice rawNode);
161
162private:
164 makeTransaction(Slice data, SHAMapHash const& hash, bool hashValid);
165
167 makeAccountState(Slice data, SHAMapHash const& hash, bool hashValid);
168
170 makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool hashValid);
171};
172
173} // namespace ripple
174
175#endif
Identifies a node inside a SHAMap.
SHAMapTreeNode & operator=(SHAMapTreeNode const &)=delete
static intr_ptr::SharedPtr< SHAMapTreeNode > makeAccountState(Slice data, SHAMapHash const &hash, bool hashValid)
virtual ~SHAMapTreeNode() noexcept=default
virtual std::string getString(SHAMapNodeID const &) const
virtual bool isLeaf() const =0
Determines if this is a leaf node.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeTransaction(Slice data, SHAMapHash const &hash, bool hashValid)
SHAMapTreeNode(SHAMapTreeNode const &)=delete
virtual void partialDestructor()
static intr_ptr::SharedPtr< SHAMapTreeNode > makeTransactionWithMeta(Slice data, SHAMapHash const &hash, bool hashValid)
virtual void updateHash()=0
Recalculate the hash of this node.
SHAMapTreeNode(std::uint32_t cowid) noexcept
Construct a node.
virtual bool isInner() const =0
Determines if this is an inner node.
std::uint32_t cowid_
Determines the owning SHAMap, if any.
virtual void invariants(bool is_root=false) const =0
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
SHAMapTreeNode(std::uint32_t cowid, SHAMapHash const &hash) noexcept
SHAMapHash const & getHash() const
Return the hash of this node.
virtual void serializeForWire(Serializer &) const =0
Serialize the node in a format appropriate for sending over the wire.
virtual void serializeWithPrefix(Serializer &) const =0
Serialize the node in a format appropriate for hashing.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFromWire(Slice rawNode)
virtual SHAMapNodeType getType() const =0
Determines the type of node.
A shared intrusive pointer class that supports weak pointers.
An immutable linear range of bytes.
Definition Slice.h:27
void unshare()
If this node is shared with another map, mark it as no longer shared.
virtual intr_ptr::SharedPtr< SHAMapTreeNode > clone(std::uint32_t cowid) const =0
Make a copy of this node, setting the owner.
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
static constexpr unsigned char const wireTypeAccountState
static constexpr unsigned char const wireTypeCompressedInner
static constexpr unsigned char const wireTypeInner
static constexpr unsigned char const wireTypeTransaction
static constexpr unsigned char const wireTypeTransactionWithMeta
Implement the strong count, weak count, and bit flags for an intrusive pointer.