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 {
32  friend Invariants_test; // this test wants access to the private type_
33 
34 public:
37 
39  explicit STLedgerEntry(Keylet const& k);
40 
42  : STLedgerEntry(Keylet(type, key))
43  {
44  }
45 
46  STLedgerEntry(SerialIter& sit, uint256 const& index);
47  STLedgerEntry(SerialIter&& sit, uint256 const& index)
48  : STLedgerEntry(sit, index)
49  {
50  }
51 
52  STLedgerEntry(STObject const& object, uint256 const& index);
53 
54  STBase*
55  copy(std::size_t n, void* buf) const override
56  {
57  return emplace(n, buf, *this);
58  }
59 
60  STBase*
61  move(std::size_t n, void* buf) override
62  {
63  return emplace(n, buf, std::move(*this));
64  }
65 
67  getSType() const override
68  {
69  return STI_LEDGERENTRY;
70  }
71 
73  getFullText() const override;
74 
76  getText() const override;
77 
79  getJson(JsonOptions options) const override;
80 
85  uint256 const&
86  key() const
87  {
88  return key_;
89  }
90 
92  getType() const
93  {
94  return type_;
95  }
96 
97  // is this a ledger entry that can be threaded
98  bool
99  isThreadedType() const;
100 
101  bool
102  thread(
103  uint256 const& txID,
104  std::uint32_t ledgerSeq,
105  uint256& prevTxID,
106  std::uint32_t& prevLedgerID);
107 
108 private:
109  /* Make STObject comply with the template for this SLE type
110  Can throw
111  */
112  void
113  setSLEType();
114 
115 private:
118 };
119 
121 
122 } // namespace ripple
123 
124 #endif
ripple::STLedgerEntry::setSLEType
void setSLEType()
Definition: STLedgerEntry.cpp:71
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:109
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:116
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STLedgerEntry::getFullText
std::string getFullText() const override
Definition: STLedgerEntry.cpp:84
ripple::STI_LEDGERENTRY
@ STI_LEDGERENTRY
Definition: SField.h:80
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(SerialIter &&sit, uint256 const &index)
Definition: STLedgerEntry.h:47
ripple::STLedgerEntry::Invariants_test
friend Invariants_test
Definition: STLedgerEntry.h:32
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:149
ripple::STLedgerEntry::key
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
Definition: STLedgerEntry.h:86
ripple::base_uint< 256 >
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(LedgerEntryType type, uint256 const &key)
Definition: STLedgerEntry.h:41
ripple::STLedgerEntry::getText
std::string getText() const override
Definition: STLedgerEntry.cpp:102
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:308
std::uint32_t
ripple::STLedgerEntry::getType
LedgerEntryType getType() const
Definition: STLedgerEntry.h:92
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::STLedgerEntry::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STLedgerEntry.h:55
ripple::STLedgerEntry::thread
bool thread(uint256 const &txID, std::uint32_t ledgerSeq, uint256 &prevTxID, std::uint32_t &prevLedgerID)
Definition: STLedgerEntry.cpp:125
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:62
ripple::LedgerEntryType
LedgerEntryType
Ledger entry types.
Definition: LedgerFormats.h:36
std::size_t
ripple::STLedgerEntry::getSType
SerializedTypeID getSType() const override
Definition: STLedgerEntry.h:67
ripple::STLedgerEntry::type_
LedgerEntryType type_
Definition: STLedgerEntry.h:117
ripple::STLedgerEntry::isThreadedType
bool isThreadedType() const
Definition: STLedgerEntry.cpp:119
ripple::STLedgerEntry::move
STBase * move(std::size_t n, void *buf) override
Definition: STLedgerEntry.h:61
Json::Value
Represents a JSON value.
Definition: json_value.h:145