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/TxFormats.h>
27 #include <boost/container/flat_set.hpp>
28 #include <boost/logic/tribool.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 char const*
47  {
48  return "STTx";
49  }
50 
51  static std::size_t const minMultiSigners = 1;
52  static std::size_t const maxMultiSigners = 8;
53 
54 public:
55  STTx() = delete;
56  STTx&
57  operator=(STTx const& other) = delete;
58 
59  STTx(STTx const& other) = default;
60 
61  explicit STTx(SerialIter& sit) noexcept(false);
62  explicit STTx(SerialIter&& sit) noexcept(false) : STTx(sit)
63  {
64  }
65 
66  explicit STTx(STObject&& object) noexcept(false);
67 
74  STTx(TxType type, std::function<void(STObject&)> assembler);
75 
76  STBase*
77  copy(std::size_t n, void* buf) const override
78  {
79  return emplace(n, buf, *this);
80  }
81 
82  STBase*
83  move(std::size_t n, void* buf) override
84  {
85  return emplace(n, buf, std::move(*this));
86  }
87 
88  // STObject functions.
90  getSType() const override
91  {
92  return STI_TRANSACTION;
93  }
95  getFullText() const override;
96 
97  // Outer transaction functions / signature functions.
98  Blob
99  getSignature() const;
100 
101  uint256
102  getSigningHash() const;
103 
104  TxType
105  getTxnType() const
106  {
107  return tx_type_;
108  }
109 
110  Blob
112  {
113  return getFieldVL(sfSigningPubKey);
114  }
115 
117  getSequence() const
118  {
119  return getFieldU32(sfSequence);
120  }
121  void
123  {
124  return setFieldU32(sfSequence, seq);
125  }
126 
127  boost::container::flat_set<AccountID>
128  getMentionedAccounts() const;
129 
130  uint256
132  {
133  return tid_;
134  }
135 
137  getJson(JsonOptions options) const override;
139  getJson(JsonOptions options, bool binary) const;
140 
141  void
142  sign(PublicKey const& publicKey, SecretKey const& secretKey);
143 
147  enum class RequireFullyCanonicalSig : bool { no, yes };
149  checkSign(RequireFullyCanonicalSig requireCanonicalSig) const;
150 
151  // SQL Functions with metadata.
152  static std::string const&
154 
156  getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
157  const;
158 
160  getMetaSQL(
161  Serializer rawTxn,
162  std::uint32_t inLedger,
163  char status,
164  std::string const& escapedMetaData) const;
165 
166 private:
168  checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
169 
171  checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const;
172 
175 };
176 
177 bool
179 
188 sterilize(STTx const& stx);
189 
191 bool
192 isPseudoTx(STObject const& tx);
193 
194 } // namespace ripple
195 
196 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:105
ripple::STTx::checkMultiSign
std::pair< bool, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:298
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:228
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:110
std::string
STL class.
std::shared_ptr
STL class.
ripple::STTx::checkSign
std::pair< bool, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:175
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
functional
std::pair
ripple::sfSigningPubKey
const SF_Blob sfSigningPubKey(access, STI_VL, 3, "SigningPubKey")
Definition: SField.h:459
std::vector< unsigned char >
ripple::sfSequence
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
Definition: SField.h:356
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STTx::getSigningHash
uint256 getSigningHash() const
Definition: STTx.cpp:145
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:216
std::function
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:568
ripple::STTx::setSequence
void setSequence(std::uint32_t seq)
Definition: STTx.h:122
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< 256 >
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:524
ripple::STTx::getCountedObjectName
static char const * getCountedObjectName()
Definition: STTx.h:46
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:39
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:495
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:77
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:111
std::uint32_t
ripple::STTx::checkSingleSign
std::pair< bool, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:258
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:164
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:194
ripple::STTx::getSequence
std::uint32_t getSequence() const
Definition: STTx.h:117
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:131
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:515
ripple::STTx::maxMultiSigners
static const std::size_t maxMultiSigners
Definition: STTx.h:52
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:173
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:112
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:35
ripple::txnSqlNew
@ txnSqlNew
Definition: STTx.h:34
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:51
std::size_t
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.h:83
ripple::STTx::STTx
STTx(SerialIter &&sit) noexcept(false)
Definition: STTx.h:62
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:532
ripple::STObject::setFieldU32
void setFieldU32(SField const &field, std::uint32_t)
Definition: STObject.cpp:632
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:147
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.h:90
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:174