rippled
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 <ripple/basics/XRPAmount.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/ledger/OpenView.h>
26 #include <ripple/ledger/RawView.h>
27 #include <ripple/ledger/ReadView.h>
28 #include <ripple/protocol/TER.h>
29 #include <ripple/protocol/TxMeta.h>
30 #include <memory>
31 
32 namespace ripple {
33 namespace detail {
34 
35 // Helper class that buffers modifications
37 {
38 public:
40 
41 private:
42  enum class Action {
43  cache,
44  erase,
45  insert,
46  modify,
47  };
48 
50 
53 
54 public:
55  ApplyStateTable() = default;
56  ApplyStateTable(ApplyStateTable&&) = default;
57 
58  ApplyStateTable(ApplyStateTable const&) = delete;
60  operator=(ApplyStateTable&&) = delete;
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,
73  beast::Journal j);
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 
127 private:
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,
138  beast::Journal j);
139 
140  void
141  threadTx(
142  ReadView const& base,
143  TxMeta& meta,
144  AccountID const& to,
145  Mods& mods,
146  beast::Journal j);
147 
148  void
149  threadOwners(
150  ReadView const& base,
151  TxMeta& meta,
152  std::shared_ptr<SLE const> const& sle,
153  Mods& mods,
154  beast::Journal j);
155 };
156 
157 } // namespace detail
158 } // namespace ripple
159 
160 #endif
ripple::detail::ApplyStateTable::size
std::size_t size() const
Definition: ApplyStateTable.cpp:55
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
std::shared_ptr
STL class.
ripple::detail::ApplyStateTable::insert
void insert(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:432
ripple::ReadView::key_type
uint256 key_type
Definition: ReadView.h:131
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:55
ripple::detail::ApplyStateTable::visit
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
Definition: ApplyStateTable.cpp:74
ripple::detail::ApplyStateTable::operator=
ApplyStateTable & operator=(ApplyStateTable &&)=delete
ripple::detail::ApplyStateTable::exists
bool exists(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:268
std::function
ripple::detail::ApplyStateTable::ApplyStateTable
ApplyStateTable()=default
ripple::detail::ApplyStateTable::threadItem
static void threadItem(TxMeta &meta, std::shared_ptr< SLE > const &to)
Definition: ApplyStateTable.cpp:523
ripple::detail::ApplyStateTable::Action::cache
@ cache
ripple::detail::ApplyStateTable::dropsDestroyed
XRPAmount const & dropsDestroyed() const
Definition: ApplyStateTable.h:122
ripple::detail::ApplyStateTable::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: ApplyStateTable.cpp:514
ripple::detail::ApplyStateTable::dropsDestroyed_
XRPAmount dropsDestroyed_
Definition: ApplyStateTable.h:52
ripple::detail::ApplyStateTable::replace
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:462
ripple::TxMeta
Definition: TxMeta.h:32
ripple::base_uint< 256 >
ripple::RawView
Interface for ledger entry changes.
Definition: RawView.h:36
ripple::detail::ApplyStateTable::apply
void apply(RawView &to) const
Definition: ApplyStateTable.cpp:31
ripple::detail::ApplyStateTable::threadOwners
void threadOwners(ReadView const &base, TxMeta &meta, std::shared_ptr< SLE const > const &sle, Mods &mods, beast::Journal j)
Definition: ApplyStateTable.cpp:617
ripple::TERSubset< CanCvtToTER >
ripple::detail::ApplyStateTable::erase
void erase(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:381
ripple::detail::ApplyStateTable::Action::erase
@ erase
ripple::STTx
Definition: STTx.h:45
ripple::detail::ApplyStateTable::threadTx
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
Definition: ApplyStateTable.cpp:597
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::map
STL class.
ripple::detail::ApplyStateTable::read
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:325
memory
ripple::detail::ApplyStateTable::rawErase
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:405
ripple::detail::ApplyStateTable::getForMod
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
Definition: ApplyStateTable.cpp:548
ripple::detail::ApplyStateTable::key_type
ReadView::key_type key_type
Definition: ApplyStateTable.h:39
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::detail::ApplyStateTable::update
void update(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:491
ripple::detail::ApplyStateTable::succ
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
Definition: ApplyStateTable.cpp:290
std::optional< STAmount >
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:88
std::size_t
ripple::detail::ApplyStateTable::Action::modify
@ modify
ripple::detail::ApplyStateTable::peek
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
Definition: ApplyStateTable.cpp:347
ripple::detail::ApplyStateTable::items_
items_t items_
Definition: ApplyStateTable.h:51
ripple::detail::ApplyStateTable::Action
Action
Definition: ApplyStateTable.h:42
std::unordered_map
STL class.
ripple::detail::ApplyStateTable::Action::insert
@ insert
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::detail::ApplyStateTable
Definition: ApplyStateTable.h:36