rippled
STLedgerEntry.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_PROTOCOL_STLEDGERENTRY_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STLEDGERENTRY_H_INCLUDED
22 
23 #include <ripple/protocol/Indexes.h>
24 #include <ripple/protocol/STObject.h>
25 
26 namespace ripple {
27 
28 class Invariants_test;
29 
30 class STLedgerEntry final : public STObject, public CountedObject<STLedgerEntry>
31 {
34 
35 public:
38 
40  explicit STLedgerEntry(Keylet const& k);
42  STLedgerEntry(SerialIter& sit, uint256 const& index);
43  STLedgerEntry(SerialIter&& sit, uint256 const& index);
44  STLedgerEntry(STObject const& object, uint256 const& index);
45 
47  getSType() const override;
48 
50  getFullText() const override;
51 
53  getText() const override;
54 
56  getJson(JsonOptions options) const override;
57 
62  uint256 const&
63  key() const;
64 
66  getType() const;
67 
68  // is this a ledger entry that can be threaded
69  bool
70  isThreadedType() const;
71 
72  bool
73  thread(
74  uint256 const& txID,
75  std::uint32_t ledgerSeq,
76  uint256& prevTxID,
77  std::uint32_t& prevLedgerID);
78 
79 private:
80  /* Make STObject comply with the template for this SLE type
81  Can throw
82  */
83  void
84  setSLEType();
85 
86  friend Invariants_test; // this test wants access to the private type_
87 
88  STBase*
89  copy(std::size_t n, void* buf) const override;
90  STBase*
91  move(std::size_t n, void* buf) override;
92 
93  friend class detail::STVar;
94 };
95 
96 using SLE = STLedgerEntry;
97 
99  : STLedgerEntry(Keylet(type, key))
100 {
101 }
102 
104  : STLedgerEntry(sit, index)
105 {
106 }
107 
112 inline uint256 const&
114 {
115  return key_;
116 }
117 
118 inline LedgerEntryType
120 {
121  return type_;
122 }
123 
124 } // namespace ripple
125 
126 #endif
ripple::STLedgerEntry::move
STBase * move(std::size_t n, void *buf) override
Definition: STLedgerEntry.cpp:98
ripple::STLedgerEntry::setSLEType
void setSLEType()
Definition: STLedgerEntry.cpp:61
ripple::STLedgerEntry::key
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
Definition: STLedgerEntry.h:113
ripple::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:38
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::STLedgerEntry::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STLedgerEntry.cpp:117
ripple::STLedgerEntry
Definition: STLedgerEntry.h:30
std::string
STL class.
std::shared_ptr< STLedgerEntry >
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::STLedgerEntry::key_
uint256 key_
Definition: STLedgerEntry.h:32
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STLedgerEntry::getFullText
std::string getFullText() const override
Definition: STLedgerEntry.cpp:74
ripple::STLedgerEntry::Invariants_test
friend Invariants_test
Definition: STLedgerEntry.h:86
ripple::base_uint< 256 >
ripple::STLedgerEntry::getText
std::string getText() const override
Definition: STLedgerEntry.cpp:110
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(Keylet const &k)
Create an empty object with the given key and type.
Definition: STLedgerEntry.cpp:32
ripple::SerialIter
Definition: Serializer.h:310
std::uint32_t
ripple::STLedgerEntry::getType
LedgerEntryType getType() const
Definition: STLedgerEntry.h:119
ripple::STObject
Definition: STObject.h:51
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::LedgerEntryType
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:53
ripple::STLedgerEntry::thread
bool thread(uint256 const &txID, std::uint32_t ledgerSeq, uint256 &prevTxID, std::uint32_t &prevLedgerID)
Definition: STLedgerEntry.cpp:133
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
std::size_t
ripple::STLedgerEntry::getSType
SerializedTypeID getSType() const override
Definition: STLedgerEntry.cpp:104
ripple::STLedgerEntry::type_
LedgerEntryType type_
Definition: STLedgerEntry.h:33
ripple::STLedgerEntry::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STLedgerEntry.cpp:92
ripple::STLedgerEntry::isThreadedType
bool isThreadedType() const
Definition: STLedgerEntry.cpp:127
ripple::detail::STVar
Definition: STVar.h:49
Json::Value
Represents a JSON value.
Definition: json_value.h:145