rippled
TxMeta.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_APP_TX_TRANSACTIONMETA_H_INCLUDED
21 #define RIPPLE_APP_TX_TRANSACTIONMETA_H_INCLUDED
22 
23 #include <ripple/protocol/STLedgerEntry.h>
24 #include <ripple/protocol/STArray.h>
25 #include <ripple/protocol/TER.h>
26 #include <ripple/beast/utility/Journal.h>
27 #include <boost/container/flat_set.hpp>
28 #include <boost/optional.hpp>
29 
30 namespace ripple {
31 
32 // VFALCO Move to ripple/app/ledger/detail, rename to TxMeta
33 class TxMeta
34 {
35 public:
37  using ref = const pointer&;
38 
39 private:
40  struct CtorHelper
41  {
42  explicit CtorHelper() = default;
43  };
44  template<class T>
45  TxMeta (uint256 const& txID, std::uint32_t ledger, T const& data, CtorHelper);
46 public:
47  TxMeta ()
48  : mLedger (0)
49  , mIndex (static_cast<std::uint32_t> (-1))
50  , mResult (255)
51  {
52  }
53 
54  TxMeta (uint256 const& txID, std::uint32_t ledger, std::uint32_t index)
55  : mTransactionID (txID)
56  , mLedger (ledger)
57  , mIndex (static_cast<std::uint32_t> (-1))
58  , mResult (255)
59  {
60  }
61 
62  TxMeta (uint256 const& txID, std::uint32_t ledger, Blob const&);
63  TxMeta (uint256 const& txID, std::uint32_t ledger, std::string const&);
64  TxMeta (uint256 const& txID, std::uint32_t ledger, STObject const&);
65 
66  void init (uint256 const& transactionID, std::uint32_t ledger);
67  void clear ()
68  {
69  mNodes.clear ();
70  }
71  void swap (TxMeta&) noexcept;
72 
73  uint256 const& getTxID ()
74  {
75  return mTransactionID;
76  }
78  {
79  return mLedger;
80  }
81  int getResult () const
82  {
83  return mResult;
84  }
85  TER getResultTER () const
86  {
87  return TER::fromInt (mResult);
88  }
90  {
91  return mIndex;
92  }
93 
94  bool isNodeAffected (uint256 const& ) const;
95  void setAffectedNode (uint256 const& , SField const& type,
96  std::uint16_t nodeType);
97  STObject& getAffectedNode (SLE::ref node, SField const& type); // create if needed
98  STObject& getAffectedNode (uint256 const& );
99  const STObject& peekAffectedNode (uint256 const& ) const;
100 
102  boost::container::flat_set<AccountID>
104 
106  {
107  return getAsObject ().getJson (p);
108  }
109  void addRaw (Serializer&, TER, std::uint32_t index);
110 
111  STObject getAsObject () const;
113  {
114  return (mNodes);
115  }
116 
117  void setDeliveredAmount (STAmount const& delivered)
118  {
119  mDelivered.reset (delivered);
120  }
121 
123  {
124  assert (hasDeliveredAmount ());
125  return *mDelivered;
126  }
127 
128  bool hasDeliveredAmount () const
129  {
130  return static_cast <bool> (mDelivered);
131  }
132 
133  static bool thread (STObject& node, uint256 const& prevTxID, std::uint32_t prevLgrID);
134 
135 private:
139  int mResult;
140 
141  boost::optional <STAmount> mDelivered;
142 
144 };
145 
146 } // ripple
147 
148 #endif
ripple::TxMeta::mResult
int mResult
Definition: TxMeta.h:139
ripple::TxMeta::clear
void clear()
Definition: TxMeta.h:67
std::string
STL class.
std::shared_ptr
STL class.
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::TxMeta::TxMeta
TxMeta(uint256 const &txID, std::uint32_t ledger, std::uint32_t index)
Definition: TxMeta.h:54
ripple::TxMeta::getAsObject
STObject getAsObject() const
Definition: TxMeta.cpp:242
ripple::TxMeta::getAffectedAccounts
boost::container::flat_set< AccountID > getAffectedAccounts(beast::Journal j) const
Return a list of accounts affected by this transaction.
Definition: TxMeta.cpp:115
std::vector< unsigned char >
ripple::TxMeta::TxMeta
TxMeta()
Definition: TxMeta.h:47
ripple::TxMeta::mIndex
std::uint32_t mIndex
Definition: TxMeta.h:138
ripple::TxMeta::getTxID
uint256 const & getTxID()
Definition: TxMeta.h:73
ripple::TxMeta::CtorHelper
Definition: TxMeta.h:40
ripple::TxMeta::isNodeAffected
bool isNodeAffected(uint256 const &) const
Definition: TxMeta.cpp:81
ripple::TxMeta::CtorHelper::CtorHelper
CtorHelper()=default
ripple::TxMeta::swap
void swap(TxMeta &) noexcept
Definition: TxMeta.cpp:216
ripple::TxMeta::mNodes
STArray mNodes
Definition: TxMeta.h:143
ripple::TxMeta
Definition: TxMeta.h:33
ripple::base_uint< 256 >
ripple::TxMeta::getResultTER
TER getResultTER() const
Definition: TxMeta.h:85
ripple::TxMeta::mTransactionID
uint256 mTransactionID
Definition: TxMeta.h:136
ripple::STArray::clear
void clear()
Definition: STArray.h:134
ripple::TxMeta::mLedger
std::uint32_t mLedger
Definition: TxMeta.h:137
ripple::TERSubset< CanCvtToTER >
ripple::STArray
Definition: STArray.h:28
ripple::TxMeta::addRaw
void addRaw(Serializer &, TER, std::uint32_t index)
Definition: TxMeta.cpp:254
ripple::TxMeta::init
void init(uint256 const &transactionID, std::uint32_t ledger)
Definition: TxMeta.cpp:208
ripple::TxMeta::mDelivered
boost::optional< STAmount > mDelivered
Definition: TxMeta.h:141
ripple::STAmount
Definition: STAmount.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::uint32_t
ripple::TxMeta::getResult
int getResult() const
Definition: TxMeta.h:81
ripple::TxMeta::getJson
Json::Value getJson(JsonOptions p) const
Definition: TxMeta.h:105
ripple::TxMeta::thread
static bool thread(STObject &node, uint256 const &prevTxID, std::uint32_t prevLgrID)
Definition: TxMeta.cpp:222
ripple::Serializer
Definition: Serializer.h:43
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::TxMeta::getNodes
STArray & getNodes()
Definition: TxMeta.h:112
ripple::TxMeta::getAffectedNode
STObject & getAffectedNode(SLE::ref node, SField const &type)
Definition: TxMeta.cpp:166
ripple::SField
Identifies fields.
Definition: SField.h:112
ripple::TERSubset< CanCvtToTER >::fromInt
static constexpr TERSubset fromInt(int from)
Definition: TER.h:323
std
STL namespace.
ripple::TxMeta::hasDeliveredAmount
bool hasDeliveredAmount() const
Definition: TxMeta.h:128
ripple::TxMeta::setDeliveredAmount
void setDeliveredAmount(STAmount const &delivered)
Definition: TxMeta.h:117
ripple::TxMeta::getLgrSeq
std::uint32_t getLgrSeq()
Definition: TxMeta.h:77
ripple::TxMeta::getDeliveredAmount
STAmount getDeliveredAmount() const
Definition: TxMeta.h:122
ripple::STObject::getJson
virtual Json::Value getJson(JsonOptions options) const override
Definition: STObject.cpp:657
ripple::TxMeta::getIndex
std::uint32_t getIndex() const
Definition: TxMeta.h:89
ripple::TxMeta::peekAffectedNode
const STObject & peekAffectedNode(uint256 const &) const
Definition: TxMeta.cpp:196
ripple::TxMeta::setAffectedNode
void setAffectedNode(uint256 const &, SField const &type, std::uint16_t nodeType)
Definition: TxMeta.cpp:92
Json::Value
Represents a JSON value.
Definition: json_value.h:141