rippled
Loading...
Searching...
No Matches
ApplyStateTable.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_LEDGER_APPLYSTATETABLE_H_INCLUDED
21#define RIPPLE_LEDGER_APPLYSTATETABLE_H_INCLUDED
22
23#include <xrpl/beast/utility/Journal.h>
24#include <xrpl/ledger/OpenView.h>
25#include <xrpl/ledger/RawView.h>
26#include <xrpl/ledger/ReadView.h>
27#include <xrpl/protocol/TER.h>
28#include <xrpl/protocol/TxMeta.h>
29#include <xrpl/protocol/XRPAmount.h>
30
31#include <memory>
32
33namespace ripple {
34namespace detail {
35
36// Helper class that buffers modifications
38{
39public:
41
42private:
43 enum class Action {
44 cache,
45 erase,
46 insert,
47 modify,
48 };
49
51
54
55public:
56 ApplyStateTable() = default;
58
63 operator=(ApplyStateTable const&) = delete;
64
65 void
66 apply(RawView& to) const;
67
69 apply(
70 OpenView& to,
71 STTx const& tx,
72 TER ter,
73 std::optional<STAmount> const& deliver,
74 std::optional<uint256 const> const& parentBatchId,
75 bool isDryRun,
77
78 bool
79 exists(ReadView const& base, Keylet const& k) const;
80
82 succ(
83 ReadView const& base,
84 key_type const& key,
85 std::optional<key_type> const& last) const;
86
88 read(ReadView const& base, Keylet const& k) const;
89
91 peek(ReadView const& base, Keylet const& k);
92
94 size() const;
95
96 void
97 visit(
98 ReadView const& base,
99 std::function<void(
100 uint256 const& key,
101 bool isDelete,
102 std::shared_ptr<SLE const> const& before,
103 std::shared_ptr<SLE const> const& after)> const& func) const;
104
105 void
106 erase(ReadView const& base, std::shared_ptr<SLE> const& sle);
107
108 void
109 rawErase(ReadView const& base, std::shared_ptr<SLE> const& sle);
110
111 void
112 insert(ReadView const& base, std::shared_ptr<SLE> const& sle);
113
114 void
115 update(ReadView const& base, std::shared_ptr<SLE> const& sle);
116
117 void
118 replace(ReadView const& base, std::shared_ptr<SLE> const& sle);
119
120 void
121 destroyXRP(XRPAmount const& fee);
122
123 // For debugging
124 XRPAmount const&
126 {
127 return dropsDestroyed_;
128 }
129
130private:
132
133 static void
134 threadItem(TxMeta& meta, std::shared_ptr<SLE> const& to);
135
137 getForMod(
138 ReadView const& base,
139 key_type const& key,
140 Mods& mods,
142
143 void
144 threadTx(
145 ReadView const& base,
146 TxMeta& meta,
147 AccountID const& to,
148 Mods& mods,
150
151 void
153 ReadView const& base,
154 TxMeta& meta,
156 Mods& mods,
158};
159
160} // namespace detail
161} // namespace ripple
162
163#endif
A generic endpoint for log messages.
Definition Journal.h:60
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:65
Interface for ledger entry changes.
Definition RawView.h:34
A view into a ledger.
Definition ReadView.h:51
uint256 key_type
Definition ReadView.h:56
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
XRPAmount const & dropsDestroyed() const
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
bool exists(ReadView const &base, Keylet const &k) const
void visit(ReadView const &base, std::function< void(uint256 const &key, bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)> const &func) const
static void threadItem(TxMeta &meta, std::shared_ptr< SLE > const &to)
ApplyStateTable & operator=(ApplyStateTable &&)=delete
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
void threadOwners(ReadView const &base, TxMeta &meta, std::shared_ptr< SLE const > const &sle, Mods &mods, beast::Journal j)
ApplyStateTable(ApplyStateTable &&)=default
ApplyStateTable & operator=(ApplyStateTable const &)=delete
void apply(RawView &to) const
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
ApplyStateTable(ApplyStateTable const &)=delete
void destroyXRP(XRPAmount const &fee)
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:3239
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:39