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
67 void
68 apply(
69 OpenView& to,
70 STTx const& tx,
71 TER ter,
72 std::optional<STAmount> const& deliver,
74
75 bool
76 exists(ReadView const& base, Keylet const& k) const;
77
79 succ(
80 ReadView const& base,
81 key_type const& key,
82 std::optional<key_type> const& last) const;
83
85 read(ReadView const& base, Keylet const& k) const;
86
88 peek(ReadView const& base, Keylet const& k);
89
91 size() const;
92
93 void
94 visit(
95 ReadView const& base,
96 std::function<void(
97 uint256 const& key,
98 bool isDelete,
99 std::shared_ptr<SLE const> const& before,
100 std::shared_ptr<SLE const> const& after)> const& func) const;
101
102 void
103 erase(ReadView const& base, std::shared_ptr<SLE> const& sle);
104
105 void
106 rawErase(ReadView const& base, std::shared_ptr<SLE> const& sle);
107
108 void
109 insert(ReadView const& base, std::shared_ptr<SLE> const& sle);
110
111 void
112 update(ReadView const& base, std::shared_ptr<SLE> const& sle);
113
114 void
115 replace(ReadView const& base, std::shared_ptr<SLE> const& sle);
116
117 void
118 destroyXRP(XRPAmount const& fee);
119
120 // For debugging
121 XRPAmount const&
123 {
124 return dropsDestroyed_;
125 }
126
127private:
129
130 static void
131 threadItem(TxMeta& meta, std::shared_ptr<SLE> const& to);
132
134 getForMod(
135 ReadView const& base,
136 key_type const& key,
137 Mods& mods,
139
140 void
141 threadTx(
142 ReadView const& base,
143 TxMeta& meta,
144 AccountID const& to,
145 Mods& mods,
147
148 void
150 ReadView const& base,
151 TxMeta& meta,
153 Mods& mods,
155};
156
157} // namespace detail
158} // namespace ripple
159
160#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