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#include <xrpl/beast/utility/Journal.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 bool isDryRun,
76
77 bool
78 exists(ReadView const& base, Keylet const& k) const;
79
81 succ(
82 ReadView const& base,
83 key_type const& key,
84 std::optional<key_type> const& last) const;
85
87 read(ReadView const& base, Keylet const& k) const;
88
90 peek(ReadView const& base, Keylet const& k);
91
93 size() const;
94
95 void
96 visit(
97 ReadView const& base,
98 std::function<void(
99 uint256 const& key,
100 bool isDelete,
101 std::shared_ptr<SLE const> const& before,
102 std::shared_ptr<SLE const> const& after)> const& func) const;
103
104 void
105 erase(ReadView const& base, std::shared_ptr<SLE> const& sle);
106
107 void
108 rawErase(ReadView const& base, std::shared_ptr<SLE> const& sle);
109
110 void
111 insert(ReadView const& base, std::shared_ptr<SLE> const& sle);
112
113 void
114 update(ReadView const& base, std::shared_ptr<SLE> const& sle);
115
116 void
117 replace(ReadView const& base, std::shared_ptr<SLE> const& sle);
118
119 void
120 destroyXRP(XRPAmount const& fee);
121
122 // For debugging
123 XRPAmount const&
125 {
126 return dropsDestroyed_;
127 }
128
129private:
131
132 static void
133 threadItem(TxMeta& meta, std::shared_ptr<SLE> const& to);
134
136 getForMod(
137 ReadView const& base,
138 key_type const& key,
139 Mods& mods,
141
142 void
143 threadTx(
144 ReadView const& base,
145 TxMeta& meta,
146 AccountID const& to,
147 Mods& mods,
149
150 void
152 ReadView const& base,
153 TxMeta& meta,
155 Mods& mods,
157};
158
159} // namespace detail
160} // namespace ripple
161
162#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:56
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:26
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:85
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39