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/Feature.h>
25 #include <ripple/protocol/PublicKey.h>
26 #include <ripple/protocol/Rules.h>
27 #include <ripple/protocol/STObject.h>
28 #include <ripple/protocol/SecretKey.h>
29 #include <ripple/protocol/SeqProxy.h>
30 #include <ripple/protocol/TxFormats.h>
31 #include <boost/container/flat_set.hpp>
32 #include <functional>
33 
34 namespace ripple {
35 
36 enum TxnSql : char {
37  txnSqlNew = 'N',
39  txnSqlHeld = 'H',
43 };
44 
45 class STTx final : public STObject, public CountedObject<STTx>
46 {
49 
50 public:
51  static std::size_t const minMultiSigners = 1;
52 
53  // if rules are not supplied then the largest possible value is returned
54  static std::size_t
55  maxMultiSigners(Rules const* rules = 0)
56  {
57  if (rules && !rules->enabled(featureExpandedSignerList))
58  return 8;
59 
60  return 32;
61  }
62 
63  STTx() = delete;
64  STTx(STTx const& other) = default;
65  STTx&
66  operator=(STTx const& other) = delete;
67 
68  explicit STTx(SerialIter& sit);
69  explicit STTx(SerialIter&& sit);
70  explicit STTx(STObject&& object);
71 
78  STTx(TxType type, std::function<void(STObject&)> assembler);
79 
80  // STObject functions.
82  getSType() const override;
83 
85  getFullText() const override;
86 
87  // Outer transaction functions / signature functions.
88  Blob
89  getSignature() const;
90 
91  uint256
92  getSigningHash() const;
93 
94  TxType
95  getTxnType() const;
96 
97  Blob
98  getSigningPubKey() const;
99 
100  SeqProxy
101  getSeqProxy() const;
102 
103  boost::container::flat_set<AccountID>
104  getMentionedAccounts() const;
105 
106  uint256
107  getTransactionID() const;
108 
110  getJson(JsonOptions options) const override;
112  getJson(JsonOptions options, bool binary) const;
113 
114  void
115  sign(PublicKey const& publicKey, SecretKey const& secretKey);
116 
120  enum class RequireFullyCanonicalSig : bool { no, yes };
122  checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
123  const;
124 
125  // SQL Functions with metadata.
126  static std::string const&
128 
130  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
131  const;
132 
134  getMetaSQL(
135  Serializer rawTxn,
136  std::uint32_t inLedger,
137  char status,
138  std::string const& escapedMetaData) const;
139 
140 private:
142  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
143 
146  RequireFullyCanonicalSig requireCanonicalSig,
147  Rules const& rules) const;
148 
149  STBase*
150  copy(std::size_t n, void* buf) const override;
151  STBase*
152  move(std::size_t n, void* buf) override;
153 
154  friend class detail::STVar;
155 };
156 
157 bool
159 
168 sterilize(STTx const& stx);
169 
171 bool
172 isPseudoTx(STObject const& tx);
173 
174 inline STTx::STTx(SerialIter&& sit) : STTx(sit)
175 {
176 }
177 
178 inline TxType
180 {
181  return tx_type_;
182 }
183 
184 inline Blob
186 {
187  return getFieldVL(sfSigningPubKey);
188 }
189 
190 inline uint256
192 {
193  return tid_;
194 }
195 
196 } // namespace ripple
197 
198 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:179
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:263
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:251
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:559
ripple::Expected
Definition: Expected.h:132
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:42
ripple::featureExpandedSignerList
const uint256 featureExpandedSignerList
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:530
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:40
ripple::STTx
Definition: STTx.h:45
ripple::TxnSql
TxnSql
Definition: STTx.h:36
ripple::SerialIter
Definition: Serializer.h:310
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:185
ripple::STTx::maxMultiSigners
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:55
std::uint32_t
ripple::SecretKey
A secret key.
Definition: SecretKey.h:36
ripple::txnSqlHeld
@ txnSqlHeld
Definition: STTx.h:39
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:229
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:191
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:293
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:550
ripple::STTx::RequireFullyCanonicalSig::yes
@ yes
ripple::STTx::STTx
STTx()=delete
ripple::STTx::checkSign
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:209
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:41
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:47
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:131
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:38
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
ripple::txnSqlNew
@ txnSqlNew
Definition: STTx.h:37
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:51
ripple::STTx::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.cpp:101
std::size_t
ripple::STTx::checkMultiSign
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:333
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:120
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:48