rippled
Loading...
Searching...
No Matches
ReadView.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpl/ledger/ReadView.h>
21
22namespace ripple {
23
24ReadView::sles_type::sles_type(ReadView const& view) : ReadViewFwdRange(view)
25{
26}
27
28auto
30{
31 return iterator(view_, view_->slesBegin());
32}
33
34auto
36{
37 return iterator(view_, view_->slesEnd());
38}
39
40auto
42{
43 return iterator(view_, view_->slesUpperBound(key));
44}
45
46ReadView::txs_type::txs_type(ReadView const& view) : ReadViewFwdRange(view)
47{
48}
49
50bool
52{
53 return begin() == end();
54}
55
56auto
57ReadView::txs_type::begin() const -> iterator
58{
59 return iterator(view_, view_->txsBegin());
60}
61
62auto
63ReadView::txs_type::end() const -> iterator
64{
65 return iterator(view_, view_->txsEnd());
66}
67
70{
71 return makeRulesGivenLedger(ledger, current.presets());
72}
73
76 DigestAwareReadView const& ledger,
78{
79 Keylet const k = keylet::amendments();
80 std::optional digest = ledger.digest(k.key);
81 if (digest)
82 {
83 auto const sle = ledger.read(k);
84 if (sle)
85 return Rules(presets, digest, sle->getFieldV256(sfAmendments));
86 }
87 return Rules(presets);
88}
89
90} // namespace ripple
ReadView that associates keys with digests.
Definition ReadView.h:255
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
A view into a ledger.
Definition ReadView.h:51
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Rules controlling protocol behavior.
Definition Rules.h:38
friend Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:69
Keylet const & amendments() noexcept
The index of the amendment table.
Definition Indexes.cpp:214
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ current
This was a new validation and was added.
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition tokens.cpp:156
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:69
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:39
uint256 key
Definition Keylet.h:40
iterator upper_bound(key_type const &key) const
Definition ReadView.cpp:41
iterator begin() const
Definition ReadView.cpp:29
sles_type(ReadView const &view)
Definition ReadView.cpp:24
iterator end() const
Definition ReadView.cpp:63
txs_type(ReadView const &view)
Definition ReadView.cpp:46
iterator begin() const
Definition ReadView.cpp:57