rippled
STTx.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_STTX_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STTX_H_INCLUDED
22 
23 #include <ripple/basics/Expected.h>
24 #include <ripple/protocol/PublicKey.h>
25 #include <ripple/protocol/STObject.h>
26 #include <ripple/protocol/SecretKey.h>
27 #include <ripple/protocol/SeqProxy.h>
28 #include <ripple/protocol/TxFormats.h>
29 #include <boost/container/flat_set.hpp>
30 #include <functional>
31 
32 namespace ripple {
33 
34 enum TxnSql : char {
35  txnSqlNew = 'N',
37  txnSqlHeld = 'H',
41 };
42 
43 class STTx final : public STObject, public CountedObject<STTx>
44 {
47 
48 public:
49  static std::size_t const minMultiSigners = 1;
50  static std::size_t const maxMultiSigners = 8;
51 
52  STTx() = delete;
53  STTx(STTx const& other) = default;
54  STTx&
55  operator=(STTx const& other) = delete;
56 
57  explicit STTx(SerialIter& sit);
58  explicit STTx(SerialIter&& sit);
59  explicit STTx(STObject&& object);
60 
67  STTx(TxType type, std::function<void(STObject&)> assembler);
68 
69  // STObject functions.
71  getSType() const override;
72 
74  getFullText() const override;
75 
76  // Outer transaction functions / signature functions.
77  Blob
78  getSignature() const;
79 
80  uint256
81  getSigningHash() const;
82 
83  TxType
84  getTxnType() const;
85 
86  Blob
87  getSigningPubKey() const;
88 
89  SeqProxy
90  getSeqProxy() const;
91 
92  boost::container::flat_set<AccountID>
93  getMentionedAccounts() const;
94 
95  uint256
96  getTransactionID() const;
97 
99  getJson(JsonOptions options) const override;
101  getJson(JsonOptions options, bool binary) const;
102 
103  void
104  sign(PublicKey const& publicKey, SecretKey const& secretKey);
105 
109  enum class RequireFullyCanonicalSig : bool { no, yes };
111  checkSign(RequireFullyCanonicalSig requireCanonicalSig) const;
112 
113  // SQL Functions with metadata.
114  static std::string const&
116 
118  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
119  const;
120 
122  getMetaSQL(
123  Serializer rawTxn,
124  std::uint32_t inLedger,
125  char status,
126  std::string const& escapedMetaData) const;
127 
128 private:
130  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
131 
133  checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const;
134 
135  STBase*
136  copy(std::size_t n, void* buf) const override;
137  STBase*
138  move(std::size_t n, void* buf) override;
139 
140  friend class detail::STVar;
141 };
142 
143 bool
145 
154 sterilize(STTx const& stx);
155 
157 bool
158 isPseudoTx(STObject const& tx);
159 
160 inline STTx::STTx(SerialIter&& sit) : STTx(sit)
161 {
162 }
163 
164 inline TxType
166 {
167  return tx_type_;
168 }
169 
170 inline Blob
172 {
173  return getFieldVL(sfSigningPubKey);
174 }
175 
176 inline uint256
178 {
179  return tid_;
180 }
181 
182 } // namespace ripple
183 
184 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:165
ripple::STTx::operator=
STTx & operator=(STTx const &other)=delete
ripple::STTx::getMetaSQL
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition: STTx.cpp:260
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
std::shared_ptr
STL class.
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
functional
std::vector< unsigned char >
ripple::sfSigningPubKey
const SF_VL sfSigningPubKey
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::TxType
TxType
Transaction type identifiers.
Definition: TxFormats.h:56
ripple::STTx::getSigningHash
uint256 getSigningHash() const
Definition: STTx.cpp:164
ripple::STTx::getSeqProxy
SeqProxy getSeqProxy() const
Definition: STTx.cpp:183
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:248
std::function
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:595
ripple::STTx::RequireFullyCanonicalSig::no
@ no
ripple::base_uint< 256 >
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:554
ripple::Expected
Definition: Expected.h:129
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:40
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:525
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::STTx::getFullText
std::string getFullText() const override
Definition: STTx.cpp:120
ripple::txnSqlValidated
@ txnSqlValidated
Definition: STTx.h:38
ripple::STTx
Definition: STTx.h:43
ripple::TxnSql
TxnSql
Definition: STTx.h:34
ripple::SerialIter
Definition: Serializer.h:310
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:171
std::uint32_t
ripple::SecretKey
A secret key.
Definition: SecretKey.h:36
ripple::txnSqlHeld
@ txnSqlHeld
Definition: STTx.h:37
ripple::STTx::sign
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:198
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:226
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:177
ripple::Serializer
Definition: Serializer.h:39
ripple::STObject
Definition: STObject.h:51
ripple::STTx::checkSingleSign
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:290
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sterilize
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition: STTx.cpp:545
ripple::STTx::checkSign
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:209
ripple::STTx::maxMultiSigners
static const std::size_t maxMultiSigners
Definition: STTx.h:50
ripple::STTx::RequireFullyCanonicalSig::yes
@ yes
ripple::STTx::STTx
STTx()=delete
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:66
ripple::STTx::getSignature
Blob getSignature() const
Definition: STTx.cpp:170
ripple::txnSqlIncluded
@ txnSqlIncluded
Definition: STTx.h:39
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:45
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:131
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:36
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::txnSqlNew
@ txnSqlNew
Definition: STTx.h:35
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:49
ripple::STTx::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.cpp:101
std::size_t
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.cpp:107
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:109
ripple::STTx::checkMultiSign
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:330
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.cpp:114
ripple::detail::STVar
Definition: STVar.h:49
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::STTx::tx_type_
TxType tx_type_
Definition: STTx.h:46