rippled
Loading...
Searching...
No Matches
CachedView.h
1#pragma once
2
3#include <xrpl/basics/hardened_hash.h>
4#include <xrpl/ledger/CachedSLEs.h>
5#include <xrpl/ledger/ReadView.h>
6
7#include <mutex>
8#include <type_traits>
9
10namespace xrpl {
11
12namespace detail {
13
15{
16private:
21
22public:
23 CachedViewImpl() = delete;
26 operator=(CachedViewImpl const&) = delete;
27
28 CachedViewImpl(DigestAwareReadView const* base, CachedSLEs& cache) : base_(*base), cache_(cache)
29 {
30 }
31
32 //
33 // ReadView
34 //
35
36 bool
37 exists(Keylet const& k) const override;
38
40 read(Keylet const& k) const override;
41
42 bool
43 open() const override
44 {
45 return base_.open();
46 }
47
48 LedgerHeader const&
49 header() const override
50 {
51 return base_.header();
52 }
53
54 Fees const&
55 fees() const override
56 {
57 return base_.fees();
58 }
59
60 Rules const&
61 rules() const override
62 {
63 return base_.rules();
64 }
65
67 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const override
68 {
69 return base_.succ(key, last);
70 }
71
73 slesBegin() const override
74 {
75 return base_.slesBegin();
76 }
77
79 slesEnd() const override
80 {
81 return base_.slesEnd();
82 }
83
85 slesUpperBound(uint256 const& key) const override
86 {
87 return base_.slesUpperBound(key);
88 }
89
91 txsBegin() const override
92 {
93 return base_.txsBegin();
94 }
95
97 txsEnd() const override
98 {
99 return base_.txsEnd();
100 }
101
102 bool
103 txExists(key_type const& key) const override
104 {
105 return base_.txExists(key);
106 }
107
108 tx_type
109 txRead(key_type const& key) const override
110 {
111 return base_.txRead(key);
112 }
113
114 //
115 // DigestAwareReadView
116 //
117
119 digest(key_type const& key) const override
120 {
121 return base_.digest(key);
122 }
123};
124
125} // namespace detail
126
131template <class Base>
133{
134private:
136
138
139public:
140 using base_type = Base;
141
142 CachedView() = delete;
143 CachedView(CachedView const&) = delete;
145 operator=(CachedView const&) = delete;
146
148 : CachedViewImpl(base.get(), cache), sp_(base)
149 {
150 }
151
157 base() const
158 {
159 return sp_;
160 }
161};
162
163} // namespace xrpl
Wraps a DigestAwareReadView to provide caching.
Definition CachedView.h:133
CachedView(std::shared_ptr< Base const > const &base, CachedSLEs &cache)
Definition CachedView.h:147
CachedView & operator=(CachedView const &)=delete
std::shared_ptr< Base const > sp_
Definition CachedView.h:137
std::shared_ptr< Base const > const & base() const
Returns the base type.
Definition CachedView.h:157
CachedView()=delete
CachedView(CachedView const &)=delete
ReadView that associates keys with digests.
Definition ReadView.h:229
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual std::unique_ptr< txs_type::iter_base > txsBegin() const =0
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual std::unique_ptr< txs_type::iter_base > txsEnd() const =0
virtual std::unique_ptr< sles_type::iter_base > slesUpperBound(key_type const &key) const =0
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:33
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
virtual std::unique_ptr< sles_type::iter_base > slesBegin() const =0
virtual std::unique_ptr< sles_type::iter_base > slesEnd() const =0
Rules controlling protocol behavior.
Definition Rules.h:18
Map/cache combination.
Definition TaggedCache.h:42
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition CachedView.h:109
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition CachedView.h:73
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
CachedViewImpl(DigestAwareReadView const *base, CachedSLEs &cache)
Definition CachedView.h:28
LedgerHeader const & header() const override
Returns information about the ledger.
Definition CachedView.h:49
CachedViewImpl(CachedViewImpl const &)=delete
std::unordered_map< key_type, uint256, hardened_hash<> > map_
Definition CachedView.h:20
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition CachedView.h:97
Rules const & rules() const override
Returns the tx processing rules.
Definition CachedView.h:61
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:67
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition CachedView.h:85
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
Definition CachedView.h:119
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition CachedView.h:91
bool open() const override
Returns true if this reflects an open ledger.
Definition CachedView.h:43
DigestAwareReadView const & base_
Definition CachedView.h:17
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition CachedView.h:103
Fees const & fees() const override
Returns the fees for the base ledger.
Definition CachedView.h:55
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition CachedView.cpp:8
CachedViewImpl & operator=(CachedViewImpl const &)=delete
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition CachedView.h:79
T is_same_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.
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
Information about the notional ledger backing the view.