xrpld
Loading...
Searching...
No Matches
CachedView.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/hardened_hash.h>
5#include <xrpl/ledger/CachedSLEs.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/Fees.h>
8#include <xrpl/protocol/Keylet.h>
9#include <xrpl/protocol/LedgerHeader.h>
10#include <xrpl/protocol/Rules.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12
13#include <memory>
14#include <mutex>
15#include <optional>
16#include <type_traits>
17#include <unordered_map>
18
19namespace xrpl {
20
21namespace detail {
22
24{
25private:
30
31public:
32 CachedViewImpl() = delete;
35 operator=(CachedViewImpl const&) = delete;
36
37 CachedViewImpl(DigestAwareReadView const* base, CachedSLEs& cache) : base_(*base), cache_(cache)
38 {
39 }
40
41 //
42 // ReadView
43 //
44
45 bool
46 exists(Keylet const& k) const override;
47
49 read(Keylet const& k) const override;
50
51 bool
52 open() const override
53 {
54 return base_.open();
55 }
56
57 LedgerHeader const&
58 header() const override
59 {
60 return base_.header();
61 }
62
63 Fees const&
64 fees() const override
65 {
66 return base_.fees();
67 }
68
69 Rules const&
70 rules() const override
71 {
72 return base_.rules();
73 }
74
76 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const override
77 {
78 return base_.succ(key, last);
79 }
80
82 slesBegin() const override
83 {
84 return base_.slesBegin();
85 }
86
88 slesEnd() const override
89 {
90 return base_.slesEnd();
91 }
92
94 slesUpperBound(uint256 const& key) const override
95 {
96 return base_.slesUpperBound(key);
97 }
98
100 txsBegin() const override
101 {
102 return base_.txsBegin();
103 }
104
106 txsEnd() const override
107 {
108 return base_.txsEnd();
109 }
110
111 bool
112 txExists(key_type const& key) const override
113 {
114 return base_.txExists(key);
115 }
116
117 tx_type
118 txRead(key_type const& key) const override
119 {
120 return base_.txRead(key);
121 }
122
123 //
124 // DigestAwareReadView
125 //
126
128 digest(key_type const& key) const override
129 {
130 return base_.digest(key);
131 }
132};
133
134} // namespace detail
135
141template <class Base>
143{
144private:
146
148
149public:
150 using base_type = Base;
151
152 CachedView() = delete;
153 CachedView(CachedView const&) = delete;
155 operator=(CachedView const&) = delete;
156
158 : CachedViewImpl(base.get(), cache), sp_(base)
159 {
160 }
161
168 base() const
169 {
170 return sp_;
171 }
172};
173
174} // namespace xrpl
CachedView(std::shared_ptr< Base const > const &base, CachedSLEs &cache)
Definition CachedView.h:157
CachedView & operator=(CachedView const &)=delete
std::shared_ptr< Ledger const > sp_
Definition CachedView.h:147
std::shared_ptr< Ledger const > const & base() const
Definition CachedView.h:168
CachedView()=delete
CachedView(CachedView const &)=delete
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:43
uint256 key_type
Definition ReadView.h:45
Rules controlling protocol behavior.
Definition Rules.h:40
std::shared_ptr< STLedgerEntry const > const_pointer
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition CachedView.h:118
std::unique_ptr< SlesType::iter_base > slesBegin() const override
Definition CachedView.h:82
CachedViewImpl(DigestAwareReadView const *base, CachedSLEs &cache)
Definition CachedView.h:37
LedgerHeader const & header() const override
Returns information about the ledger.
Definition CachedView.h:58
CachedViewImpl(CachedViewImpl const &)=delete
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
Rules const & rules() const override
Returns the tx processing rules.
Definition CachedView.h:70
std::unique_ptr< SlesType::iter_base > slesEnd() const override
Definition CachedView.h:88
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
Definition CachedView.h:76
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
Definition CachedView.h:128
bool open() const override
Returns true if this reflects an open ledger.
Definition CachedView.h:52
DigestAwareReadView const & base_
Definition CachedView.h:26
std::unordered_map< key_type, uint256, HardenedHash<> > map_
Definition CachedView.h:29
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition CachedView.h:112
std::unique_ptr< SlesType::iter_base > slesUpperBound(uint256 const &key) const override
Definition CachedView.h:94
Fees const & fees() const override
Returns the fees for the base ledger.
Definition CachedView.h:64
bool exists(Keylet const &k) const override
Determine if a state item exists.
CachedViewImpl & operator=(CachedViewImpl const &)=delete
std::unique_ptr< TxsType::iter_base > txsEnd() const override
Definition CachedView.h:106
std::unique_ptr< TxsType::iter_base > txsBegin() const override
Definition CachedView.h:100
T is_base_of_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
TaggedCache< uint256, SLE const > CachedSLEs
BaseUInt< 256 > uint256
Definition base_uint.h:580
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
Information about the notional ledger backing the view.