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:
35  static char const*
37  {
38  return "STLedgerEntry";
39  }
40 
43 
45  explicit STLedgerEntry(Keylet const& k);
46 
48  : STLedgerEntry(Keylet(type, key))
49  {
50  }
51 
52  STLedgerEntry(SerialIter& sit, uint256 const& index);
53  STLedgerEntry(SerialIter&& sit, uint256 const& index)
54  : STLedgerEntry(sit, index)
55  {
56  }
57 
58  STLedgerEntry(STObject const& object, uint256 const& index);
59 
60  STBase*
61  copy(std::size_t n, void* buf) const override
62  {
63  return emplace(n, buf, *this);
64  }
65 
66  STBase*
67  move(std::size_t n, void* buf) override
68  {
69  return emplace(n, buf, std::move(*this));
70  }
71 
73  getSType() const override
74  {
75  return STI_LEDGERENTRY;
76  }
77 
79  getFullText() const override;
80 
82  getText() const override;
83 
85  getJson(JsonOptions options) const override;
86 
91  uint256 const&
92  key() const
93  {
94  return key_;
95  }
96 
98  getType() const
99  {
100  return type_;
101  }
102 
103  // is this a ledger entry that can be threaded
104  bool
105  isThreadedType() const;
106 
107  bool
108  thread(
109  uint256 const& txID,
110  std::uint32_t ledgerSeq,
111  uint256& prevTxID,
112  std::uint32_t& prevLedgerID);
113 
114 private:
115  /* Make STObject comply with the template for this SLE type
116  Can throw
117  */
118  void
119  setSLEType();
120 
121 private:
124 };
125 
127 
128 } // namespace ripple
129 
130 #endif
ripple::STLedgerEntry::setSLEType
void setSLEType()
Definition: STLedgerEntry.cpp:64
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:110
ripple::STLedgerEntry::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STLedgerEntry.cpp:102
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:122
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STLedgerEntry::getFullText
std::string getFullText() const override
Definition: STLedgerEntry.cpp:77
ripple::STI_LEDGERENTRY
@ STI_LEDGERENTRY
Definition: SField.h:80
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(SerialIter &&sit, uint256 const &index)
Definition: STLedgerEntry.h:53
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:92
ripple::base_uint< 256 >
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(LedgerEntryType type, uint256 const &key)
Definition: STLedgerEntry.h:47
ripple::STLedgerEntry::getText
std::string getText() const override
Definition: STLedgerEntry.cpp:95
ripple::STLedgerEntry::STLedgerEntry
STLedgerEntry(Keylet const &k)
Create an empty object with the given key and type.
Definition: STLedgerEntry.cpp:31
ripple::SerialIter
Definition: Serializer.h:308
std::uint32_t
ripple::STLedgerEntry::getType
LedgerEntryType getType() const
Definition: STLedgerEntry.h:98
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:61
ripple::STLedgerEntry::thread
bool thread(uint256 const &txID, std::uint32_t ledgerSeq, uint256 &prevTxID, std::uint32_t &prevLedgerID)
Definition: STLedgerEntry.cpp:118
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:73
ripple::STLedgerEntry::getCountedObjectName
static char const * getCountedObjectName()
Definition: STLedgerEntry.h:36
ripple::STLedgerEntry::type_
LedgerEntryType type_
Definition: STLedgerEntry.h:123
ripple::STLedgerEntry::isThreadedType
bool isThreadedType() const
Definition: STLedgerEntry.cpp:112
ripple::STLedgerEntry::move
STBase * move(std::size_t n, void *buf) override
Definition: STLedgerEntry.h:67
Json::Value
Represents a JSON value.
Definition: json_value.h:145