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
105 boost::container::flat_set<AccountID>
106 getMentionedAccounts() const;
107
108 uint256
109 getTransactionID() const;
110
112 getJson(JsonOptions options) const override;
113
115 getJson(JsonOptions options, bool binary) const;
116
117 void
118 sign(PublicKey const& publicKey, SecretKey const& secretKey);
119
123 enum class RequireFullyCanonicalSig : bool { no, yes };
125 checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
126 const;
127
128 // SQL Functions with metadata.
129 static std::string const&
131
133 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
134 const;
135
138 Serializer rawTxn,
139 std::uint32_t inLedger,
140 char status,
141 std::string const& escapedMetaData) const;
142
143private:
145 checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
146
149 RequireFullyCanonicalSig requireCanonicalSig,
150 Rules const& rules) const;
151
152 STBase*
153 copy(std::size_t n, void* buf) const override;
154 STBase*
155 move(std::size_t n, void* buf) override;
156
157 friend class detail::STVar;
158};
159
160bool
162
171sterilize(STTx const& stx);
172
174bool
175isPseudoTx(STObject const& tx);
176
177inline STTx::STTx(SerialIter&& sit) : STTx(sit)
178{
179}
180
181inline TxType
183{
184 return tx_type_;
185}
186
187inline Blob
189{
190 return getFieldVL(sfSigningPubKey);
191}
192
193inline uint256
195{
196 return tid_;
197}
198
199} // namespace ripple
200
201#endif
Represents a JSON value.
Definition: json_value.h:148
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:126
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:297
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:228
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:379
SeqProxy getSeqProxy() const
Definition: STTx.cpp:213
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:260
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:339
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:188
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:239
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:57
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:123
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
STTx(STTx const &other)=default
TxType getTxnType() const
Definition: STTx.h:182
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition: STTx.cpp:309
uint256 getTransactionID() const
Definition: STTx.h:194
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:631
TxType
Transaction type identifiers.
Definition: TxFormats.h:57
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:640
SerializedTypeID
Definition: SField.h:108
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:604
Note, should be treated as flags that can be | and &.
Definition: STBase.h:38