rippled
Loading...
Searching...
No Matches
SHAMapTreeNode.h
1#pragma once
2
3#include <xrpl/basics/IntrusivePointer.h>
4#include <xrpl/basics/IntrusiveRefCounts.h>
5#include <xrpl/basics/SHAMapHash.h>
6#include <xrpl/protocol/Serializer.h>
7#include <xrpl/shamap/SHAMapItem.h>
8#include <xrpl/shamap/SHAMapNodeID.h>
9
10#include <cstdint>
11#include <string>
12
13namespace xrpl {
14
15// These are wire-protocol identifiers used during serialization to encode the
16// type of a node. They should not be arbitrarily be changed.
17static constexpr unsigned char const wireTypeTransaction = 0;
18static constexpr unsigned char const wireTypeAccountState = 1;
19static constexpr unsigned char const wireTypeInner = 2;
20static constexpr unsigned char const wireTypeCompressedInner = 3;
21static constexpr unsigned char const wireTypeTransactionWithMeta = 4;
22
23enum class SHAMapNodeType {
24 tnINNER = 1,
25 tnTRANSACTION_NM = 2, // transaction, no metadata
26 tnTRANSACTION_MD = 3, // transaction, with metadata
28};
29
31{
32protected:
34
42
43protected:
46 operator=(SHAMapTreeNode const&) = delete;
47
55 {
56 }
57
58 explicit SHAMapTreeNode(std::uint32_t cowid, SHAMapHash const& hash) noexcept
59 : hash_(hash), cowid_(cowid)
60 {
61 }
64public:
65 virtual ~SHAMapTreeNode() noexcept = default;
66
67 // Needed to support weak intrusive pointers
68 virtual void
70
95 cowid() const
96 {
97 return cowid_;
98 }
99
105 void
107 {
108 cowid_ = 0;
109 }
110
117 virtual void
119
121 SHAMapHash const&
122 getHash() const
123 {
124 return hash_;
125 }
126
128 virtual SHAMapNodeType
129 getType() const = 0;
130
132 virtual bool
133 isLeaf() const = 0;
134
136 virtual bool
137 isInner() const = 0;
138
140 virtual void
142
144 virtual void
146
147 virtual std::string
148 getString(SHAMapNodeID const&) const;
149
150 virtual void
151 invariants(bool is_root = false) const = 0;
152
154 makeFromPrefix(Slice rawNode, SHAMapHash const& hash);
155
157 makeFromWire(Slice rawNode);
158
159private:
161 makeTransaction(Slice data, SHAMapHash const& hash, bool hashValid);
162
164 makeAccountState(Slice data, SHAMapHash const& hash, bool hashValid);
165
167 makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool hashValid);
168};
169
170} // namespace xrpl
Identifies a node inside a SHAMap.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeAccountState(Slice data, SHAMapHash const &hash, bool hashValid)
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFromPrefix(Slice rawNode, SHAMapHash const &hash)
SHAMapHash const & getHash() const
Return the hash of this node.
virtual void serializeWithPrefix(Serializer &) const =0
Serialize the node in a format appropriate for hashing.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeTransactionWithMeta(Slice data, SHAMapHash const &hash, bool hashValid)
std::uint32_t cowid_
Determines the owning SHAMap, if any.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFromWire(Slice rawNode)
virtual void serializeForWire(Serializer &) const =0
Serialize the node in a format appropriate for sending over the wire.
virtual SHAMapNodeType getType() const =0
Determines the type of node.
SHAMapTreeNode(SHAMapTreeNode const &)=delete
virtual void partialDestructor()
virtual bool isLeaf() const =0
Determines if this is a leaf node.
virtual bool isInner() const =0
Determines if this is an inner node.
virtual void invariants(bool is_root=false) const =0
SHAMapTreeNode(std::uint32_t cowid) noexcept
Construct a node.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeTransaction(Slice data, SHAMapHash const &hash, bool hashValid)
SHAMapTreeNode & operator=(SHAMapTreeNode const &)=delete
SHAMapTreeNode(std::uint32_t cowid, SHAMapHash const &hash) noexcept
virtual ~SHAMapTreeNode() noexcept=default
virtual std::string getString(SHAMapNodeID const &) const
virtual void updateHash()=0
Recalculate the hash of this node.
A shared intrusive pointer class that supports weak pointers.
An immutable linear range of bytes.
Definition Slice.h:26
virtual intr_ptr::SharedPtr< SHAMapTreeNode > clone(std::uint32_t cowid) const =0
Make a copy of this node, setting the owner.
void unshare()
If this node is shared with another map, mark it as no longer shared.
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:5
static constexpr unsigned char const wireTypeAccountState
static constexpr unsigned char const wireTypeInner
static constexpr unsigned char const wireTypeCompressedInner
static constexpr unsigned char const wireTypeTransactionWithMeta
static constexpr unsigned char const wireTypeTransaction
Implement the strong count, weak count, and bit flags for an intrusive pointer.