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/beast/utility/Journal.h>
24 #include <ripple/protocol/STArray.h>
25 #include <ripple/protocol/STLedgerEntry.h>
26 #include <ripple/protocol/TER.h>
27 #include <boost/container/flat_set.hpp>
28 #include <boost/optional.hpp>
29 
30 namespace ripple {
31 
32 class TxMeta
33 {
34 private:
35  struct CtorHelper
36  {
37  explicit CtorHelper() = default;
38  };
39  template <class T>
40  TxMeta(
41  uint256 const& txID,
42  std::uint32_t ledger,
43  T const& data,
44  CtorHelper);
45 
46 public:
47  TxMeta(uint256 const& transactionID, std::uint32_t ledger);
48  TxMeta(uint256 const& txID, std::uint32_t ledger, Blob const&);
49  TxMeta(uint256 const& txID, std::uint32_t ledger, std::string const&);
50  TxMeta(uint256 const& txID, std::uint32_t ledger, STObject const&);
51 
52  uint256 const&
54  {
55  return mTransactionID;
56  }
59  {
60  return mLedger;
61  }
62  int
63  getResult() const
64  {
65  return mResult;
66  }
67  TER
68  getResultTER() const
69  {
70  return TER::fromInt(mResult);
71  }
73  getIndex() const
74  {
75  return mIndex;
76  }
77 
78  void
79  setAffectedNode(uint256 const&, SField const& type, std::uint16_t nodeType);
80  STObject&
81  getAffectedNode(SLE::ref node, SField const& type); // create if needed
82  STObject&
83  getAffectedNode(uint256 const&);
84 
86  boost::container::flat_set<AccountID>
88 
91  {
92  return getAsObject().getJson(p);
93  }
94  void
96 
97  STObject
98  getAsObject() const;
99  STArray&
101  {
102  return (mNodes);
103  }
104 
105  void
106  setDeliveredAmount(STAmount const& delivered)
107  {
108  mDelivered.reset(delivered);
109  }
110 
111  STAmount
113  {
114  assert(hasDeliveredAmount());
115  return *mDelivered;
116  }
117 
118  bool
120  {
121  return static_cast<bool>(mDelivered);
122  }
123 
124 private:
128  int mResult;
129 
130  boost::optional<STAmount> mDelivered;
131 
133 };
134 
135 } // namespace ripple
136 
137 #endif
ripple::TxMeta::mResult
int mResult
Definition: TxMeta.h:128
std::string
STL class.
std::shared_ptr
STL class.
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
ripple::TxMeta::getAsObject
STObject getAsObject() const
Definition: TxMeta.cpp:205
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::mIndex
std::uint32_t mIndex
Definition: TxMeta.h:127
ripple::TxMeta::TxMeta
TxMeta(uint256 const &txID, std::uint32_t ledger, T const &data, CtorHelper)
Definition: TxMeta.cpp:30
ripple::TxMeta::getTxID
uint256 const & getTxID()
Definition: TxMeta.h:53
ripple::TxMeta::CtorHelper
Definition: TxMeta.h:35
ripple::TxMeta::CtorHelper::CtorHelper
CtorHelper()=default
ripple::TxMeta::mNodes
STArray mNodes
Definition: TxMeta.h:132
ripple::TxMeta
Definition: TxMeta.h:32
ripple::base_uint< 256 >
ripple::TxMeta::getResultTER
TER getResultTER() const
Definition: TxMeta.h:68
ripple::TxMeta::mTransactionID
uint256 mTransactionID
Definition: TxMeta.h:125
ripple::TxMeta::mLedger
std::uint32_t mLedger
Definition: TxMeta.h:126
ripple::TERSubset< CanCvtToTER >
ripple::STArray
Definition: STArray.h:28
ripple::TxMeta::addRaw
void addRaw(Serializer &, TER, std::uint32_t index)
Definition: TxMeta.cpp:218
ripple::TxMeta::mDelivered
boost::optional< STAmount > mDelivered
Definition: TxMeta.h:130
ripple::STAmount
Definition: STAmount.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::TxMeta::getResult
int getResult() const
Definition: TxMeta.h:63
ripple::TxMeta::getJson
Json::Value getJson(JsonOptions p) const
Definition: TxMeta.h:90
ripple::Serializer
Definition: Serializer.h:39
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:100
ripple::TxMeta::getAffectedNode
STObject & getAffectedNode(SLE::ref node, SField const &type)
Definition: TxMeta.cpp:173
ripple::SField
Identifies fields.
Definition: SField.h:109
ripple::TERSubset< CanCvtToTER >::fromInt
static constexpr TERSubset fromInt(int from)
Definition: TER.h:345
ripple::TxMeta::hasDeliveredAmount
bool hasDeliveredAmount() const
Definition: TxMeta.h:119
ripple::TxMeta::setDeliveredAmount
void setDeliveredAmount(STAmount const &delivered)
Definition: TxMeta.h:106
ripple::TxMeta::getLgrSeq
std::uint32_t getLgrSeq()
Definition: TxMeta.h:58
ripple::TxMeta::getDeliveredAmount
STAmount getDeliveredAmount() const
Definition: TxMeta.h:112
ripple::STObject::getJson
virtual Json::Value getJson(JsonOptions options) const override
Definition: STObject.cpp:698
ripple::TxMeta::getIndex
std::uint32_t getIndex() const
Definition: TxMeta.h:73
ripple::TxMeta::setAffectedNode
void setAffectedNode(uint256 const &, SField const &type, std::uint16_t nodeType)
Definition: TxMeta.cpp:90
Json::Value
Represents a JSON value.
Definition: json_value.h:145