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 <xrpld/ledger/OpenView.h>
24#include <xrpld/ledger/RawView.h>
25#include <xrpld/ledger/ReadView.h>
26
27#include <xrpl/beast/utility/Journal.h>
28#include <xrpl/protocol/TER.h>
29#include <xrpl/protocol/TxMeta.h>
30#include <xrpl/protocol/XRPAmount.h>
31
32#include <memory>
33
34namespace ripple {
35namespace detail {
36
37// Helper class that buffers modifications
39{
40public:
42
43private:
44 enum class Action {
45 cache,
46 erase,
47 insert,
48 modify,
49 };
50
52
55
56public:
57 ApplyStateTable() = default;
59
64 operator=(ApplyStateTable const&) = delete;
65
66 void
67 apply(RawView& to) const;
68
70 apply(
71 OpenView& to,
72 STTx const& tx,
73 TER ter,
74 std::optional<STAmount> const& deliver,
75 std::optional<uint256 const> const& parentBatchId,
76 bool isDryRun,
78
79 bool
80 exists(ReadView const& base, Keylet const& k) const;
81
83 succ(
84 ReadView const& base,
85 key_type const& key,
86 std::optional<key_type> const& last) const;
87
89 read(ReadView const& base, Keylet const& k) const;
90
92 peek(ReadView const& base, Keylet const& k);
93
95 size() const;
96
97 void
98 visit(
99 ReadView const& base,
100 std::function<void(
101 uint256 const& key,
102 bool isDelete,
103 std::shared_ptr<SLE const> const& before,
104 std::shared_ptr<SLE const> const& after)> const& func) const;
105
106 void
107 erase(ReadView const& base, std::shared_ptr<SLE> const& sle);
108
109 void
110 rawErase(ReadView const& base, std::shared_ptr<SLE> const& sle);
111
112 void
113 insert(ReadView const& base, std::shared_ptr<SLE> const& sle);
114
115 void
116 update(ReadView const& base, std::shared_ptr<SLE> const& sle);
117
118 void
119 replace(ReadView const& base, std::shared_ptr<SLE> const& sle);
120
121 void
122 destroyXRP(XRPAmount const& fee);
123
124 // For debugging
125 XRPAmount const&
127 {
128 return dropsDestroyed_;
129 }
130
131private:
133
134 static void
135 threadItem(TxMeta& meta, std::shared_ptr<SLE> const& to);
136
138 getForMod(
139 ReadView const& base,
140 key_type const& key,
141 Mods& mods,
143
144 void
145 threadTx(
146 ReadView const& base,
147 TxMeta& meta,
148 AccountID const& to,
149 Mods& mods,
151
152 void
154 ReadView const& base,
155 TxMeta& meta,
157 Mods& mods,
159};
160
161} // namespace detail
162} // namespace ripple
163
164#endif
A generic endpoint for log messages.
Definition Journal.h:60
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:66
Interface for ledger entry changes.
Definition RawView.h:35
A view into a ledger.
Definition ReadView.h:52
uint256 key_type
Definition ReadView.h:57
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:3179
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:39