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/SecretKey.h>
25 #include <ripple/protocol/STObject.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 {
35  txnSqlNew = 'N',
37  txnSqlHeld = 'H',
41 };
42 
43 class STTx final
44  : public STObject
45  , public CountedObject <STTx>
46 {
47 public:
48  static char const* getCountedObjectName () { return "STTx"; }
49 
50  static std::size_t const minMultiSigners = 1;
51  static std::size_t const maxMultiSigners = 8;
52 
53 public:
54  STTx () = delete;
55  STTx& operator= (STTx const& other) = delete;
56 
57  STTx (STTx const& other) = default;
58 
59  explicit STTx (SerialIter& sit) noexcept (false);
60  explicit STTx (SerialIter&& sit) noexcept (false) : STTx(sit) {}
61 
62  explicit STTx (STObject&& object) noexcept (false);
63 
70  STTx (
71  TxType type,
72  std::function<void(STObject&)> assembler);
73 
74  STBase*
75  copy (std::size_t n, void* buf) const override
76  {
77  return emplace(n, buf, *this);
78  }
79 
80  STBase*
81  move (std::size_t n, void* buf) override
82  {
83  return emplace(n, buf, std::move(*this));
84  }
85 
86  // STObject functions.
87  SerializedTypeID getSType () const override
88  {
89  return STI_TRANSACTION;
90  }
91  std::string getFullText () const override;
92 
93  // Outer transaction functions / signature functions.
94  Blob getSignature () const;
95 
96  uint256 getSigningHash () const;
97 
98  TxType getTxnType () const
99  {
100  return tx_type_;
101  }
102 
104  {
105  return getFieldVL (sfSigningPubKey);
106  }
107 
109  {
110  return getFieldU32 (sfSequence);
111  }
113  {
114  return setFieldU32 (sfSequence, seq);
115  }
116 
117  boost::container::flat_set<AccountID>
118  getMentionedAccounts() const;
119 
121  {
122  return tid_;
123  }
124 
125  Json::Value getJson (JsonOptions options) const override;
126  Json::Value getJson (JsonOptions options, bool binary) const;
127 
128  void sign (
129  PublicKey const& publicKey,
130  SecretKey const& secretKey);
131 
135  enum class RequireFullyCanonicalSig : bool
136  {
137  no,
138  yes
139  };
141  checkSign(RequireFullyCanonicalSig requireCanonicalSig) const;
142 
143  // SQL Functions with metadata.
144  static
145  std::string const&
147 
149  std::uint32_t inLedger, std::string const& escapedMetaData) const;
150 
152  Serializer rawTxn,
153  std::uint32_t inLedger,
154  char status,
155  std::string const& escapedMetaData) const;
156 
157 private:
159  checkSingleSign (RequireFullyCanonicalSig requireCanonicalSig) const;
160 
162  checkMultiSign (RequireFullyCanonicalSig requireCanonicalSig) const;
163 
166 };
167 
168 bool passesLocalChecks (STObject const& st, std::string&);
169 
178 sterilize (STTx const& stx);
179 
181 bool isPseudoTx(STObject const& tx);
182 
183 } // ripple
184 
185 #endif
ripple::STTx::getTxnType
TxType getTxnType() const
Definition: STTx.h:98
ripple::STTx::checkMultiSign
std::pair< bool, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:299
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:232
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:102
std::string
STL class.
std::shared_ptr
STL class.
ripple::STTx::checkSign
std::pair< bool, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:182
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
functional
std::pair
ripple::sfSigningPubKey
const SF_Blob sfSigningPubKey(access, STI_VL, 3, "SigningPubKey")
Definition: SField.h:442
std::vector< unsigned char >
ripple::sfSequence
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
Definition: SField.h:340
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:52
ripple::STTx::getSigningHash
uint256 getSigningHash() const
Definition: STTx.cpp:149
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:223
std::function
ripple::STObject::getFieldVL
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:542
ripple::STTx::setSequence
void setSequence(std::uint32_t seq)
Definition: STTx.h:112
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:161
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:525
ripple::STTx::getCountedObjectName
static char const * getCountedObjectName()
Definition: STTx.h:48
ripple::txnSqlUnknown
@ txnSqlUnknown
Definition: STTx.h:40
ripple::passesLocalChecks
bool passesLocalChecks(STObject const &st, std::string &reason)
Definition: STTx.cpp:496
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:75
ripple::STTx::getFullText
std::string getFullText() const override
Definition: STTx.cpp:106
ripple::txnSqlValidated
@ txnSqlValidated
Definition: STTx.h:38
ripple::STTx
Definition: STTx.h:43
ripple::TxnSql
TxnSql
Definition: STTx.h:33
ripple::SerialIter
Definition: Serializer.h:311
ripple::STTx::getSigningPubKey
Blob getSigningPubKey() const
Definition: STTx.h:103
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:37
ripple::STTx::sign
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:166
ripple::STTx::getJson
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:202
ripple::STTx::getSequence
std::uint32_t getSequence() const
Definition: STTx.h:108
ripple::STTx::getTransactionID
uint256 getTransactionID() const
Definition: STTx.h:120
ripple::Serializer
Definition: Serializer.h:43
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:516
ripple::STTx::maxMultiSigners
static const std::size_t maxMultiSigners
Definition: STTx.h:51
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:65
ripple::STTx::getSignature
Blob getSignature() const
Definition: STTx.cpp:154
ripple::txnSqlIncluded
@ txnSqlIncluded
Definition: STTx.h:39
ripple::STTx::tid_
uint256 tid_
Definition: STTx.h:164
ripple::STTx::getMentionedAccounts
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:117
ripple::txnSqlConflict
@ txnSqlConflict
Definition: STTx.h:36
ripple::txnSqlNew
@ txnSqlNew
Definition: STTx.h:35
ripple::STTx::minMultiSigners
static const std::size_t minMultiSigners
Definition: STTx.h:50
std::size_t
ripple::STTx::move
STBase * move(std::size_t n, void *buf) override
Definition: STTx.h:81
ripple::STTx::STTx
STTx(SerialIter &&sit) noexcept(false)
Definition: STTx.h:60
ripple::STObject::getFieldU32
std::uint32_t getFieldU32(SField const &field) const
Definition: STObject.cpp:512
ripple::STObject::setFieldU32
void setFieldU32(SField const &field, std::uint32_t)
Definition: STObject.cpp:601
ripple::STTx::RequireFullyCanonicalSig
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:135
ripple::STTx::getSType
SerializedTypeID getSType() const override
Definition: STTx.h:87
Json::Value
Represents a JSON value.
Definition: json_value.h:141
ripple::STI_TRANSACTION
@ STI_TRANSACTION
Definition: SField.h:80
ripple::STTx::tx_type_
TxType tx_type_
Definition: STTx.h:165