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 : hash_(hash), cowid_(cowid)
59 {
60 }
63public:
64 virtual ~SHAMapTreeNode() noexcept = default;
65
66 // Needed to support weak intrusive pointers
67 virtual void
69
94 cowid() const
95 {
96 return cowid_;
97 }
98
104 void
106 {
107 cowid_ = 0;
108 }
109
116 virtual void
118
120 SHAMapHash const&
121 getHash() const
122 {
123 return hash_;
124 }
125
127 virtual SHAMapNodeType
128 getType() const = 0;
129
131 virtual bool
132 isLeaf() const = 0;
133
135 virtual bool
136 isInner() const = 0;
137
139 virtual void
141
143 virtual void
145
146 virtual std::string
147 getString(SHAMapNodeID const&) const;
148
149 virtual void
150 invariants(bool is_root = false) const = 0;
151
153 makeFromPrefix(Slice rawNode, SHAMapHash const& hash);
154
156 makeFromWire(Slice rawNode);
157
158private:
160 makeTransaction(Slice data, SHAMapHash const& hash, bool hashValid);
161
163 makeAccountState(Slice data, SHAMapHash const& hash, bool hashValid);
164
166 makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool hashValid);
167};
168
169} // 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.