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
38enum TxnSql : char {
39 txnSqlNew = 'N',
44 txnSqlUnknown = 'U'
45};
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 Blob
91 getSignature() const;
92
94 getSigningHash() const;
95
96 TxType
97 getTxnType() const;
98
99 Blob
100 getSigningPubKey() const;
101
103 getSeqProxy() const;
104
107 getSeqValue() const;
108
109 boost::container::flat_set<AccountID>
110 getMentionedAccounts() const;
111
112 uint256
113 getTransactionID() const;
114
116 getJson(JsonOptions options) const override;
117
119 getJson(JsonOptions options, bool binary) const;
120
121 void
122 sign(PublicKey const& publicKey, SecretKey const& secretKey);
123
127 enum class RequireFullyCanonicalSig : bool { no, yes };
128
130 checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
131 const;
132
135 RequireFullyCanonicalSig requireCanonicalSig,
136 Rules const& rules) const;
137
138 // SQL Functions with metadata.
139 static std::string const&
141
143 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
144 const;
145
148 Serializer rawTxn,
149 std::uint32_t inLedger,
150 char status,
151 std::string const& escapedMetaData) const;
152
155
156private:
158 checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
159
162 RequireFullyCanonicalSig requireCanonicalSig,
163 Rules const& rules) const;
164
167 STObject const& batchSigner,
168 RequireFullyCanonicalSig requireCanonicalSig) const;
169
172 STObject const& batchSigner,
173 RequireFullyCanonicalSig requireCanonicalSig,
174 Rules const& rules) const;
175
176 STBase*
177 copy(std::size_t n, void* buf) const override;
178 STBase*
179 move(std::size_t n, void* buf) override;
180
181 friend class detail::STVar;
183};
184
185bool
187
196sterilize(STTx const& stx);
197
199bool
200isPseudoTx(STObject const& tx);
201
202inline STTx::STTx(SerialIter&& sit) : STTx(sit)
203{
204}
205
206inline TxType
208{
209 return tx_type_;
210}
211
212inline Blob
214{
215 return getFieldVL(sfSigningPubKey);
216}
217
218inline uint256
220{
221 return tid_;
222}
223
224} // namespace ripple
225
226#endif
Represents a JSON value.
Definition: json_value.h:149
Tracks the number of instances of an object.
A public key.
Definition: PublicKey.h:61
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:657
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:162
std::vector< uint256 > getBatchTransactionIDs() const
Retrieves a batch of transaction IDs from the STTx.
Definition: STTx.cpp:583
uint256 getSigningHash() const
Definition: STTx.cpp:197
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:342
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:237
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:545
SeqProxy getSeqProxy() const
Definition: STTx.cpp:216
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:305
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:421
Expected< void, std::string > checkBatchSingleSign(STObject const &batchSigner, RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:430
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:213
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:248
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:57
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:127
TxType tx_type_
Definition: STTx.h:50
std::vector< uint256 > batch_txn_ids_
Definition: STTx.h:182
uint256 tid_
Definition: STTx.h:49
Expected< void, std::string > checkBatchMultiSign(STObject const &batchSigner, RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:520
STTx & operator=(STTx const &other)=delete
Blob getSignature() const
Definition: STTx.cpp:203
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
TxType getTxnType() const
Definition: STTx.h:207
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition: STTx.cpp:354
uint256 getTransactionID() const
Definition: STTx.h:219
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:269
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:811
TxType
Transaction type identifiers.
Definition: TxFormats.h:57
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:820
SerializedTypeID
Definition: SField.h:107
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:781
Note, should be treated as flags that can be | and &.
Definition: STBase.h:37