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