rippled
ApplyViewBase.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/detail/ApplyViewBase.h>
21 #include <ripple/basics/contract.h>
22 #include <ripple/ledger/CashDiff.h>
23 
24 namespace ripple {
25 namespace detail {
26 
28  ReadView const* base, ApplyFlags flags)
29  : flags_ (flags)
30  , base_ (base)
31 {
32 }
33 
34 //---
35 
36 bool
38 {
39  return base_->open();
40 }
41 
42 LedgerInfo const&
44 {
45  return base_->info();
46 }
47 
48 Fees const&
50 {
51  return base_->fees();
52 }
53 
54 Rules const&
56 {
57  return base_->rules();
58 }
59 
60 bool
61 ApplyViewBase::exists (Keylet const& k) const
62 {
63  return items_.exists(*base_, k);
64 }
65 
66 auto
68  boost::optional<key_type> const& last) const ->
69  boost::optional<key_type>
70 {
71  return items_.succ(*base_, key, last);
72 }
73 
75 ApplyViewBase::read (Keylet const& k) const
76 {
77  return items_.read(*base_, k);
78 }
79 
80 auto
82  std::unique_ptr<sles_type::iter_base>
83 {
84  return base_->slesBegin();
85 }
86 
87 auto
89  std::unique_ptr<sles_type::iter_base>
90 {
91  return base_->slesEnd();
92 }
93 
94 auto
97 {
98  return base_->slesUpperBound(key);
99 }
100 
101 auto
103  std::unique_ptr<txs_type::iter_base>
104 {
105  return base_->txsBegin();
106 }
107 
108 auto
110  std::unique_ptr<txs_type::iter_base>
111 {
112  return base_->txsEnd();
113 }
114 
115 bool
117 {
118  return base_->txExists(key);
119 }
120 
121 auto
123  key_type const& key) const ->
124  tx_type
125 {
126  return base_->txRead(key);
127 }
128 
129 //---
130 
133 {
134  return flags_;
135 }
136 
139 {
140  return items_.peek(*base_, k);
141 }
142 
143 void
145  std::shared_ptr<SLE> const& sle)
146 {
147  items_.erase(*base_, sle);
148 }
149 
150 void
152  std::shared_ptr<SLE> const& sle)
153 {
154  items_.insert(*base_, sle);
155 }
156 
157 void
159  std::shared_ptr<SLE> const& sle)
160 {
161  items_.update(*base_, sle);
162 }
163 
164 //---
165 
166 void
168  std::shared_ptr<SLE> const& sle)
169 {
170  items_.rawErase(*base_, sle);
171 }
172 
173 void
175  std::shared_ptr<SLE> const& sle)
176 {
177  items_.insert(*base_, sle);
178 }
179 
180 void
182  std::shared_ptr<SLE> const& sle)
183 {
184  items_.replace(*base_, sle);
185 }
186 
187 void
189  XRPAmount const& fee)
190 {
191  items_.destroyXRP(fee);
192 }
193 
194 //---
195 
197  CashFilter lhsFilter, ApplyViewBase const& lhs,
198  CashFilter rhsFilter, ApplyViewBase const& rhs)
199 {
200  assert (lhs.base_ == rhs.base_);
201  return CashDiff {
202  *lhs.base_, lhsFilter, lhs.items_, rhsFilter, rhs.items_ };
203 }
204 
205 } // detail
206 } // ripple
ripple::ReadView::info
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
std::shared_ptr
STL class.
ripple::detail::ApplyViewBase::rawReplace
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition: ApplyViewBase.cpp:181
ripple::detail::ApplyViewBase::txsBegin
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition: ApplyViewBase.cpp:102
ripple::ReadView::txs_type
Definition: ReadView.h:207
std::pair
ripple::detail::ApplyStateTable::insert
void insert(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:436
ripple::detail::ApplyViewBase::txRead
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition: ApplyViewBase.cpp:122
ripple::detail::ApplyViewBase::exists
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition: ApplyViewBase.cpp:61
ripple::CashDiff
Definition: CashDiff.h:61
ripple::ReadView::fees
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:30
ripple::detail::ApplyViewBase::update
void update(std::shared_ptr< SLE > const &sle) override
Indicate changes to a peeked SLE.
Definition: ApplyViewBase.cpp:158
ripple::ReadView::txsEnd
virtual std::unique_ptr< txs_type::iter_base > txsEnd() const =0
ripple::detail::ApplyStateTable::exists
bool exists(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:261
ripple::ReadView::txExists
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
ripple::ReadView::slesBegin
virtual std::unique_ptr< sles_type::iter_base > slesBegin() const =0
ripple::detail::ApplyViewBase::fees
Fees const & fees() const override
Returns the fees for the base ledger.
Definition: ApplyViewBase.cpp:49
ripple::detail::ApplyViewBase::items_
detail::ApplyStateTable items_
Definition: ApplyViewBase.h:139
ripple::detail::ApplyStateTable::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: ApplyStateTable.cpp:523
ripple::detail::ApplyStateTable::replace
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:468
ripple::detail::ApplyViewBase::ApplyViewBase
ApplyViewBase()=delete
ripple::ReadView::txsBegin
virtual std::unique_ptr< txs_type::iter_base > txsBegin() const =0
ripple::detail::ApplyViewBase::txsEnd
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition: ApplyViewBase.cpp:109
ripple::base_uint< 256 >
ripple::detail::ApplyViewBase::open
bool open() const override
Returns true if this reflects an open ledger.
Definition: ApplyViewBase.cpp:37
ripple::detail::cashFlowDiff
CashDiff cashFlowDiff(CashFilter lhsFilter, ApplyViewBase const &lhs, CashFilter rhsFilter, ApplyViewBase const &rhs)
Definition: ApplyViewBase.cpp:196
ripple::Fees
Reflects the fee settings for a particular ledger.
Definition: ReadView.h:47
ripple::detail::ApplyViewBase::info
LedgerInfo const & info() const override
Returns information about the ledger.
Definition: ApplyViewBase.cpp:43
ripple::detail::ApplyViewBase::slesEnd
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition: ApplyViewBase.cpp:88
ripple::detail::ApplyViewBase::base_
ReadView const * base_
Definition: ApplyViewBase.h:138
ripple::detail::ApplyViewBase::succ
boost::optional< key_type > succ(key_type const &key, boost::optional< key_type > const &last=boost::none) const override
Return the key of the next state item.
Definition: ApplyViewBase.cpp:67
ripple::ReadView::slesEnd
virtual std::unique_ptr< sles_type::iter_base > slesEnd() const =0
ripple::detail::ApplyStateTable::erase
void erase(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:381
ripple::detail::ApplyViewBase::slesBegin
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition: ApplyViewBase.cpp:81
ripple::detail::ApplyViewBase::rawErase
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition: ApplyViewBase.cpp:167
ripple::detail::ApplyStateTable::read
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:322
ripple::detail::ApplyStateTable::rawErase
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:408
ripple::detail::ApplyViewBase::insert
void insert(std::shared_ptr< SLE > const &sle) override
Insert a new state SLE.
Definition: ApplyViewBase.cpp:151
ripple::detail::ApplyViewBase::erase
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
Definition: ApplyViewBase.cpp:144
ripple::detail::ApplyViewBase::flags
ApplyFlags flags() const override
Returns the tx apply flags.
Definition: ApplyViewBase.cpp:132
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:186
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ReadView::sles_type
Definition: ReadView.h:198
ripple::ReadView::rules
virtual Rules const & rules() const =0
Returns the tx processing rules.
std
STL namespace.
ripple::detail::ApplyStateTable::update
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:498
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:126
ripple::detail::ApplyViewBase::flags_
ApplyFlags flags_
Definition: ApplyViewBase.h:137
ripple::detail::ApplyViewBase::read
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: ApplyViewBase.cpp:75
ripple::detail::ApplyViewBase::peek
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
Definition: ApplyViewBase.cpp:138
ripple::LedgerInfo
Information about the notional ledger backing the view.
Definition: ReadView.h:79
ripple::detail::ApplyViewBase::rules
Rules const & rules() const override
Returns the tx processing rules.
Definition: ApplyViewBase.cpp:55
ripple::detail::ApplyViewBase::txExists
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition: ApplyViewBase.cpp:116
ripple::detail::ApplyStateTable::peek
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
Definition: ApplyStateTable.cpp:345
std::unique_ptr
STL class.
ripple::ReadView::open
virtual bool open() const =0
Returns true if this reflects an open ledger.
ripple::detail::ApplyViewBase
Definition: ApplyViewBase.h:33
ripple::CashFilter
CashFilter
Definition: CashDiff.h:39
ripple::detail::ApplyViewBase::rawInsert
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition: ApplyViewBase.cpp:174
ripple::detail::ApplyViewBase::slesUpperBound
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition: ApplyViewBase.cpp:95
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::detail::ApplyViewBase::rawDestroyXRP
void rawDestroyXRP(XRPAmount const &feeDrops) override
Destroy XRP.
Definition: ApplyViewBase.cpp:188