rippled
Loading...
Searching...
No Matches
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 <xrpld/app/main/Application.h>
24#include <xrpld/core/Config.h>
25
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/ledger/ApplyViewImpl.h>
28#include <xrpl/protocol/STTx.h>
29#include <xrpl/protocol/XRPAmount.h>
30
31#include <optional>
32
33namespace ripple {
34
37{
38public:
39 explicit ApplyContext(
41 OpenView& base,
42 std::optional<uint256 const> const& parentBatchId,
43 STTx const& tx,
48
49 explicit ApplyContext(
51 OpenView& base,
52 STTx const& tx,
58 app,
59 base,
60 std::nullopt,
61 tx,
63 baseFee,
64 flags,
65 journal)
66 {
67 XRPL_ASSERT(
68 (flags & tapBATCH) == 0, "Batch apply flag should not be set");
69 }
70
72 STTx const& tx;
76
79 {
80 return *view_;
81 }
82
83 ApplyView const&
84 view() const
85 {
86 return *view_;
87 }
88
89 // VFALCO Unfortunately this is necessary
90 RawView&
92 {
93 return *view_;
94 }
95
96 ApplyFlags const&
97 flags() const
98 {
99 return flags_;
100 }
101
103 void
104 deliver(STAmount const& amount)
105 {
106 view_->deliver(amount);
107 }
108
110 void
111 discard();
112
115
118 size();
119
121 void
122 visit(std::function<void(
123 uint256 const& key,
124 bool isDelete,
125 std::shared_ptr<SLE const> const& before,
126 std::shared_ptr<SLE const> const& after)> const& func);
127
128 void
130 {
131 view_->rawDestroyXRP(fee);
132 }
133
140 TER
141 checkInvariants(TER const result, XRPAmount const fee);
142
143private:
144 TER
145 failInvariantCheck(TER const result);
146
147 template <std::size_t... Is>
148 TER
150 TER const result,
151 XRPAmount const fee,
153
157
158 // The ID of the batch transaction we are executing under, if seated.
160};
161
162} // namespace ripple
163
164#endif
A generic endpoint for log messages.
Definition Journal.h:60
static Sink & getNullSink()
Returns a Sink which does nothing.
State information when applying a tx.
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.
ApplyContext(Application &app, OpenView &base, STTx const &tx, TER preclaimResult, XRPAmount baseFee, ApplyFlags flags, beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
std::optional< TxMeta > apply(TER)
Apply the transaction result to the base.
ApplyView & view()
ApplyFlags const & flags() const
void discard()
Discard changes and start fresh.
TER failInvariantCheck(TER const result)
void destroyXRP(XRPAmount const &fee)
Application & app
ApplyView const & view() const
beast::Journal const journal
XRPAmount const baseFee
std::size_t size()
Get the number of unapplied changes.
std::optional< ApplyViewImpl > view_
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
std::optional< uint256 const > parentBatchId_
TER checkInvariantsHelper(TER const result, XRPAmount const fee, std::index_sequence< Is... >)
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:143
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:65
Interface for ledger entry changes.
Definition RawView.h:34
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3266
@ tapBATCH
Definition ApplyView.h:45
STL namespace.