rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/Expected.h>
24#include <xrpl/protocol/Feature.h>
25#include <xrpl/protocol/PublicKey.h>
26#include <xrpl/protocol/Rules.h>
27#include <xrpl/protocol/STObject.h>
28#include <xrpl/protocol/SecretKey.h>
29#include <xrpl/protocol/SeqProxy.h>
30#include <xrpl/protocol/TxFormats.h>
31
32#include <boost/container/flat_set.hpp>
33
34#include <functional>
35
36namespace ripple {
37
46
47class STTx final : public STObject, public CountedObject<STTx>
48{
51
52public:
53 static std::size_t const minMultiSigners = 1;
54
55 // if rules are not supplied then the largest possible value is returned
56 static std::size_t
57 maxMultiSigners(Rules const* rules = 0)
58 {
59 if (rules && !rules->enabled(featureExpandedSignerList))
60 return 8;
61
62 return 32;
63 }
64
65 STTx() = delete;
66 STTx(STTx const& other) = default;
67 STTx&
68 operator=(STTx const& other) = delete;
69
70 explicit STTx(SerialIter& sit);
71 explicit STTx(SerialIter&& sit);
72 explicit STTx(STObject&& object);
73
80 STTx(TxType type, std::function<void(STObject&)> assembler);
81
82 // STObject functions.
84 getSType() const override;
85
87 getFullText() const override;
88
89 // Outer transaction functions / signature functions.
90 static Blob
91 getSignature(STObject const& sigObject);
92
93 Blob
95 {
96 return getSignature(*this);
97 }
98
100 getSigningHash() const;
101
102 TxType
103 getTxnType() const;
104
105 Blob
106 getSigningPubKey() const;
107
109 getSeqProxy() const;
110
113 getSeqValue() const;
114
115 boost::container::flat_set<AccountID>
116 getMentionedAccounts() const;
117
118 uint256
119 getTransactionID() const;
120
122 getJson(JsonOptions options) const override;
123
125 getJson(JsonOptions options, bool binary) const;
126
127 void
128 sign(
129 PublicKey const& publicKey,
130 SecretKey const& secretKey,
132 {});
133
134 enum class RequireFullyCanonicalSig : bool { no, yes };
135
143 checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
144 const;
145
148 RequireFullyCanonicalSig requireCanonicalSig,
149 Rules const& rules) 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
161 Serializer rawTxn,
162 std::uint32_t inLedger,
163 char status,
164 std::string const& escapedMetaData) const;
165
168
169private:
179 checkSign(
180 RequireFullyCanonicalSig requireCanonicalSig,
181 Rules const& rules,
182 STObject const& sigObject) const;
183
186 RequireFullyCanonicalSig requireCanonicalSig,
187 STObject const& sigObject) const;
188
191 RequireFullyCanonicalSig requireCanonicalSig,
192 Rules const& rules,
193 STObject const& sigObject) const;
194
197 STObject const& batchSigner,
198 RequireFullyCanonicalSig requireCanonicalSig) const;
199
202 STObject const& batchSigner,
203 RequireFullyCanonicalSig requireCanonicalSig,
204 Rules const& rules) const;
205
206 STBase*
207 copy(std::size_t n, void* buf) const override;
208 STBase*
209 move(std::size_t n, void* buf) override;
210
211 friend class detail::STVar;
213};
214
215bool
217
226sterilize(STTx const& stx);
227
229bool
230isPseudoTx(STObject const& tx);
231
232inline STTx::STTx(SerialIter&& sit) : STTx(sit)
233{
234}
235
236inline TxType
238{
239 return tx_type_;
240}
241
242inline Blob
244{
245 return getFieldVL(sfSigningPubKey);
246}
247
248inline uint256
250{
251 return tid_;
252}
253
254} // namespace ripple
255
256#endif
Represents a JSON value.
Definition json_value.h:149
Tracks the number of instances of an object.
A public key.
Definition PublicKey.h:62
Rules controlling protocol behavior.
Definition Rules.h:38
A type which can be exported to a well known binary format.
Definition STBase.h:135
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:663
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition STTx.cpp:162
uint256 getSigningHash() const
Definition STTx.cpp:197
static std::string const & getMetaSQLInsertReplaceHeader()
Definition STTx.cpp:375
std::vector< uint256 > batchTxnIds_
Definition STTx.h:212
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig, STObject const &sigObject) const
Definition STTx.cpp:454
SeqProxy getSeqProxy() const
Definition STTx.cpp:216
Json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:338
Expected< void, std::string > checkBatchSingleSign(STObject const &batchSigner, RequireFullyCanonicalSig requireCanonicalSig) const
Definition STTx.cpp:465
std::vector< uint256 > const & getBatchTransactionIDs() const
Retrieves a batch of transaction IDs from the STTx.
Definition STTx.cpp:629
STBase * move(std::size_t n, void *buf) override
Definition STTx.cpp:138
static std::size_t const minMultiSigners
Definition STTx.h:53
Blob getSigningPubKey() const
Definition STTx.h:243
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Check the signature.
Definition STTx.cpp:282
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition STTx.h:57
RequireFullyCanonicalSig
Definition STTx.h:134
TxType tx_type_
Definition STTx.h:50
uint256 tid_
Definition STTx.h:49
Expected< void, std::string > checkBatchMultiSign(STObject const &batchSigner, RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition STTx.cpp:557
STTx & operator=(STTx const &other)=delete
Blob getSignature() const
Definition STTx.h:94
STTx()=delete
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
Definition STTx.cpp:231
STTx(STTx const &other)=default
void sign(PublicKey const &publicKey, SecretKey const &secretKey, std::optional< std::reference_wrapper< SField const > > signatureTarget={})
Definition STTx.cpp:237
TxType getTxnType() const
Definition STTx.h:237
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition STTx.cpp:387
uint256 getTransactionID() const
Definition STTx.h:249
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules, STObject const &sigObject) const
Definition STTx.cpp:583
SerializedTypeID getSType() const override
Definition STTx.cpp:145
std::string getFullText() const override
Definition STTx.cpp:151
Expected< void, std::string > checkBatchSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition STTx.cpp:302
STBase * copy(std::size_t n, void *buf) const override
Definition STTx.cpp:132
A secret key.
Definition SecretKey.h:38
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:56
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition STTx.cpp:861
TxType
Transaction type identifiers.
Definition TxFormats.h:57
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:870
SerializedTypeID
Definition SField.h:110
TxnSql
Definition STTx.h:38
@ txnSqlIncluded
Definition STTx.h:43
@ txnSqlUnknown
Definition STTx.h:44
@ txnSqlConflict
Definition STTx.h:40
@ txnSqlHeld
Definition STTx.h:41
@ txnSqlNew
Definition STTx.h:39
@ txnSqlValidated
Definition STTx.h:42
bool passesLocalChecks(STObject const &st, std::string &)
Definition STTx.cpp:831
Note, should be treated as flags that can be | and &.
Definition STBase.h:37