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/ledger/ApplyViewImpl.h>
25 #include <ripple/basics/XRPAmount.h>
26 #include <ripple/core/Config.h>
27 #include <ripple/protocol/STTx.h>
28 #include <ripple/beast/utility/Journal.h>
29 #include <boost/optional.hpp>
30 #include <utility>
31 
32 namespace ripple {
33 
36 {
37 public:
38  explicit
40  STTx const& tx, TER preclaimResult,
43 
45  STTx const& tx;
49 
50  ApplyView&
51  view()
52  {
53  return *view_;
54  }
55 
56  ApplyView const&
57  view() const
58  {
59  return *view_;
60  }
61 
62  // VFALCO Unfortunately this is necessary
63  RawView&
65  {
66  return *view_;
67  }
68 
70  void
71  deliver (STAmount const& amount)
72  {
73  view_->deliver(amount);
74  }
75 
77  void
78  discard();
79 
81  void
82  apply (TER);
83 
86  size ();
87 
89  void
90  visit (std::function <void (
91  uint256 const& key,
92  bool isDelete,
93  std::shared_ptr <SLE const> const& before,
94  std::shared_ptr <SLE const> const& after)> const& func);
95 
96  void
97  destroyXRP (XRPAmount const& fee)
98  {
99  view_->rawDestroyXRP(fee);
100  }
101 
108  TER
109  checkInvariants(TER const result, XRPAmount const fee);
110 
111 private:
112  TER
113  failInvariantCheck (TER const result);
114 
115  template<std::size_t... Is>
116  TER
118 
121  boost::optional<ApplyViewImpl> view_;
122 };
123 
124 } // ripple
125 
126 #endif
ripple::ApplyContext::ApplyContext
ApplyContext(Application &app, OpenView &base, STTx const &tx, TER preclaimResult, FeeUnit64 baseFee, ApplyFlags flags, beast::Journal=beast::Journal{beast::Journal::getNullSink()})
Definition: ApplyContext.cpp:31
ripple::Application
Definition: Application.h:85
ripple::ApplyContext::view_
boost::optional< ApplyViewImpl > view_
Definition: ApplyContext.h:121
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:142
utility
ripple::ApplyContext::preclaimResult
const TER preclaimResult
Definition: ApplyContext.h:46
std::index_sequence
ripple::ApplyContext::view
ApplyView const & view() const
Definition: ApplyContext.h:57
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:52
ripple::ApplyContext::flags_
ApplyFlags flags_
Definition: ApplyContext.h:120
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:30
ripple::ApplyContext::journal
const beast::Journal journal
Definition: ApplyContext.h:48
ripple::ApplyContext::rawView
RawView & rawView()
Definition: ApplyContext.h:64
std::function
ripple::ApplyContext::base_
OpenView & base_
Definition: ApplyContext.h:119
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:67
ripple::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:150
ripple::ApplyContext::app
Application & app
Definition: ApplyContext.h:44
ripple::base_uint< 256 >
ripple::RawView
Interface for ledger entry changes.
Definition: RawView.h:37
ripple::ApplyContext::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: ApplyContext.h:97
ripple::TERSubset< CanCvtToTER >
ripple::STAmount
Definition: STAmount.h:42
ripple::ApplyContext::discard
void discard()
Discard changes and start fresh.
Definition: ApplyContext.cpp:47
ripple::STTx
Definition: STTx.h:43
ripple::ApplyContext::deliver
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
Definition: ApplyContext.h:71
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:72
ripple::ApplyContext::view
ApplyView & view()
Definition: ApplyContext.h:51
ripple::ApplyContext::apply
void apply(TER)
Apply the transaction result to the base.
Definition: ApplyContext.cpp:53
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:65
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:88
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:87
std::size_t
ripple::ApplyContext::baseFee
const FeeUnit64 baseFee
Definition: ApplyContext.h:47
ripple::ApplyContext::size
std::size_t size()
Get the number of unapplied changes.
Definition: ApplyContext.cpp:59
ripple::ApplyContext::tx
STTx const & tx
Definition: ApplyContext.h:45
ripple::ApplyContext::failInvariantCheck
TER failInvariantCheck(TER const result)
Definition: ApplyContext.cpp:74
ripple::XRPAmount
Definition: XRPAmount.h:46