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 
33 #include <functional>
34 
35 namespace ripple {
36 
37 enum TxnSql : char {
38  txnSqlNew = 'N',
40  txnSqlHeld = 'H',
44 };
45 
46 class STTx final : public STObject, public CountedObject<STTx>
47 {
50 
51 public:
52  static std::size_t const minMultiSigners = 1;
53 
54  // if rules are not supplied then the largest possible value is returned
55  static std::size_t
56  maxMultiSigners(Rules const* rules = 0)
57  {
58  if (rules && !rules->enabled(featureExpandedSignerList))
59  return 8;
60 
61  return 32;
62  }
63 
64  STTx() = delete;
65  STTx(STTx const& other) = default;
66  STTx&
67  operator=(STTx const& other) = delete;
68 
69  explicit STTx(SerialIter& sit);
70  explicit STTx(SerialIter&& sit);
71  explicit STTx(STObject&& object);
72 
79  STTx(TxType type, std::function<void(STObject&)> assembler);
80 
81  // STObject functions.
83  getSType() const override;
84 
86  getFullText() const override;
87 
88  // Outer transaction functions / signature functions.
89  Blob
90  getSignature() const;
91 
92  uint256
93  getSigningHash() const;
94 
95  TxType
96  getTxnType() const;
97 
98  Blob
99  getSigningPubKey() const;
100 
101  SeqProxy
102  getSeqProxy() const;
103 
104  boost::container::flat_set<AccountID>
105  getMentionedAccounts() const;
106 
107  uint256
108  getTransactionID() const;
109 
111  getJson(JsonOptions options) const override;
112 
114  getJson(JsonOptions options, bool binary) const;
115 
116  void
117  sign(PublicKey const& publicKey, SecretKey const& secretKey);
118 
122  enum class RequireFullyCanonicalSig : bool { no, yes };
124  checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
125  const;
126 
127  // SQL Functions with metadata.
128  static std::string const&
130 
132  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
133  const;
134 
136  getMetaSQL(
137  Serializer rawTxn,
138  std::uint32_t inLedger,
139  char status,
140  std::string const& escapedMetaData) const;
141 
142 private:
144  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
145 
148  RequireFullyCanonicalSig requireCanonicalSig,
149  Rules const& rules) const;
150 
151  STBase*
152  copy(std::size_t n, void* buf) const override;
153  STBase*
154  move(std::size_t n, void* buf) override;
155 
156  friend class detail::STVar;
157 };
158 
159 bool
161 
170 sterilize(STTx const& stx);
171 
173 bool
174 isPseudoTx(STObject const& tx);
175 
176 inline STTx::STTx(SerialIter&& sit) : STTx(sit)
177 {
178 }
179 
180 inline TxType
182 {
183  return tx_type_;
184 }
185 
186 inline Blob
188 {
189  return getFieldVL(sfSigningPubKey);
190 }
191 
192 inline uint256
194 {
195  return tid_;
196 }
197 
198 } // namespace ripple
199 
200 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:181
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:280
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
std::shared_ptr
STL class.
functional
std::vector< unsigned char >
ripple::sfSigningPubKey
const SF_VL sfSigningPubKey
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:106
ripple::TxType
TxType
Transaction type identifiers.
Definition: TxFormats.h:56
ripple::STTx::getSigningHash
uint256 getSigningHash() const
Definition: STTx.cpp:165
ripple::STTx::getSeqProxy
SeqProxy getSeqProxy() const
Definition: STTx.cpp:184
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:268
std::function
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:611
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:576
ripple::Expected
Definition: Expected.h:132
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:43
ripple::featureExpandedSignerList
const uint256 featureExpandedSignerList
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:547
ripple::PublicKey
A public key.
Definition: PublicKey.h:61
ripple::STTx::getFullText
std::string getFullText() const override
Definition: STTx.cpp:121
ripple::txnSqlValidated
@ txnSqlValidated
Definition: STTx.h:41
ripple::STTx
Definition: STTx.h:46
ripple::TxnSql
TxnSql
Definition: STTx.h:37
ripple::SerialIter
Definition: Serializer.h:311
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:187
ripple::STTx::maxMultiSigners
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:56
std::uint32_t
ripple::SecretKey
A secret key.
Definition: SecretKey.h:36
ripple::txnSqlHeld
@ txnSqlHeld
Definition: STTx.h:40
ripple::STTx::sign
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:199
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:231
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:193
ripple::Serializer
Definition: Serializer.h:40
ripple::STObject
Definition: STObject.h:55
ripple::STTx::checkSingleSign
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:310
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:567
ripple::JsonOptions
Note, should be treated as flags that can be | and &.
Definition: STBase.h:35
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:210
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
ripple::STTx::getSignature
Blob getSignature() const
Definition: STTx.cpp:171
ripple::txnSqlIncluded
@ txnSqlIncluded
Definition: STTx.h:42
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:48
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:132
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:39
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:38
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:52
ripple::STTx::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.cpp:102
std::size_t
ripple::STTx::checkMultiSign
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:350
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.cpp:108
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:122
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.cpp:115
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:49