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#include <boost/container/flat_set.hpp>
32
33#include <functional>
34
35namespace ripple {
36
37enum TxnSql : char {
38 txnSqlNew = 'N',
43 txnSqlUnknown = 'U'
44};
45
46class STTx final : public STObject, public CountedObject<STTx>
47{
50
51public:
52 static std::size_t const minMultiSigners = 1;
53
54 // if rules are not supplied then the largest possible value is returned
55 static std::size_t
56 maxMultiSigners(Rules const* rules = 0)
57 {
58 if (rules && !rules->enabled(featureExpandedSignerList))
59 return 8;
60
61 return 32;
62 }
63
64 STTx() = delete;
65 STTx(STTx const& other) = default;
66 STTx&
67 operator=(STTx const& other) = delete;
68
69 explicit STTx(SerialIter& sit);
70 explicit STTx(SerialIter&& sit);
71 explicit STTx(STObject&& object);
72
79 STTx(TxType type, std::function<void(STObject&)> assembler);
80
81 // STObject functions.
83 getSType() const override;
84
86 getFullText() const override;
87
88 // Outer transaction functions / signature functions.
89 Blob
90 getSignature() const;
91
93 getSigningHash() const;
94
95 TxType
96 getTxnType() const;
97
98 Blob
99 getSigningPubKey() const;
100
102 getSeqProxy() const;
103
104 boost::container::flat_set<AccountID>
105 getMentionedAccounts() const;
106
107 uint256
108 getTransactionID() const;
109
111 getJson(JsonOptions options) const override;
112
114 getJson(JsonOptions options, bool binary) const;
115
116 void
117 sign(PublicKey const& publicKey, SecretKey const& secretKey);
118
122 enum class RequireFullyCanonicalSig : bool { no, yes };
124 checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const& rules)
125 const;
126
127 // SQL Functions with metadata.
128 static std::string const&
130
132 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData)
133 const;
134
137 Serializer rawTxn,
138 std::uint32_t inLedger,
139 char status,
140 std::string const& escapedMetaData) const;
141
142private:
144 checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const;
145
148 RequireFullyCanonicalSig requireCanonicalSig,
149 Rules const& rules) const;
150
151 STBase*
152 copy(std::size_t n, void* buf) const override;
153 STBase*
154 move(std::size_t n, void* buf) override;
155
156 friend class detail::STVar;
157};
158
159bool
161
170sterilize(STTx const& stx);
171
173bool
174isPseudoTx(STObject const& tx);
175
176inline STTx::STTx(SerialIter&& sit) : STTx(sit)
177{
178}
179
180inline TxType
182{
183 return tx_type_;
184}
185
186inline Blob
188{
189 return getFieldVL(sfSigningPubKey);
190}
191
192inline uint256
194{
195 return tid_;
196}
197
198} // namespace ripple
199
200#endif
Represents a JSON value.
Definition: json_value.h:147
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:124
Blob getFieldVL(SField const &field) const
Definition: STObject.cpp:627
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition: STTx.cpp:132
uint256 getSigningHash() const
Definition: STTx.cpp:167
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:270
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Definition: STTx.cpp:201
Expected< void, std::string > checkMultiSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:352
SeqProxy getSeqProxy() const
Definition: STTx.cpp:186
Json::Value getJson(JsonOptions options) const override
Definition: STTx.cpp:233
Expected< void, std::string > checkSingleSign(RequireFullyCanonicalSig requireCanonicalSig) const
Definition: STTx.cpp:312
STBase * move(std::size_t n, void *buf) override
Definition: STTx.cpp:108
static std::size_t const minMultiSigners
Definition: STTx.h:52
Blob getSigningPubKey() const
Definition: STTx.h:187
Expected< void, std::string > checkSign(RequireFullyCanonicalSig requireCanonicalSig, Rules const &rules) const
Definition: STTx.cpp:212
static std::size_t maxMultiSigners(Rules const *rules=0)
Definition: STTx.h:56
RequireFullyCanonicalSig
Check the signature.
Definition: STTx.h:122
TxType tx_type_
Definition: STTx.h:49
uint256 tid_
Definition: STTx.h:48
STTx & operator=(STTx const &other)=delete
Blob getSignature() const
Definition: STTx.cpp:173
STTx()=delete
STTx(STTx const &other)=default
TxType getTxnType() const
Definition: STTx.h:181
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition: STTx.cpp:282
uint256 getTransactionID() const
Definition: STTx.h:193
SerializedTypeID getSType() const override
Definition: STTx.cpp:115
std::string getFullText() const override
Definition: STTx.cpp:121
STBase * copy(std::size_t n, void *buf) const override
Definition: STTx.cpp:102
A secret key.
Definition: SecretKey.h:37
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:604
TxType
Transaction type identifiers.
Definition: TxFormats.h:57
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:613
SerializedTypeID
Definition: SField.h:108
TxnSql
Definition: STTx.h:37
@ txnSqlIncluded
Definition: STTx.h:42
@ txnSqlUnknown
Definition: STTx.h:43
@ txnSqlConflict
Definition: STTx.h:39
@ txnSqlHeld
Definition: STTx.h:40
@ txnSqlNew
Definition: STTx.h:38
@ txnSqlValidated
Definition: STTx.h:41
bool passesLocalChecks(STObject const &st, std::string &)
Definition: STTx.cpp:577
Note, should be treated as flags that can be | and &.
Definition: STBase.h:36