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 {
45 public:
46  static std::size_t const minMultiSigners = 1;
47  static std::size_t const maxMultiSigners = 8;
48 
49 public:
50  STTx() = delete;
51  STTx&
52  operator=(STTx const& other) = delete;
53 
54  STTx(STTx const& other) = default;
55 
56  explicit STTx(SerialIter& sit) noexcept(false);
57  explicit STTx(SerialIter&& sit) noexcept(false) : STTx(sit)
58  {
59  }
60 
61  explicit STTx(STObject&& object) noexcept(false);
62 
69  STTx(TxType type, std::function<void(STObject&)> assembler);
70 
71  STBase*
72  copy(std::size_t n, void* buf) const override
73  {
74  return emplace(n, buf, *this);
75  }
76 
77  STBase*
78  move(std::size_t n, void* buf) override
79  {
80  return emplace(n, buf, std::move(*this));
81  }
82 
83  // STObject functions.
85  getSType() const override
86  {
87  return STI_TRANSACTION;
88  }
90  getFullText() const override;
91 
92  // Outer transaction functions / signature functions.
93  Blob
94  getSignature() const;
95 
96  uint256
97  getSigningHash() const;
98 
99  TxType
100  getTxnType() const
101  {
102  return tx_type_;
103  }
104 
105  Blob
107  {
108  return getFieldVL(sfSigningPubKey);
109  }
110 
111  SeqProxy
112  getSeqProxy() const;
113 
114  boost::container::flat_set<AccountID>
115  getMentionedAccounts() const;
116 
117  uint256
119  {
120  return tid_;
121  }
122 
124  getJson(JsonOptions options) const override;
126  getJson(JsonOptions options, bool binary) const;
127 
128  void
129  sign(PublicKey const& publicKey, SecretKey const& secretKey);
130 
134  enum class RequireFullyCanonicalSig : bool { no, yes };
136  checkSign(RequireFullyCanonicalSig requireCanonicalSig) const;
137 
138  // SQL Functions with metadata.
139  static std::string const&
141 
143  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
144  const;
145 
147  getMetaSQL(
148  Serializer rawTxn,
149  std::uint32_t inLedger,
150  char status,
151  std::string const& escapedMetaData) const;
152 
153 private:
155  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
156 
158  checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const;
159 
162 };
163 
164 bool
166 
175 sterilize(STTx const& stx);
176 
178 bool
179 isPseudoTx(STObject const& tx);
180 
181 } // namespace ripple
182 
183 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:100
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:241
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:145
ripple::STTx::getSeqProxy
SeqProxy getSeqProxy() const
Definition: STTx.cpp:164
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:229
std::function
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:568
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:149
ripple::STTx::RequireFullyCanonicalSig::no
@ no
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:75
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:535
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:506
ripple::PublicKey
A public key.
Definition: PublicKey.h:59
ripple::STTx::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.h:72
ripple::STTx::getFullText
std::string getFullText() const override
Definition: STTx.cpp:101
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:106
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:179
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:207
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:118
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:271
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:526
ripple::STTx::checkSign
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:190
ripple::STTx::maxMultiSigners
static const std::size_t maxMultiSigners
Definition: STTx.h:47
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:62
ripple::STTx::getSignature
Blob getSignature() const
Definition: STTx.cpp:151
ripple::txnSqlIncluded
@ txnSqlIncluded
Definition: STTx.h:39
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:160
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:112
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:46
std::size_t
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.h:78
ripple::STTx::STTx
STTx(SerialIter &&sit) noexcept(false)
Definition: STTx.h:57
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:134
ripple::STTx::checkMultiSign
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:311
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.h:85
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::STI_TRANSACTION
@ STI_TRANSACTION
Definition: SField.h:79
ripple::STTx::tx_type_
TxType tx_type_
Definition: STTx.h:161