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/protocol/PublicKey.h>
24 #include <ripple/protocol/STObject.h>
25 #include <ripple/protocol/SecretKey.h>
26 #include <ripple/protocol/SeqProxy.h>
27 #include <ripple/protocol/TxFormats.h>
28 #include <boost/container/flat_set.hpp>
29 #include <functional>
30 
31 namespace ripple {
32 
33 enum TxnSql : char {
34  txnSqlNew = 'N',
36  txnSqlHeld = 'H',
40 };
41 
42 class STTx final : public STObject, public CountedObject<STTx>
43 {
44 public:
45  static std::size_t const minMultiSigners = 1;
46  static std::size_t const maxMultiSigners = 8;
47 
48 public:
49  STTx() = delete;
50  STTx&
51  operator=(STTx const& other) = delete;
52 
53  STTx(STTx const& other) = default;
54 
55  explicit STTx(SerialIter& sit) noexcept(false);
56  explicit STTx(SerialIter&& sit) noexcept(false) : STTx(sit)
57  {
58  }
59 
60  explicit STTx(STObject&& object) noexcept(false);
61 
68  STTx(TxType type, std::function<void(STObject&)> assembler);
69 
70  STBase*
71  copy(std::size_t n, void* buf) const override
72  {
73  return emplace(n, buf, *this);
74  }
75 
76  STBase*
77  move(std::size_t n, void* buf) override
78  {
79  return emplace(n, buf, std::move(*this));
80  }
81 
82  // STObject functions.
84  getSType() const override
85  {
86  return STI_TRANSACTION;
87  }
89  getFullText() const override;
90 
91  // Outer transaction functions / signature functions.
92  Blob
93  getSignature() const;
94 
95  uint256
96  getSigningHash() const;
97 
98  TxType
99  getTxnType() const
100  {
101  return tx_type_;
102  }
103 
104  Blob
106  {
107  return getFieldVL(sfSigningPubKey);
108  }
109 
110  SeqProxy
111  getSeqProxy() const;
112 
113  boost::container::flat_set<AccountID>
114  getMentionedAccounts() const;
115 
116  uint256
118  {
119  return tid_;
120  }
121 
123  getJson(JsonOptions options) const override;
125  getJson(JsonOptions options, bool binary) const;
126 
127  void
128  sign(PublicKey const& publicKey, SecretKey const& secretKey);
129 
133  enum class RequireFullyCanonicalSig : bool { no, yes };
135  checkSign(RequireFullyCanonicalSig requireCanonicalSig) const;
136 
137  // SQL Functions with metadata.
138  static std::string const&
140 
142  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
143  const;
144 
146  getMetaSQL(
147  Serializer rawTxn,
148  std::uint32_t inLedger,
149  char status,
150  std::string const& escapedMetaData) const;
151 
152 private:
154  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
155 
157  checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const;
158 
161 };
162 
163 bool
165 
174 sterilize(STTx const& stx);
175 
177 bool
178 isPseudoTx(STObject const& tx);
179 
180 } // namespace ripple
181 
182 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:99
ripple::STTx::checkMultiSign
std::pair< bool, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:314
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:244
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
std::shared_ptr
STL class.
ripple::STTx::checkSign
std::pair< bool, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:191
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
functional
std::pair
std::vector< unsigned char >
ripple::sfSigningPubKey
const SF_VL sfSigningPubKey
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
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:232
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:73
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:540
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:39
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:511
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:71
ripple::STTx::getFullText
std::string getFullText() const override
Definition: STTx.cpp:101
ripple::txnSqlValidated
@ txnSqlValidated
Definition: STTx.h:37
ripple::STTx
Definition: STTx.h:42
ripple::TxnSql
TxnSql
Definition: STTx.h:33
ripple::SerialIter
Definition: Serializer.h:308
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:105
std::uint32_t
ripple::STTx::checkSingleSign
std::pair< bool, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:274
ripple::SecretKey
A secret key.
Definition: SecretKey.h:36
ripple::txnSqlHeld
@ txnSqlHeld
Definition: STTx.h:36
ripple::STTx::sign
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:180
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:210
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:117
ripple::Serializer
Definition: Serializer.h:39
ripple::TxType
TxType
Transaction type identifiers.
Definition: TxFormats.h:33
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::sterilize
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition: STTx.cpp:531
ripple::STTx::maxMultiSigners
static const std::size_t maxMultiSigners
Definition: STTx.h:46
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:38
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:159
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:112
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:35
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::txnSqlNew
@ txnSqlNew
Definition: STTx.h:34
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:45
std::size_t
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.h:77
ripple::STTx::STTx
STTx(SerialIter &&sit) noexcept(false)
Definition: STTx.h:56
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:133
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.h:84
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:160