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 };
129 checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
130 const;
131
132 // SQL Functions with metadata.
133 static std::string const&
135
137 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
138 const;
139
142 Serializer rawTxn,
143 std::uint32_t inLedger,
144 char status,
145 std::string const& escapedMetaData) const;
146
147private:
149 checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
150
153 RequireFullyCanonicalSig requireCanonicalSig,
154 Rules const& rules) const;
155
156 STBase*
157 copy(std::size_t n, void* buf) const override;
158 STBase*
159 move(std::size_t n, void* buf) override;
160
161 friend class detail::STVar;
162};
163
164bool
166
175sterilize(STTx const& stx);
176
178bool
179isPseudoTx(STObject const& tx);
180
181inline STTx::STTx(SerialIter&& sit) : STTx(sit)
182{
183}
184
185inline TxType
187{
188 return tx_type_;
189}
190
191inline Blob
193{
194 return getFieldVL(sfSigningPubKey);
195}
196
197inline uint256
199{
200 return tid_;
201}
202
203} // namespace ripple
204
205#endif
Represents a JSON value.
Definition: json_value.h:150
Tracks the number of instances of an object.
A public key.
Definition: PublicKey.h:62
Rules controlling protocol behavior.
Definition: Rules.h:35
A type which can be exported to a well known binary format.
Definition: STBase.h:136
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:657
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:159
uint256 getSigningHash() const
Definition: STTx.cpp:194
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:303
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:234
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:385
SeqProxy getSeqProxy() const
Definition: STTx.cpp:213
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:266
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:345
STBase * move(std::size_t n, void *buf) override
Definition: STTx.cpp:135
static std::size_t const minMultiSigners
Definition: STTx.h:53
Blob getSigningPubKey() const
Definition: STTx.h:192
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:245
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
uint256 tid_
Definition: STTx.h:49
STTx & operator=(STTx const &other)=delete
Blob getSignature() const
Definition: STTx.cpp:200
STTx()=delete
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
Definition: STTx.cpp:228
STTx(STTx const &other)=default
TxType getTxnType() const
Definition: STTx.h:186
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition: STTx.cpp:315
uint256 getTransactionID() const
Definition: STTx.h:198
SerializedTypeID getSType() const override
Definition: STTx.cpp:142
std::string getFullText() const override
Definition: STTx.cpp:148
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.cpp:129
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:26
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition: STTx.cpp:637
TxType
Transaction type identifiers.
Definition: TxFormats.h:57
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:646
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:610
Note, should be treated as flags that can be | and &.
Definition: STBase.h:38