rippled
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 <ripple/ledger/ReadView.h>
21 
22 namespace ripple {
23 
24 ReadView::sles_type::sles_type(ReadView const& view) : ReadViewFwdRange(view)
25 {
26 }
27 
28 auto
29 ReadView::sles_type::begin() const -> iterator
30 {
31  return iterator(view_, view_->slesBegin());
32 }
33 
34 auto
35 ReadView::sles_type::end() const -> iterator
36 {
37  return iterator(view_, view_->slesEnd());
38 }
39 
40 auto
41 ReadView::sles_type::upper_bound(key_type const& key) const -> iterator
42 {
43  return iterator(view_, view_->slesUpperBound(key));
44 }
45 
46 ReadView::txs_type::txs_type(ReadView const& view) : ReadViewFwdRange(view)
47 {
48 }
49 
50 bool
52 {
53  return begin() == end();
54 }
55 
56 auto
57 ReadView::txs_type::begin() const -> iterator
58 {
59  return iterator(view_, view_->txsBegin());
60 }
61 
62 auto
63 ReadView::txs_type::end() const -> iterator
64 {
65  return iterator(view_, view_->txsEnd());
66 }
67 
68 Rules
69 makeRulesGivenLedger(DigestAwareReadView const& ledger, Rules const& current)
70 {
71  return makeRulesGivenLedger(ledger, current.presets());
72 }
73 
74 Rules
76  DigestAwareReadView const& ledger,
77  std::unordered_set<uint256, beast::uhash<>> const& presets)
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
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::keylet::amendments
Keylet const & amendments() noexcept
The index of the amendment table.
Definition: Indexes.cpp:163
std::unordered_set
STL class.
ripple::ReadView::sles_type::sles_type
sles_type(ReadView const &view)
Definition: ReadView.cpp:24
ripple::ReadView::txs_type::empty
bool empty() const
Definition: ReadView.cpp:51
ripple::ReadView::sles_type::upper_bound
iterator upper_bound(key_type const &key) const
Definition: ReadView.cpp:41
ripple::ReadView::sles_type::begin
iterator begin() const
Definition: ReadView.cpp:29
ripple::digest
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
Definition: tokens.cpp:47
ripple::Keylet::key
uint256 key
Definition: Keylet.h:40
ripple::base_uint< 256 >
ripple::ReadView::txs_type::begin
iterator begin() const
Definition: ReadView.cpp:57
ripple::DigestAwareReadView
ReadView that associates keys with digests.
Definition: ReadView.h:329
ripple::ReadView::sles_type::end
iterator end() const
Definition: ReadView.cpp:35
ripple::ValStatus::current
@ current
This was a new validation and was added.
ripple::ReadView::txs_type::end
iterator end() const
Definition: ReadView.cpp:63
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::makeRulesGivenLedger
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition: ReadView.cpp:69
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
std::optional
beast::uhash<>
ripple::DigestAwareReadView::digest
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
ripple::sfAmendments
const SF_VECTOR256 sfAmendments
ripple::ReadView::txs_type::txs_type
txs_type(ReadView const &view)
Definition: ReadView.cpp:46