xrpld
Loading...
Searching...
No Matches
STTx.h
1#pragma once
2
3#include <xrpl/basics/Blob.h>
4#include <xrpl/basics/CountedObject.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/HashPrefix.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/Rules.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STBase.h>
13#include <xrpl/protocol/STObject.h>
14#include <xrpl/protocol/SecretKey.h>
15#include <xrpl/protocol/SeqProxy.h>
16#include <xrpl/protocol/Serializer.h>
17#include <xrpl/protocol/Sign.h>
18#include <xrpl/protocol/TxFormats.h>
19
20#include <boost/container/flat_set.hpp>
21
22#include <cstddef>
23#include <cstdint>
24#include <expected>
25#include <functional>
26#include <memory>
27#include <optional>
28#include <string>
29#include <vector>
30
31namespace xrpl {
32
33enum class TxnSql : char {
34 New = 'N',
35 Conflict = 'C',
36 Held = 'H',
37 Validated = 'V',
38 Included = 'I',
39 Unknown = 'U'
40};
41
42class STTx final : public STObject, public CountedObject<STTx>
43{
46
47public:
48 static constexpr std::size_t kMinMultiSigners = 1;
49 static constexpr std::size_t kMaxMultiSigners = 32;
50
51 STTx() = delete;
52 STTx(STTx const& other) = default;
53 STTx&
54 operator=(STTx const& other) = delete;
55
56 explicit STTx(SerialIter& sit);
57 explicit STTx(SerialIter&& sit);
58 explicit STTx(STObject&& object);
59
67 STTx(TxType type, std::function<void(STObject&)> assembler);
68
69 // STObject functions.
70 [[nodiscard]] SerializedTypeID
71 getSType() const override;
72
73 [[nodiscard]] std::string
74 getFullText() const override;
75
76 // Outer transaction functions / signature functions.
77 static Blob
78 getSignature(STObject const& sigObject);
79
80 [[nodiscard]] Blob
82 {
83 return getSignature(*this);
84 }
85
86 [[nodiscard]] UInt256
87 getSigningHash() const;
88
89 [[nodiscard]] TxType
90 getTxnType() const;
91
92 [[nodiscard]] Blob
93 getSigningPubKey() const;
94
95 [[nodiscard]] SeqProxy
96 getSeqProxy() const;
97
98 [[nodiscard]] boost::container::flat_set<AccountID>
100
101 [[nodiscard]] UInt256
102 getTransactionID() const;
103
104 [[nodiscard]] json::Value
105 getJson(JsonOptions options) const override;
106
107 [[nodiscard]] json::Value
108 getJson(JsonOptions options, bool binary) const;
109
116 void
117 sign(PublicKey const& publicKey, SecretKey const& secretKey);
118
130 void
131 sign(
132 PublicKey const& publicKey,
133 SecretKey const& secretKey,
134 SignatureRole role,
135 Rules const& rules);
136
143 [[nodiscard]] std::expected<void, std::string>
144 checkSign(Rules const& rules) const;
145
146 [[nodiscard]] std::expected<void, std::string>
147 checkBatchSign() const;
148
149 // SQL Functions with metadata.
150 static std::string const&
152
153 [[nodiscard]] std::string
154 getMetaSQL(std::uint32_t inLedger, std::string const& escapedMetaData) const;
155
156 [[nodiscard]] std::string
158 Serializer rawTxn,
159 std::uint32_t inLedger,
160 TxnSql status,
161 std::string const& escapedMetaData) const;
162
166 [[nodiscard]] std::vector<UInt256>
168
173 [[nodiscard]] std::vector<std::shared_ptr<STTx const>> const&
174 getBatchTransactions() const;
175
180 [[nodiscard]] AccountID
181 getInitiator() const;
182
183 [[nodiscard]] AccountID
184 getFeePayerID() const;
185
186private:
197 [[nodiscard]] std::expected<void, std::string>
198 checkSign(Rules const& rules, STObject const& sigObject, SignatureRole role) const;
199
200 [[nodiscard]] std::expected<void, std::string>
201 checkSingleSign(STObject const& sigObject, HashPrefix prefix) const;
202
203 [[nodiscard]] std::expected<void, std::string>
204 checkMultiSign(STObject const& sigObject, HashPrefix prefix) const;
205
206 [[nodiscard]] std::expected<void, std::string>
207 checkBatchSingleSign(STObject const& batchSigner, std::vector<UInt256> const& txIds) const;
208
209 [[nodiscard]] std::expected<void, std::string>
210 checkBatchMultiSign(STObject const& batchSigner, std::vector<UInt256> const& txIds) const;
211
212 void
214
215 STBase*
216 copy(std::size_t n, void* buf) const override;
217 STBase*
218 move(std::size_t n, void* buf) override;
219
220 friend class detail::STVar;
222};
223
224bool
226
236sterilize(STTx const& stx);
237
241bool
242isPseudoTx(STObject const& tx);
243
244inline STTx::STTx(SerialIter&& sit) // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
245 : STTx(sit)
246{
247}
248
249inline TxType
251{
252 return txType_;
253}
254
255inline Blob
257{
258 return getFieldVL(sfSigningPubKey);
259}
260
261inline UInt256
263{
264 return tid_;
265}
266
267} // namespace xrpl
Represents a JSON value.
Definition json_value.h:117
A public key.
Definition PublicKey.h:53
Rules controlling protocol behavior.
Definition Rules.h:40
A type which can be exported to a well known binary format.
Definition STBase.h:129
Blob getFieldVL(SField const &field) const
Definition STObject.cpp:649
STObject(STObject const &)=default
std::string getFullText() const override
Definition STTx.cpp:135
STBase * move(std::size_t n, void *buf) override
Definition STTx.cpp:122
Blob getSignature() const
Definition STTx.h:81
std::string getMetaSQL(std::uint32_t inLedger, std::string const &escapedMetaData) const
Definition STTx.cpp:400
std::optional< std::vector< std::shared_ptr< STTx const > > > batchTxns_
Definition STTx.h:221
STTx & operator=(STTx const &other)=delete
static std::string const & getMetaSQLInsertReplaceHeader()
Definition STTx.cpp:388
STTx(STTx const &other)=default
static constexpr std::size_t kMinMultiSigners
Definition STTx.h:48
SeqProxy getSeqProxy() const
Definition STTx.cpp:198
UInt256 tid_
Definition STTx.h:44
std::expected< void, std::string > checkBatchSingleSign(STObject const &batchSigner, std::vector< UInt256 > const &txIds) const
Definition STTx.cpp:470
std::expected< void, std::string > checkSign(Rules const &rules) const
Check the signature.
Definition STTx.cpp:270
std::expected< void, std::string > checkSingleSign(STObject const &sigObject, HashPrefix prefix) const
Definition STTx.cpp:463
std::expected< void, std::string > checkBatchMultiSign(STObject const &batchSigner, std::vector< UInt256 > const &txIds) const
Definition STTx.cpp:556
void sign(PublicKey const &publicKey, SecretKey const &secretKey)
Sign the transaction as its account.
Definition STTx.cpp:215
STBase * copy(std::size_t n, void *buf) const override
Definition STTx.cpp:116
STTx()=delete
static constexpr std::size_t kMaxMultiSigners
Definition STTx.h:49
void buildBatchTxns()
Definition STTx.cpp:597
TxType getTxnType() const
Definition STTx.h:250
UInt256 getTransactionID() const
Definition STTx.h:262
AccountID getFeePayerID() const
Definition STTx.cpp:673
Blob getSigningPubKey() const
Definition STTx.h:256
UInt256 getSigningHash() const
Definition STTx.cpp:179
TxType txType_
Definition STTx.h:45
json::Value getJson(JsonOptions options) const override
Definition STTx.cpp:351
std::vector< UInt256 > getBatchTransactionIDs() const
The IDs of the inner transactions of a Batch.
Definition STTx.cpp:637
AccountID getInitiator() const
The account responsible for the authorization: the delegate when sfDelegate is present,...
Definition STTx.cpp:659
SerializedTypeID getSType() const override
Definition STTx.cpp:129
boost::container::flat_set< AccountID > getMentionedAccounts() const
Definition STTx.cpp:146
std::expected< void, std::string > checkMultiSign(STObject const &sigObject, HashPrefix prefix) const
Definition STTx.cpp:575
std::vector< std::shared_ptr< STTx const > > const & getBatchTransactions() const
The inner transactions of a Batch, built and validated at construction.
Definition STTx.cpp:648
std::expected< void, std::string > checkBatchSign() const
Definition STTx.cpp:300
A secret key.
Definition SecretKey.h:24
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TxType
Transaction type identifiers.
Definition TxFormats.h:45
TxnSql
Definition STTx.h:33
@ Validated
Definition STTx.h:37
@ Included
Definition STTx.h:38
@ Conflict
Definition STTx.h:35
bool passesLocalChecks(STTx const &tx, std::string &)
Definition STTx.cpp:850
BaseUInt< 256 > UInt256
Definition base_uint.h:580
SignatureRole
The signature slots on a transaction.
Definition Sign.h:23
SerializedTypeID
Definition SField.h:94
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:35
std::vector< unsigned char > Blob
Storage for linear binary data.
Definition Blob.h:11
std::shared_ptr< STTx const > sterilize(STTx const &stx)
Sterilize a transaction.
Definition STTx.cpp:880
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition STTx.cpp:889
Note, should be treated as flags that can be | and &.
Definition STBase.h:22