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/ledger/OpenView.h>
24 #include <ripple/ledger/RawView.h>
25 #include <ripple/ledger/ReadView.h>
26 #include <ripple/ledger/TxMeta.h>
27 #include <ripple/basics/XRPAmount.h>
28 #include <ripple/protocol/TER.h>
29 #include <ripple/beast/utility/Journal.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  {
44  cache,
45  erase,
46  insert,
47  modify,
48  };
49 
50  using items_t = std::map<key_type,
52 
55 
56 public:
57  ApplyStateTable() = default;
58  ApplyStateTable (ApplyStateTable&&) = default;
59 
60  ApplyStateTable (ApplyStateTable const&) = delete;
62  ApplyStateTable& operator= (ApplyStateTable const&) = delete;
63 
64  void
65  apply (RawView& to) const;
66 
67  void
68  apply (OpenView& to, STTx const& tx,
69  TER ter, boost::optional<
70  STAmount> const& deliver,
71  beast::Journal j);
72 
73  bool
74  exists (ReadView const& base,
75  Keylet const& k) const;
76 
77  boost::optional<key_type>
78  succ (ReadView const& base,
79  key_type const& key, boost::optional<
80  key_type> const& last) const;
81 
83  read (ReadView const& base,
84  Keylet const& k) const;
85 
87  peek (ReadView const& base,
88  Keylet const& k);
89 
91  size () const;
92 
93  void
94  visit (ReadView const& base,
95  std::function <void (
96  uint256 const& key,
97  bool isDelete,
98  std::shared_ptr <SLE const> const& before,
99  std::shared_ptr <SLE const> const& after)> const& func) const;
100 
101  void
102  erase (ReadView const& base,
103  std::shared_ptr<SLE> const& sle);
104 
105  void
106  rawErase (ReadView const& base,
107  std::shared_ptr<SLE> const& sle);
108 
109  void
110  insert(ReadView const& base,
111  std::shared_ptr<SLE> const& sle);
112 
113  void
114  update(ReadView const& base,
115  std::shared_ptr<SLE> const& sle);
116 
117  void
118  replace(ReadView const& base,
119  std::shared_ptr<SLE> const& sle);
120 
121  void
122  destroyXRP (XRPAmount const& fee);
123 
124  // For debugging
125  XRPAmount const& dropsDestroyed () const
126  {
127  return dropsDestroyed_;
128  }
129 
130 private:
131  using Mods = hash_map<key_type,
133 
134  static
135  void
136  threadItem (TxMeta& meta,
137  std::shared_ptr<SLE> const& to);
138 
140  getForMod (ReadView const& base,
141  key_type const& key, Mods& mods,
142  beast::Journal j);
143 
144  void
145  threadTx (ReadView const& base, TxMeta& meta,
146  AccountID const& to, Mods& mods,
147  beast::Journal j);
148 
149  void
150  threadOwners (ReadView const& base,
151  TxMeta& meta, std::shared_ptr<
152  SLE const> const& sle, Mods& mods,
153  beast::Journal j);
154 };
155 
156 } // detail
157 } // ripple
158 
159 #endif
ripple::detail::ApplyStateTable::size
std::size_t size() const
Definition: ApplyStateTable.cpp:56
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::STLedgerEntry
Definition: STLedgerEntry.h:30
std::shared_ptr
STL class.
std::pair
ripple::detail::ApplyStateTable::insert
void insert(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:436
ripple::ReadView::key_type
uint256 key_type
Definition: ReadView.h:193
ripple::OpenView
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:52
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:75
ripple::detail::ApplyStateTable::operator=
ApplyStateTable & operator=(ApplyStateTable &&)=delete
ripple::detail::ApplyStateTable::exists
bool exists(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:261
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:532
ripple::detail::ApplyStateTable::Action::cache
@ cache
ripple::detail::ApplyStateTable::dropsDestroyed
XRPAmount const & dropsDestroyed() const
Definition: ApplyStateTable.h:125
ripple::detail::ApplyStateTable::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition: ApplyStateTable.cpp:523
ripple::detail::ApplyStateTable::dropsDestroyed_
XRPAmount dropsDestroyed_
Definition: ApplyStateTable.h:54
ripple::detail::ApplyStateTable::replace
void replace(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:468
ripple::TxMeta
Definition: TxMeta.h:33
ripple::base_uint< 256 >
ripple::RawView
Interface for ledger entry changes.
Definition: RawView.h:37
ripple::detail::ApplyStateTable::Mods
hash_map< key_type, std::shared_ptr< SLE > > Mods
Definition: ApplyStateTable.h:132
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:611
ripple::TERSubset< CanCvtToTER >
ripple::STAmount
Definition: STAmount.h:42
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:43
ripple::detail::ApplyStateTable::threadTx
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
Definition: ApplyStateTable.cpp:593
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::map
STL class.
ripple::detail::ApplyStateTable::read
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
Definition: ApplyStateTable.cpp:322
memory
ripple::detail::ApplyStateTable::rawErase
void rawErase(ReadView const &base, std::shared_ptr< SLE > const &sle)
Definition: ApplyStateTable.cpp:408
ripple::detail::ApplyStateTable::getForMod
std::shared_ptr< SLE > getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
Definition: ApplyStateTable.cpp:547
ripple::detail::ApplyStateTable::succ
boost::optional< key_type > succ(ReadView const &base, key_type const &key, boost::optional< key_type > const &last) const
Definition: ApplyStateTable.cpp:284
ripple::detail::ApplyStateTable::key_type
ReadView::key_type key_type
Definition: ApplyStateTable.h:39
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:186
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:498
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:87
std::size_t
ripple::detail::ApplyStateTable::items_t
std::map< key_type, std::pair< Action, std::shared_ptr< SLE > >> items_t
Definition: ApplyStateTable.h:51
ripple::detail::ApplyStateTable::Action::modify
@ modify
ripple::detail::ApplyStateTable::peek
std::shared_ptr< SLE > peek(ReadView const &base, Keylet const &k)
Definition: ApplyStateTable.cpp:345
ripple::detail::ApplyStateTable::items_
items_t items_
Definition: ApplyStateTable.h:53
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