rippled
ApplyContext.h
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 #ifndef RIPPLE_TX_APPLYCONTEXT_H_INCLUDED
21 #define RIPPLE_TX_APPLYCONTEXT_H_INCLUDED
22 
23 #include <ripple/app/main/Application.h>
24 #include <ripple/basics/XRPAmount.h>
25 #include <ripple/beast/utility/Journal.h>
26 #include <ripple/core/Config.h>
27 #include <ripple/ledger/ApplyViewImpl.h>
28 #include <ripple/protocol/STTx.h>
29 #include <optional>
30 #include <utility>
31 
32 namespace ripple {
33 
36 {
37 public:
38  explicit ApplyContext(
40  OpenView& base,
41  STTx const& tx,
44  ApplyFlags flags,
46 
48  STTx const& tx;
52 
53  ApplyView&
54  view()
55  {
56  return *view_;
57  }
58 
59  ApplyView const&
60  view() const
61  {
62  return *view_;
63  }
64 
65  // VFALCO Unfortunately this is necessary
66  RawView&
68  {
69  return *view_;
70  }
71 
73  void
74  deliver(STAmount const& amount)
75  {
76  view_->deliver(amount);
77  }
78 
80  void
81  discard();
82 
84  void apply(TER);
85 
88  size();
89 
91  void
92  visit(std::function<void(
93  uint256 const& key,
94  bool isDelete,
95  std::shared_ptr<SLE const> const& before,
96  std::shared_ptr<SLE const> const& after)> const& func);
97 
98  void
99  destroyXRP(XRPAmount const& fee)
100  {
101  view_->rawDestroyXRP(fee);
102  }
103 
110  TER
111  checkInvariants(TER const result, XRPAmount const fee);
112 
113 private:
114  TER
115  failInvariantCheck(TER const result);
116 
117  template <std::size_t... Is>
118  TER
120  TER const result,
121  XRPAmount const fee,
123 
127 };
128 
129 } // namespace ripple
130 
131 #endif
ripple::Application
Definition: Application.h:115
std::shared_ptr
STL class.
ripple::ApplyContext::checkInvariants
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
Definition: ApplyContext.cpp:147
utility
ripple::ApplyContext::preclaimResult
const TER preclaimResult
Definition: ApplyContext.h:49
ripple::ApplyContext::baseFee
const XRPAmount baseFee
Definition: ApplyContext.h:50
std::index_sequence
ripple::ApplyContext::view
ApplyView const & view() const
Definition: ApplyContext.h:60
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::ApplyContext::flags_
ApplyFlags flags_
Definition: ApplyContext.h:125
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:29
ripple::ApplyContext::journal
const beast::Journal journal
Definition: ApplyContext.h:51
ripple::ApplyContext::rawView
RawView & rawView()
Definition: ApplyContext.h:67
std::function
ripple::ApplyContext::base_
OpenView & base_
Definition: ApplyContext.h:124
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
ripple::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:134
ripple::ApplyContext::app
Application & app
Definition: ApplyContext.h:47
ripple::base_uint< 256 >
ripple::RawView
Interface for ledger entry changes.
Definition: RawView.h:36
ripple::ApplyContext::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: ApplyContext.h:99
ripple::TERSubset< CanCvtToTER >
ripple::STAmount
Definition: STAmount.h:45
ripple::ApplyContext::discard
void discard()
Discard changes and start fresh.
Definition: ApplyContext.cpp:51
ripple::STTx
Definition: STTx.h:45
ripple::ApplyContext::deliver
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
Definition: ApplyContext.h:74
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::ApplyContext::view
ApplyView & view()
Definition: ApplyContext.h:54
ripple::ApplyContext::apply
void apply(TER)
Apply the transaction result to the base.
Definition: ApplyContext.cpp:57
ripple::ApplyContext::visit
void visit(std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func)
Visit unapplied changes.
Definition: ApplyContext.cpp:69
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ApplyContext::checkInvariantsHelper
TER checkInvariantsHelper(TER const result, XRPAmount const fee, std::index_sequence< Is... >)
Definition: ApplyContext.cpp:93
ripple::ApplyContext::ApplyContext
ApplyContext(Application &app, OpenView &base, STTx const &tx, TER preclaimResult, XRPAmount baseFee, ApplyFlags flags, beast::Journal=beast::Journal{beast::Journal::getNullSink()})
Definition: ApplyContext.cpp:31
ripple::ApplyContext::view_
std::optional< ApplyViewImpl > view_
Definition: ApplyContext.h:126
optional
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:88
std::size_t
ripple::ApplyContext::size
std::size_t size()
Get the number of unapplied changes.
Definition: ApplyContext.cpp:63
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:48
ripple::ApplyContext::failInvariantCheck
TER failInvariantCheck(TER const result)
Definition: ApplyContext.cpp:79
ripple::XRPAmount
Definition: XRPAmount.h:46